Skip to content

Commit c91f8c4

Browse files
authored
Fix metrics reporting period (#14019)
* fix reporting period * fixes
1 parent 9f60969 commit c91f8c4

File tree

5 files changed

+54
-34
lines changed

5 files changed

+54
-34
lines changed

config/core/configmaps/observability.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ metadata:
2222
app.kubernetes.io/component: observability
2323
app.kubernetes.io/version: devel
2424
annotations:
25-
knative.dev/example-checksum: "fed4756e"
25+
knative.dev/example-checksum: "54abd711"
2626
data:
2727
_example: |
2828
################################
@@ -95,11 +95,22 @@ data:
9595
# It supports either prometheus (the default) or opencensus.
9696
metrics.backend-destination: prometheus
9797
98+
# metrics.reporting-period-seconds specifies the global metrics reporting period for control and data plane components.
99+
# If a zero or negative value is passed the default reporting period is used (10 secs).
100+
# If the attribute is not specified a default value is used per metrics backend.
101+
# For the prometheus backend the default reporting period is 5s while for opencensus it is 60s.
102+
metrics.reporting-period-seconds: "5"
103+
98104
# metrics.request-metrics-backend-destination specifies the request metrics
99105
# destination. It enables queue proxy to send request metrics.
100106
# Currently supported values: prometheus (the default), opencensus.
101107
metrics.request-metrics-backend-destination: prometheus
102108
109+
# metrics.request-metrics-reporting-period-seconds specifies the request metrics reporting period in sec at queue proxy.
110+
# If a zero or negative value is passed the default reporting period is used (10 secs).
111+
# If the attribute is not specified, it is overridden by the value of metrics.reporting-period-seconds.
112+
metrics.request-metrics-reporting-period-seconds: "5"
113+
103114
# profiling.enable indicates whether it is allowed to retrieve runtime profiling data from
104115
# the pods via an HTTP server in the format expected by the pprof visualization tool. When
105116
# enabled, the Knative Serving pods expose the profiling data on an alternate HTTP port 8008.

pkg/queue/sharedmain/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ type config struct {
9494
ServingEnableProbeRequestLog bool `split_words:"true"` // optional
9595

9696
// Metrics configuration
97-
ServingRequestMetricsBackend string `split_words:"true"` // optional
98-
MetricsCollectorAddress string `split_words:"true"` // optional
97+
ServingRequestMetricsBackend string `split_words:"true"` // optional
98+
ServingRequestMetricsReportingPeriodSeconds int `split_words:"true"` // optional
99+
MetricsCollectorAddress string `split_words:"true"` // optional
99100

100101
// Tracing configuration
101102
TracingConfigDebug bool `split_words:"true"` // optional
@@ -366,7 +367,7 @@ func supportsMetrics(ctx context.Context, logger *zap.SugaredLogger, env config)
366367
if env.ServingRequestMetricsBackend == "" {
367368
return false
368369
}
369-
if err := setupMetricsExporter(ctx, logger, env.ServingRequestMetricsBackend, env.MetricsCollectorAddress); err != nil {
370+
if err := setupMetricsExporter(ctx, logger, env.ServingRequestMetricsBackend, env.ServingRequestMetricsReportingPeriodSeconds, env.MetricsCollectorAddress); err != nil {
370371
logger.Errorw("Error setting up request metrics exporter. Request metrics will be unavailable.", zap.Error(err))
371372
return false
372373
}
@@ -412,7 +413,7 @@ func requestAppMetricsHandler(logger *zap.SugaredLogger, currentHandler http.Han
412413
return h
413414
}
414415

415-
func setupMetricsExporter(ctx context.Context, logger *zap.SugaredLogger, backend string, collectorAddress string) error {
416+
func setupMetricsExporter(ctx context.Context, logger *zap.SugaredLogger, backend string, reportingPeriod int, collectorAddress string) error {
416417
// Set up OpenCensus exporter.
417418
// NOTE: We use revision as the component instead of queue because queue is
418419
// implementation specific. The current metrics are request relative. Using
@@ -424,8 +425,9 @@ func setupMetricsExporter(ctx context.Context, logger *zap.SugaredLogger, backen
424425
Component: "revision",
425426
PrometheusPort: networking.UserQueueMetricsPort,
426427
ConfigMap: map[string]string{
427-
metrics.BackendDestinationKey: backend,
428-
"metrics.opencensus-address": collectorAddress,
428+
metrics.BackendDestinationKey: backend,
429+
"metrics.opencensus-address": collectorAddress,
430+
"metrics.reporting-period-seconds": strconv.Itoa(reportingPeriod),
429431
},
430432
}
431433
return metrics.UpdateExporter(ctx, ops, logger)

pkg/reconciler/revision/resources/deploy_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ var (
144144
}, {
145145
Name: "SERVING_REQUEST_METRICS_BACKEND",
146146
Value: "",
147+
}, {
148+
Name: "SERVING_REQUEST_METRICS_REPORTING_PERIOD_SECONDS",
149+
Value: "0",
147150
}, {
148151
Name: "TRACING_CONFIG_BACKEND",
149152
Value: "",

pkg/reconciler/revision/resources/queue.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container
325325
}, {
326326
Name: "SERVING_REQUEST_METRICS_BACKEND",
327327
Value: cfg.Observability.RequestMetricsBackend,
328+
}, {
329+
Name: "SERVING_REQUEST_METRICS_REPORTING_PERIOD_SECONDS",
330+
Value: strconv.Itoa(cfg.Observability.RequestMetricsReportingPeriodSeconds),
328331
}, {
329332
Name: "TRACING_CONFIG_BACKEND",
330333
Value: string(cfg.Tracing.Backend),

pkg/reconciler/revision/resources/queue_test.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -903,33 +903,34 @@ func TestTCPProbeGeneration(t *testing.T) {
903903
}
904904

905905
var defaultEnv = map[string]string{
906-
"CONTAINER_CONCURRENCY": "0",
907-
"ENABLE_HTTP2_AUTO_DETECTION": "false",
908-
"ENABLE_PROFILING": "false",
909-
"METRICS_DOMAIN": metrics.Domain(),
910-
"METRICS_COLLECTOR_ADDRESS": "",
911-
"QUEUE_SERVING_PORT": "8012",
912-
"QUEUE_SERVING_TLS_PORT": "8112",
913-
"REVISION_TIMEOUT_SECONDS": "45",
914-
"REVISION_RESPONSE_START_TIMEOUT_SECONDS": "0",
915-
"REVISION_IDLE_TIMEOUT_SECONDS": "0",
916-
"SERVING_CONFIGURATION": "",
917-
"SERVING_ENABLE_PROBE_REQUEST_LOG": "false",
918-
"SERVING_ENABLE_REQUEST_LOG": "false",
919-
"SERVING_LOGGING_CONFIG": "",
920-
"SERVING_LOGGING_LEVEL": "",
921-
"SERVING_NAMESPACE": "foo",
922-
"SERVING_REQUEST_LOG_TEMPLATE": "",
923-
"SERVING_REQUEST_METRICS_BACKEND": "",
924-
"SERVING_REVISION": "bar",
925-
"SERVING_SERVICE": "",
926-
"SYSTEM_NAMESPACE": system.Namespace(),
927-
"TRACING_CONFIG_BACKEND": "",
928-
"TRACING_CONFIG_DEBUG": "false",
929-
"TRACING_CONFIG_SAMPLE_RATE": "0",
930-
"TRACING_CONFIG_ZIPKIN_ENDPOINT": "",
931-
"USER_PORT": strconv.Itoa(v1.DefaultUserPort),
932-
"ROOT_CA": "",
906+
"CONTAINER_CONCURRENCY": "0",
907+
"ENABLE_HTTP2_AUTO_DETECTION": "false",
908+
"ENABLE_PROFILING": "false",
909+
"METRICS_DOMAIN": metrics.Domain(),
910+
"METRICS_COLLECTOR_ADDRESS": "",
911+
"QUEUE_SERVING_PORT": "8012",
912+
"QUEUE_SERVING_TLS_PORT": "8112",
913+
"REVISION_TIMEOUT_SECONDS": "45",
914+
"REVISION_RESPONSE_START_TIMEOUT_SECONDS": "0",
915+
"REVISION_IDLE_TIMEOUT_SECONDS": "0",
916+
"SERVING_CONFIGURATION": "",
917+
"SERVING_ENABLE_PROBE_REQUEST_LOG": "false",
918+
"SERVING_ENABLE_REQUEST_LOG": "false",
919+
"SERVING_LOGGING_CONFIG": "",
920+
"SERVING_LOGGING_LEVEL": "",
921+
"SERVING_NAMESPACE": "foo",
922+
"SERVING_REQUEST_LOG_TEMPLATE": "",
923+
"SERVING_REQUEST_METRICS_BACKEND": "",
924+
"SERVING_REQUEST_METRICS_REPORTING_PERIOD_SECONDS": "0",
925+
"SERVING_REVISION": "bar",
926+
"SERVING_SERVICE": "",
927+
"SYSTEM_NAMESPACE": system.Namespace(),
928+
"TRACING_CONFIG_BACKEND": "",
929+
"TRACING_CONFIG_DEBUG": "false",
930+
"TRACING_CONFIG_SAMPLE_RATE": "0",
931+
"TRACING_CONFIG_ZIPKIN_ENDPOINT": "",
932+
"USER_PORT": strconv.Itoa(v1.DefaultUserPort),
933+
"ROOT_CA": "",
933934
}
934935

935936
func probeJSON(container *corev1.Container) string {

0 commit comments

Comments
 (0)