Add root-level cluster_name and standardize collection_interval for OpenTelemetry features#2189
Add root-level cluster_name and standardize collection_interval for OpenTelemetry features#2189Paamicky wants to merge 13 commits into
Conversation
| transform/set_cluster_name: | ||
| error_mode: ignore | ||
| flatten_data: false | ||
| log_statements: | ||
| - context: resource | ||
| error_mode: ignore | ||
| statements: | ||
| - set(resource.attributes["k8s.cluster.name"], "TestCluster") | ||
| metric_statements: [] | ||
| trace_statements: [] |
There was a problem hiding this comment.
Shouldn't this have resource statements for each of the resource types? I see the same processor is being used in metric pipelines as well.
There was a problem hiding this comment.
Fixed. otlp logs now uses its own processor (transform/set_cluster_name_logs) so it doesn't overwrite the metric_statements used by the metrics pipelines
There was a problem hiding this comment.
Can't they share a single transform processor?
There was a problem hiding this comment.
Fixed. set_cluster_name now registers with both metric_statements and log_statements in a single processor. Pipelines will use statements relevant to its signal.
WithTraceResourceStatements is not yet supported in the transform processor.
// Traces are not handled: WithTraceResourceStatements is not yet supported.
// Traces sent via OTLP on EKS should include k8s.cluster.name from the SDK.
This will need a separate PR if we want to add it.
There was a problem hiding this comment.
Can you add WithTraceResourceStatements or a WithResourceStatements to that transformprocessor translator so it's consistent?
23cab82 to
59cea26
Compare
|
|
||
| // GetCollectionInterval returns the collection interval for an OpenTelemetry feature. | ||
| // It checks the feature-specific collection_interval field. Default is 30s. | ||
| func GetCollectionInterval(conf *confmap.Conf, featureKey string) time.Duration { |
There was a problem hiding this comment.
This does the exact same thing as GetOrDefaultDuration
There was a problem hiding this comment.
yeah removed to use the already existing function: GetOrDefaultDuration
|
|
||
| // GetOtelClusterName returns the cluster name for OpenTelemetry-based features. | ||
| // It reads exclusively from opentelemetry::cluster_name. | ||
| func GetOtelClusterName(conf *confmap.Conf) string { |
There was a problem hiding this comment.
I don't think we need a separate function for this.
There was a problem hiding this comment.
removed the function wrapper and defined inline at each call site.
| } | ||
|
|
||
| // DefaultCollectionInterval is the default collection interval for OpenTelemetry-based features. | ||
| const DefaultCollectionInterval = 30 * time.Second |
There was a problem hiding this comment.
Don't define this here. It doesn't apply to all cases of collection interval. It's only for the opentelemetry pipelines.
There was a problem hiding this comment.
Moved to a local constant in each package that uses it.
d7d65ea to
23ade6b
Compare
| "opentelemetry": map[string]interface{}{ | ||
| "collect": map[string]interface{}{ | ||
| "container_insights": map[string]interface{}{ | ||
| "cluster_name": "test-cluster", |
There was a problem hiding this comment.
seems like the cluster_name field is still showing up under container_insights section instead of showing up under opentelemetry/collect section, mind updating this please ?
…OpenTelemetry features
…OpenTelemetry features
a522694 to
939e783
Compare
5689959 to
65265df
Compare
Binary Size Reportlinux/amd64
Notable changes:
linux/arm64
windows/amd64
Investigating size changesUse go-size-analyzer to compare binaries: GOEXPERIMENT=jsonv2 go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa diff --old <baseline-binary> --new <new-binary> |
| transform/set_cluster_name: | ||
| error_mode: ignore | ||
| flatten_data: false | ||
| log_statements: | ||
| - context: resource | ||
| error_mode: ignore | ||
| statements: | ||
| - set(resource.attributes["k8s.cluster.name"], "TestCluster") | ||
| metric_statements: [] | ||
| trace_statements: [] |
There was a problem hiding this comment.
Can you add WithTraceResourceStatements or a WithResourceStatements to that transformprocessor translator so it's consistent?
10d20a4 to
8ca11d7
Compare
| transform/set_cluster_name: | ||
| error_mode: ignore | ||
| flatten_data: false | ||
| log_statements: [] | ||
| metric_statements: | ||
| metric_statements: [] | ||
| trace_statements: | ||
| - context: resource | ||
| error_mode: ignore | ||
| statements: | ||
| - set(resource.attributes["k8s.cluster.name"], "TestCluster") |
There was a problem hiding this comment.
This isn't quite right. I would expect to see the same statement in each of the *_statements sections.
transform/set_cluster_name:
error_mode: ignore
flatten_data: false
log_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["k8s.cluster.name"], "TestCluster")
metric_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["k8s.cluster.name"], "TestCluster")
trace_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["k8s.cluster.name"], "TestCluster")| "type": "object", | ||
| "properties": { | ||
| "cluster_name": { | ||
| "description": "The name of the EKS/AKS cluster. Applied to all components under opentelemetry.", |
There was a problem hiding this comment.
nit:
| "description": "The name of the EKS/AKS cluster. Applied to all components under opentelemetry.", | |
| "description": "The name of the k8s cluster. Applied to all telemetry collected under opentelemetry.", |
| stmt := fmt.Sprintf(`set(resource.attributes["k8s.cluster.name"], "%s")`, clusterName) | ||
| processors.Set(transformprocessor.NewTranslatorWithName("set_cluster_name", | ||
| transformprocessor.WithTraceResourceStatements([]string{stmt}), | ||
| )) |
There was a problem hiding this comment.
Each of the set_cluster_name transform processors needs to have all three ResourceStatements set because the same transform processor is used in all pipelines.
| )) | |
| stmt := fmt.Sprintf(`set(resource.attributes["k8s.cluster.name"], "%s")`, clusterName) | |
| processors.Set(transformprocessor.NewTranslatorWithName("set_cluster_name", | |
| transformprocessor.WithMetricResourceStatements([]string{stmt}), | |
| transformprocessor.WithLogResourceStatements([]string{stmt}), | |
| transformprocessor.WithTraceResourceStatements([]string{stmt}), | |
| )) |
There was a problem hiding this comment.
nit: Can revert the changes for this file.
| // clusterNameRegex restricts cluster_name to safe characters, preventing | ||
| // OTTL injection and template metacharacter issues in YAML templates. | ||
| var clusterNameRegex = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`) | ||
| var otelClusterNameKey = common.ConfigKey(common.OpenTelemetryKey, common.ClusterNameKey) |
There was a problem hiding this comment.
Define this in common and reuse it for all of the cluster name checks.
| yamlConfig, err := mapstructure.Marshal(cfg) | ||
| require.NoError(t, err) | ||
| yamlStr := toyamlconfig.ToYamlConfig(yamlConfig) | ||
| // os.WriteFile("./sampleConfig/opentelemetry/container_insights_config.yaml", []byte(yamlStr), 0644) |
There was a problem hiding this comment.
nit: Don't leave commented out code unnecessarily.
Description of the issue
The OpenTelemetry config section had two inconsistencies: cluster_name was required per-component, forcing customers to repeat the same cluster value for every feature, and the collection interval field name differed across features (metrics_collection_interval vs collection_interval). This has been updated to use the newer version
collection_interval.Description of changes
cluster_name: Moved toopentelemetry.cluster_name. A single value now applies to all features (Container Insights, Prometheus, Host Metrics, OTLP). Container Insights and Prometheus require it; Host Metrics and OTLP apply it when present.collection_interval: All OpenTelemetry features now use collection_interval with a 30-second default. Host Metrics renamed frommetrics_collection_interval. Database Insights retains its own hardcoded intervals.cluster_namefield and standardizedcollection_intervalacross features.CWAGENT_ROLEenvironmentvariable naming.
Tests
GetOtelClusterNameverifies root-level reads, env var is not used as fallback, empty config returns emptyLicense
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.