mirror of https://github.com/knative/pkg.git
Expose queue proxy request metrics reporting period (#2362)
* expose qp request metrics reporting period * remove dead link * add comments * add default * fix unit test * add back the correct url * use metrics.reporting-period as default * don't return a pointer
This commit is contained in:
parent
bd3cf5174f
commit
696cac83c1
|
|
@ -41,7 +41,7 @@ const (
|
||||||
DomainEnv = "METRICS_DOMAIN"
|
DomainEnv = "METRICS_DOMAIN"
|
||||||
|
|
||||||
// The following keys are used to configure metrics reporting.
|
// The following keys are used to configure metrics reporting.
|
||||||
// See https://github.com/knative/serving/blob/main/config/config-observability.yaml
|
// See https://github.com/knative/serving/blob/main/config/core/configmaps/observability.yaml
|
||||||
// for details.
|
// for details.
|
||||||
collectorAddressKey = "metrics.opencensus-address"
|
collectorAddressKey = "metrics.opencensus-address"
|
||||||
collectorSecureKey = "metrics.opencensus-require-tls"
|
collectorSecureKey = "metrics.opencensus-require-tls"
|
||||||
|
|
@ -49,6 +49,8 @@ const (
|
||||||
|
|
||||||
defaultBackendEnvName = "DEFAULT_METRICS_BACKEND"
|
defaultBackendEnvName = "DEFAULT_METRICS_BACKEND"
|
||||||
defaultPrometheusPort = 9090
|
defaultPrometheusPort = 9090
|
||||||
|
defaultPrometheusReportingPeriod = 5
|
||||||
|
defaultOpenCensusReportingPeriod = 60
|
||||||
maxPrometheusPort = 65535
|
maxPrometheusPort = 65535
|
||||||
minPrometheusPort = 1024
|
minPrometheusPort = 1024
|
||||||
defaultPrometheusHost = "0.0.0.0"
|
defaultPrometheusHost = "0.0.0.0"
|
||||||
|
|
@ -206,9 +208,9 @@ func createMetricsConfig(_ context.Context, ops ExporterOptions) (*metricsConfig
|
||||||
} else {
|
} else {
|
||||||
switch mc.backendDestination {
|
switch mc.backendDestination {
|
||||||
case openCensus:
|
case openCensus:
|
||||||
mc.reportingPeriod = time.Minute
|
mc.reportingPeriod = defaultOpenCensusReportingPeriod * time.Second
|
||||||
case prometheus:
|
case prometheus:
|
||||||
mc.reportingPeriod = 5 * time.Second
|
mc.reportingPeriod = defaultPrometheusReportingPeriod * time.Second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &mc, nil
|
return &mc, nil
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,10 @@ type ObservabilityConfig struct {
|
||||||
// OpenCensus. "None" disables all backends.
|
// OpenCensus. "None" disables all backends.
|
||||||
RequestMetricsBackend string
|
RequestMetricsBackend string
|
||||||
|
|
||||||
|
// RequestMetricsReportingPeriodSeconds specifies the request metrics reporting period in sec at queue proxy, eg 1.
|
||||||
|
// If a zero or negative value is passed the default reporting period is used (10 secs).
|
||||||
|
RequestMetricsReportingPeriodSeconds int
|
||||||
|
|
||||||
// EnableProfiling indicates whether it is allowed to retrieve runtime profiling data from
|
// EnableProfiling indicates whether it is allowed to retrieve runtime profiling data from
|
||||||
// the pods via an HTTP server in the format expected by the pprof visualization tool.
|
// the pods via an HTTP server in the format expected by the pprof visualization tool.
|
||||||
EnableProfiling bool
|
EnableProfiling bool
|
||||||
|
|
@ -114,6 +118,12 @@ func NewObservabilityConfigFromConfigMap(configMap *corev1.ConfigMap) (*Observab
|
||||||
return oc, nil
|
return oc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultRequestMetricsReportingPeriod, err := getDefaultRequestMetricsReportingPeriod(configMap.Data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = defaultRequestMetricsReportingPeriod
|
||||||
|
|
||||||
if err := cm.Parse(configMap.Data,
|
if err := cm.Parse(configMap.Data,
|
||||||
cm.AsBool("logging.enable-var-log-collection", &oc.EnableVarLogCollection),
|
cm.AsBool("logging.enable-var-log-collection", &oc.EnableVarLogCollection),
|
||||||
cm.AsString("logging.revision-url-template", &oc.LoggingURLTemplate),
|
cm.AsString("logging.revision-url-template", &oc.LoggingURLTemplate),
|
||||||
|
|
@ -121,6 +131,7 @@ func NewObservabilityConfigFromConfigMap(configMap *corev1.ConfigMap) (*Observab
|
||||||
cm.AsBool(EnableReqLogKey, &oc.EnableRequestLog),
|
cm.AsBool(EnableReqLogKey, &oc.EnableRequestLog),
|
||||||
cm.AsBool(EnableProbeReqLogKey, &oc.EnableProbeRequestLog),
|
cm.AsBool(EnableProbeReqLogKey, &oc.EnableProbeRequestLog),
|
||||||
cm.AsString("metrics.request-metrics-backend-destination", &oc.RequestMetricsBackend),
|
cm.AsString("metrics.request-metrics-backend-destination", &oc.RequestMetricsBackend),
|
||||||
|
cm.AsInt("metrics.request-metrics-reporting-period-seconds", &oc.RequestMetricsReportingPeriodSeconds),
|
||||||
cm.AsBool("profiling.enable", &oc.EnableProfiling),
|
cm.AsBool("profiling.enable", &oc.EnableProfiling),
|
||||||
cm.AsString("metrics.opencensus-address", &oc.MetricsCollectorAddress),
|
cm.AsString("metrics.opencensus-address", &oc.MetricsCollectorAddress),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
|
@ -163,3 +174,27 @@ func ConfigMapName() string {
|
||||||
}
|
}
|
||||||
return "config-observability"
|
return "config-observability"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the same as `metrics.reporting-period-seconds` for the default
|
||||||
|
// of `metrics.request-metrics-reporting-period-seconds`
|
||||||
|
func getDefaultRequestMetricsReportingPeriod(data map[string]string) (int, error) {
|
||||||
|
// Default backend is prometheus
|
||||||
|
period := defaultPrometheusReportingPeriod
|
||||||
|
if repStr := data[reportingPeriodKey]; repStr != "" {
|
||||||
|
repInt, err := strconv.Atoi(repStr)
|
||||||
|
if err != nil {
|
||||||
|
return -1, fmt.Errorf("invalid %s value %q", reportingPeriodKey, repStr)
|
||||||
|
}
|
||||||
|
period = repInt
|
||||||
|
} else {
|
||||||
|
if raw, ok := data["metrics.request-metrics-backend-destination"]; ok {
|
||||||
|
switch metricsBackend(raw) {
|
||||||
|
case prometheus:
|
||||||
|
period = defaultPrometheusReportingPeriod
|
||||||
|
case openCensus:
|
||||||
|
period = defaultOpenCensusReportingPeriod
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return period, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ func TestObservabilityConfiguration(t *testing.T) {
|
||||||
LoggingURLTemplate: "https://logging.io",
|
LoggingURLTemplate: "https://logging.io",
|
||||||
RequestLogTemplate: `{"requestMethod": "{{.Request.Method}}"}`,
|
RequestLogTemplate: `{"requestMethod": "{{.Request.Method}}"}`,
|
||||||
RequestMetricsBackend: "opencensus",
|
RequestMetricsBackend: "opencensus",
|
||||||
|
RequestMetricsReportingPeriodSeconds: defaultOpenCensusReportingPeriod,
|
||||||
},
|
},
|
||||||
data: map[string]string{
|
data: map[string]string{
|
||||||
EnableProbeReqLogKey: "true",
|
EnableProbeReqLogKey: "true",
|
||||||
|
|
@ -53,7 +54,11 @@ func TestObservabilityConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
name: "observability config with no map",
|
name: "observability config with no map",
|
||||||
wantConfig: defaultConfig(),
|
wantConfig: func() *ObservabilityConfig {
|
||||||
|
oc := defaultConfig()
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = defaultPrometheusReportingPeriod
|
||||||
|
return oc
|
||||||
|
}(),
|
||||||
}, {
|
}, {
|
||||||
name: "invalid request log template",
|
name: "invalid request log template",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
|
@ -72,6 +77,7 @@ func TestObservabilityConfiguration(t *testing.T) {
|
||||||
oc.EnableProbeRequestLog = true
|
oc.EnableProbeRequestLog = true
|
||||||
oc.EnableRequestLog = true
|
oc.EnableRequestLog = true
|
||||||
oc.LoggingURLTemplate = "https://logging.io"
|
oc.LoggingURLTemplate = "https://logging.io"
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = defaultPrometheusReportingPeriod
|
||||||
return oc
|
return oc
|
||||||
}(),
|
}(),
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -80,6 +86,7 @@ func TestObservabilityConfiguration(t *testing.T) {
|
||||||
oc := defaultConfig()
|
oc := defaultConfig()
|
||||||
oc.RequestLogTemplate = ""
|
oc.RequestLogTemplate = ""
|
||||||
oc.EnableProbeRequestLog = true
|
oc.EnableProbeRequestLog = true
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = defaultPrometheusReportingPeriod
|
||||||
return oc
|
return oc
|
||||||
}(),
|
}(),
|
||||||
data: map[string]string{
|
data: map[string]string{
|
||||||
|
|
@ -103,6 +110,7 @@ func TestObservabilityConfiguration(t *testing.T) {
|
||||||
oc.EnableProbeRequestLog = true
|
oc.EnableProbeRequestLog = true
|
||||||
oc.EnableVarLogCollection = true
|
oc.EnableVarLogCollection = true
|
||||||
oc.RequestLogTemplate = `{"requestMethod": "{{.Request.Method}}"}`
|
oc.RequestLogTemplate = `{"requestMethod": "{{.Request.Method}}"}`
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = defaultPrometheusReportingPeriod
|
||||||
return oc
|
return oc
|
||||||
}(),
|
}(),
|
||||||
data: map[string]string{
|
data: map[string]string{
|
||||||
|
|
@ -116,12 +124,27 @@ func TestObservabilityConfiguration(t *testing.T) {
|
||||||
oc := defaultConfig()
|
oc := defaultConfig()
|
||||||
oc.RequestMetricsBackend = "opencensus"
|
oc.RequestMetricsBackend = "opencensus"
|
||||||
oc.MetricsCollectorAddress = "otel:55678"
|
oc.MetricsCollectorAddress = "otel:55678"
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = defaultOpenCensusReportingPeriod
|
||||||
return oc
|
return oc
|
||||||
}(),
|
}(),
|
||||||
data: map[string]string{
|
data: map[string]string{
|
||||||
"metrics.request-metrics-backend-destination": "opencensus",
|
"metrics.request-metrics-backend-destination": "opencensus",
|
||||||
"metrics.opencensus-address": "otel:55678",
|
"metrics.opencensus-address": "otel:55678",
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
name: "observability configuration with collector address and reporting period",
|
||||||
|
wantConfig: func() *ObservabilityConfig {
|
||||||
|
oc := defaultConfig()
|
||||||
|
oc.RequestMetricsBackend = "opencensus"
|
||||||
|
oc.MetricsCollectorAddress = "otel:55678"
|
||||||
|
oc.RequestMetricsReportingPeriodSeconds = 10
|
||||||
|
return oc
|
||||||
|
}(),
|
||||||
|
data: map[string]string{
|
||||||
|
"metrics.request-metrics-backend-destination": "opencensus",
|
||||||
|
"metrics.opencensus-address": "otel:55678",
|
||||||
|
"metrics.request-metrics-reporting-period-seconds": "10",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tt := range observabilityConfigTests {
|
for _, tt := range observabilityConfigTests {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue