-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[HCP Telemetry] Move first TelemetryConfig Fetch into the TelemetryConfigProvider #18318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3810663
76d40eb
17917a1
e2020e6
bc356c3
d3ff4fd
0fa2160
3e7bd17
d355427
e67ba41
9c8711c
150fb64
1b3d71a
4769d7b
89cb0d3
aa9f8a6
b11d972
2a784ae
50266bd
24e9a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ import ( | |
|
|
||
| var ( | ||
| // defaultMetricFilters is a regex that matches all metric names. | ||
| defaultMetricFilters = regexp.MustCompile(".+") | ||
| DefaultMetricFilters = regexp.MustCompile(".+") | ||
|
|
||
| // Validation errors for AgentTelemetryConfigOK response. | ||
| errMissingPayload = errors.New("missing payload") | ||
|
|
@@ -29,6 +29,7 @@ var ( | |
| errMissingMetricsConfig = errors.New("missing metrics config") | ||
| errInvalidRefreshInterval = errors.New("invalid refresh interval") | ||
| errInvalidEndpoint = errors.New("invalid metrics endpoint") | ||
| errEmptyEndpoint = errors.New("empty metrics endpoint") | ||
| ) | ||
|
|
||
| // TelemetryConfig contains configuration for telemetry data forwarded by Consul servers | ||
|
|
@@ -43,18 +44,14 @@ type MetricsConfig struct { | |
| Labels map[string]string | ||
| Filters *regexp.Regexp | ||
| Endpoint *url.URL | ||
| Disabled bool | ||
| } | ||
|
|
||
| // RefreshConfig contains configuration for the periodic fetch of configuration from HCP. | ||
| type RefreshConfig struct { | ||
| RefreshInterval time.Duration | ||
| } | ||
|
|
||
| // MetricsEnabled returns true if metrics export is enabled, i.e. a valid metrics endpoint exists. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this func and the empty endpoint logic since we now have a |
||
| func (t *TelemetryConfig) MetricsEnabled() bool { | ||
| return t.MetricsConfig.Endpoint != nil | ||
| } | ||
|
|
||
| // validateAgentTelemetryConfigPayload ensures the returned payload from HCP is valid. | ||
| func validateAgentTelemetryConfigPayload(resp *hcptelemetry.AgentTelemetryConfigOK) error { | ||
| if resp.Payload == nil { | ||
|
|
@@ -86,7 +83,7 @@ func convertAgentTelemetryResponse(ctx context.Context, resp *hcptelemetry.Agent | |
| telemetryConfig := resp.Payload.TelemetryConfig | ||
| metricsEndpoint, err := convertMetricEndpoint(telemetryConfig.Endpoint, telemetryConfig.Metrics.Endpoint) | ||
| if err != nil { | ||
| return nil, errInvalidEndpoint | ||
| return nil, err | ||
| } | ||
|
|
||
| metricsFilters := convertMetricFilters(ctx, telemetryConfig.Metrics.IncludeList) | ||
|
|
@@ -97,6 +94,7 @@ func convertAgentTelemetryResponse(ctx context.Context, resp *hcptelemetry.Agent | |
| Endpoint: metricsEndpoint, | ||
| Labels: metricLabels, | ||
| Filters: metricsFilters, | ||
| Disabled: telemetryConfig.Metrics.Disabled, | ||
jjti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| RefreshConfig: &RefreshConfig{ | ||
| RefreshInterval: refreshInterval, | ||
|
|
@@ -114,9 +112,8 @@ func convertMetricEndpoint(telemetryEndpoint string, metricsEndpoint string) (*u | |
| endpoint = metricsEndpoint | ||
| } | ||
|
|
||
| // If endpoint is empty, server not registered with CCM, no error returned. | ||
| if endpoint == "" { | ||
| return nil, nil | ||
| return nil, errEmptyEndpoint | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like known errors. Good stuff. |
||
| } | ||
|
|
||
| // Endpoint from CTW has no metrics path, so it must be added. | ||
|
|
@@ -145,15 +142,15 @@ func convertMetricFilters(ctx context.Context, payloadFilters []string) *regexp. | |
|
|
||
| if len(validFilters) == 0 { | ||
| logger.Error("no valid filters") | ||
| return defaultMetricFilters | ||
| return DefaultMetricFilters | ||
| } | ||
|
|
||
| // Combine the valid regex strings with OR. | ||
| finalRegex := strings.Join(validFilters, "|") | ||
| composedRegex, err := regexp.Compile(finalRegex) | ||
| if err != nil { | ||
| logger.Error("failed to compile final regex", "error", err) | ||
| return defaultMetricFilters | ||
| return DefaultMetricFilters | ||
| } | ||
|
|
||
| return composedRegex | ||
|
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export this to use as default in https://github.com/hashicorp/consul/pull/18318/files#diff-9fd2535b13a1b9701661bdd379418cb004a41b5b747ff9911e8cbbffea54b9afR60.
In case the first fetch is not available, this default is set to all metrics.