-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[HCP Telemetry] Periodic Refresh for Dynamic Telemetry Configuration #18168
Changes from all commits
00cee32
77f09b8
ff4d85f
0264d5b
f12219a
8b4bf1d
5b4c997
7550818
3f1c53d
8dce916
2313673
196a4ef
3b031a2
cb869b1
38d6bca
1feea25
0d25ba4
a58baa7
f3be3ec
a353527
de55bf9
eacf20e
4ed2b74
e3839b3
b867e30
d4b788a
932633e
696966f
1d58bf6
fea50d4
bfebfb1
54eb748
9677781
c23798c
235acac
1ef0795
2e10100
952129c
b46d5b9
7ea6280
d3522ee
aaec9a6
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
hcp: Add dynamic configuration support for the export of server metrics to HCP. | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,21 +35,6 @@ type Client interface { | |
DiscoverServers(ctx context.Context) ([]string, error) | ||
} | ||
|
||
// MetricsConfig holds metrics specific configuration for the TelemetryConfig. | ||
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. Moved to new file |
||
// The endpoint field overrides the TelemetryConfig endpoint. | ||
type MetricsConfig struct { | ||
Filters []string | ||
Endpoint string | ||
} | ||
|
||
// TelemetryConfig contains configuration for telemetry data forwarded by Consul servers | ||
// to the HCP Telemetry gateway. | ||
type TelemetryConfig struct { | ||
Endpoint string | ||
Labels map[string]string | ||
MetricsConfig *MetricsConfig | ||
} | ||
|
||
type BootstrapConfig struct { | ||
Name string | ||
BootstrapExpect int | ||
|
@@ -112,10 +97,14 @@ func (c *hcpClient) FetchTelemetryConfig(ctx context.Context) (*TelemetryConfig, | |
|
||
resp, err := c.tgw.AgentTelemetryConfig(params, nil) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("failed to fetch from HCP: %w", err) | ||
} | ||
|
||
if err := validateAgentTelemetryConfigPayload(resp); err != nil { | ||
return nil, fmt.Errorf("invalid response payload: %w", err) | ||
} | ||
|
||
return convertTelemetryConfig(resp) | ||
return convertAgentTelemetryResponse(ctx, resp, c.cfg) | ||
} | ||
|
||
func (c *hcpClient) FetchBootstrap(ctx context.Context) (*BootstrapConfig, error) { | ||
|
@@ -272,60 +261,3 @@ func (c *hcpClient) DiscoverServers(ctx context.Context) ([]string, error) { | |
|
||
return servers, nil | ||
} | ||
|
||
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. Moved conversions to new file |
||
// convertTelemetryConfig validates the AgentTelemetryConfig payload and converts it into a TelemetryConfig object. | ||
func convertTelemetryConfig(resp *hcptelemetry.AgentTelemetryConfigOK) (*TelemetryConfig, error) { | ||
if resp.Payload == nil { | ||
return nil, fmt.Errorf("missing payload") | ||
} | ||
|
||
if resp.Payload.TelemetryConfig == nil { | ||
return nil, fmt.Errorf("missing telemetry config") | ||
} | ||
|
||
payloadConfig := resp.Payload.TelemetryConfig | ||
var metricsConfig MetricsConfig | ||
if payloadConfig.Metrics != nil { | ||
metricsConfig.Endpoint = payloadConfig.Metrics.Endpoint | ||
metricsConfig.Filters = payloadConfig.Metrics.IncludeList | ||
} | ||
return &TelemetryConfig{ | ||
Endpoint: payloadConfig.Endpoint, | ||
Labels: payloadConfig.Labels, | ||
MetricsConfig: &metricsConfig, | ||
}, nil | ||
} | ||
|
||
// Enabled verifies if telemetry is enabled by ensuring a valid endpoint has been retrieved. | ||
// It returns full metrics endpoint and true if a valid endpoint was obtained. | ||
func (t *TelemetryConfig) Enabled() (string, bool) { | ||
endpoint := t.Endpoint | ||
if override := t.MetricsConfig.Endpoint; override != "" { | ||
endpoint = override | ||
} | ||
|
||
if endpoint == "" { | ||
return "", false | ||
} | ||
|
||
// The endpoint from Telemetry Gateway is a domain without scheme, and without the metrics path, so they must be added. | ||
return endpoint + metricsGatewayPath, true | ||
} | ||
|
||
// DefaultLabels returns a set of <key, value> string pairs that must be added as attributes to all exported telemetry data. | ||
func (t *TelemetryConfig) DefaultLabels(cfg config.CloudConfig) map[string]string { | ||
labels := make(map[string]string) | ||
nodeID := string(cfg.NodeID) | ||
if nodeID != "" { | ||
labels["node_id"] = nodeID | ||
} | ||
if cfg.NodeName != "" { | ||
labels["node_name"] = cfg.NodeName | ||
} | ||
|
||
for k, v := range t.Labels { | ||
labels[k] = v | ||
} | ||
|
||
return labels | ||
} |
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. Removed most tests in this file to put them in |
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.
Changes:
TelemetryConfig
,MetricsConfig
, newRefreshConfig
and the conversions into thetelemetry_config.go
fileWhy this refactor?
deps.go
andtelemetry_config_provider.go
. It also avoids code duplication.