Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ const build = (opts: buildOpts = {}): FastifyInstance => {
app.addSchema(schemas.authSchema)
app.addSchema(schemas.errorSchema)

// Fixes security vulnerability:
// https://hackerone.com/reports/3464114
app.addHook('onRequest', async (request, reply) => {
const contentType = request.headers['content-type']
if (contentType && contentType.includes('\t')) {
return reply.code(400).send({ error: 'Invalid Content-Type header' })
}
})

app.register(plugins.signals)
app.register(plugins.tenantId)
app.register(
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type StorageConfigType = {
prometheusMetricsEnabled: boolean
prometheusMetricsIncludeTenantId: boolean
otelMetricsEnabled: boolean
otelMetricsTemporality: 'DELTA' | 'CUMULATIVE'
otelMetricsExportIntervalMs: number
cdnPurgeEndpointURL?: string
cdnPurgeEndpointKey?: string
Expand Down Expand Up @@ -443,6 +444,7 @@ export function getConfig(options?: { reload?: boolean }): StorageConfigType {
prometheusMetricsIncludeTenantId:
getOptionalConfigFromEnv('PROMETHEUS_METRICS_INCLUDE_TENANT') === 'true',
otelMetricsEnabled: getOptionalConfigFromEnv('OTEL_METRICS_ENABLED') === 'true',
otelMetricsTemporality: getOptionalConfigFromEnv('OTEL_METRICS_TEMPORALITY') || 'CUMULATIVE',
otelMetricsExportIntervalMs: parseInt(
getOptionalConfigFromEnv('OTEL_METRICS_EXPORT_INTERVAL_MS') || '60000',
10
Expand Down
10 changes: 8 additions & 2 deletions src/internal/monitoring/otel-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'
import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base'
import {
AggregationTemporality,
AggregationType,
MeterProvider,
PeriodicExportingMetricReader,
AggregationType,
} from '@opentelemetry/sdk-metrics'
import { HostMetrics } from '@opentelemetry/host-metrics'
import { registerInstrumentations } from '@opentelemetry/instrumentation'
Expand All @@ -19,7 +20,8 @@ import * as os from 'os'
import { logger, logSchema } from '@internal/monitoring/logger'
import { FastifyReply, FastifyRequest } from 'fastify'

const { version, otelMetricsExportIntervalMs, otelMetricsEnabled, region } = getConfig()
const { version, otelMetricsExportIntervalMs, otelMetricsEnabled, otelMetricsTemporality, region } =
getConfig()

let prometheusExporter: PrometheusExporter | undefined

Expand Down Expand Up @@ -85,6 +87,10 @@ if (otelMetricsEnabled) {
compression: process.env.OTEL_EXPORTER_OTLP_COMPRESSION as CompressionAlgorithm,
headers: exporterHeaders,
metadata: grpcMetadata,
temporalityPreference:
otelMetricsTemporality === 'DELTA'
? AggregationTemporality.DELTA
: AggregationTemporality.CUMULATIVE,
})

readers.push(
Expand Down
Loading