From 534cf019b848bb59c9121f1a3a6953c5a1cac333 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 11:18:44 +0200 Subject: [PATCH 01/28] [processor/resourcedetection] introduce kubeadm detector Signed-off-by: odubajDT --- .../metadataproviders/kubeadm/metadata.go | 48 ++++++++++++++ .../resourcedetectionprocessor/README.md | 43 +++++++++++++ .../internal/kubeadm/config.go | 49 +++++++++++++++ .../internal/kubeadm/config_test.go | 1 + .../kubeadm/generated_package_test.go | 13 ++++ .../internal/metadata/generated_config.go | 39 ++++++++++++ .../internal/metadata/generated_resource.go | 36 +++++++++++ .../kubeadm/internal/metadata/package_test.go | 14 +++++ .../internal/metadata/testdata/config.yaml | 9 +++ .../internal/kubeadm/kubeadm.go | 62 +++++++++++++++++++ .../internal/kubeadm/kubeadm_test.go | 1 + .../internal/kubeadm/metadata.yaml | 14 +++++ 12 files changed, 329 insertions(+) create mode 100644 internal/metadataproviders/kubeadm/metadata.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/config.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/config_test.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/generated_package_test.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/package_test.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/testdata/config.yaml create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml diff --git a/internal/metadataproviders/kubeadm/metadata.go b/internal/metadataproviders/kubeadm/metadata.go new file mode 100644 index 000000000000..fdb50de5b405 --- /dev/null +++ b/internal/metadataproviders/kubeadm/metadata.go @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package kubeadm // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/kubeadm" + +import ( + "context" + "fmt" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" +) + +type Provider interface { + // ClusterName returns the current K8S Node Name + ClusterName(ctx context.Context) (string, error) +} + +type kubeadmProvider struct { + kubeadmClient kubernetes.Interface + configMapName string + configMapNamespace string +} + +func NewProvider(configMapName string, configMapNamespace string, apiConf k8sconfig.APIConfig) (Provider, error) { + if configMapName == "" || configMapNamespace == "" { + return nil, fmt.Errorf("configMapName and configMapNamespace can't be empty") + } + k8sAPIClient, err := k8sconfig.MakeClient(apiConf) + if err != nil { + return nil, fmt.Errorf("failed to create K8s API client: %w", err) + } + return &kubeadmProvider{ + kubeadmClient: k8sAPIClient, + configMapName: configMapName, + configMapNamespace: configMapNamespace, + }, nil +} + +func (k *kubeadmProvider) ClusterName(ctx context.Context) (string, error) { + cluster, err := k.kubeadmClient.CoreV1().ConfigMaps(k.configMapNamespace).Get(ctx, k.configMapName, metav1.GetOptions{}) + if err != nil { + return "", fmt.Errorf("failed to fetch ConfigMap with name %s and namespace %s from K8s API: %w", k.configMapName, k.configMapNamespace, err) + } + return cluster.Name, nil +} diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index 30e91a3d6227..e6ba1a7fb0fe 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -424,6 +424,49 @@ processors: override: false ``` +### Heroku + +** You must first enable the [Heroku metadata feature](https://devcenter.heroku.com/articles/dyno-metadata) on the application ** + +Queries [Heroku metadata](https://devcenter.heroku.com/articles/dyno-metadata) to retrieve the following resource attributes: + +* heroku.release.version (identifier for the current release) +* heroku.release.creation_timestamp (time and date the release was created) +* heroku.release.commit (commit hash for the current release) +* heroku.app.name (application name) +* heroku.app.id (unique identifier for the application) +* heroku.dyno.id (dyno identifier. Used as host name) + +```yaml +processors: + resourcedetection/heroku: + detectors: [env, heroku] + timeout: 2s + override: false +``` + +### Kubeadm Metadata + +Queries the K8S api server to retrieve the following node resource attributes: + + * k8s.cluster.name + +The following permissions are required: +```yaml +kind: ClusterRole +metadata: + name: otel-collector +rules: + - apiGroups: [""] + resources: ["configmaps"] + verbs: ["get", "list"] +``` + +| Name | Type | Required | Default | Docs | +| ---- | ---- |----------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| auth_type | string | No | `serviceAccount` | How to authenticate to the K8s API server. This can be one of `none` (for no auth), `serviceAccount` (to use the standard service account token provided to the agent pod), or `kubeConfig` to use credentials from `~/.kube/config`. | +| node_from_env_var | string | Yes | `K8S_NODE_NAME` | The environment variable name that holds the name of the node to retrieve metadata from. Default value is `K8S_NODE_NAME`. You can set the env dynamically on the workload definition using the downward API; see example + ### K8S Node Metadata Queries the K8S api server to retrieve node resource attributes. diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config.go b/processor/resourcedetectionprocessor/internal/kubeadm/config.go new file mode 100644 index 000000000000..990816e729d0 --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config.go @@ -0,0 +1,49 @@ +package kubeadm + +import ( + "fmt" + "os" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata" +) + +type Config struct { + k8sconfig.APIConfig `mapstructure:",squash"` + ConfigMapNameFromEnvVar string `mapstructure:"configmap_name_from_env_var"` + ConfigMapNamespaceFromEnvVar string `mapstructure:"configmap_namespace_from_env_var"` + ResourceAttributes metadata.ResourceAttributesConfig `mapstructure:"resource_attributes"` + configMapName string + configMapNamespace string +} + +// UpdateDefaults validates and update the default config with user's provided settings +func (c *Config) UpdateDefaults() error { + c.configMapName = "kubeadm-config" + c.configMapNamespace = "kube-system" + + if c.ConfigMapNameFromEnvVar != "" { + value, envExists := os.LookupEnv(c.ConfigMapNameFromEnvVar) + if !envExists || value == "" { + return fmt.Errorf("ConfigMap name can't be found. Check the readme on how to set the required env variable") + } + c.configMapName = value + } + + if c.ConfigMapNamespaceFromEnvVar != "" { + value, envExists := os.LookupEnv(c.ConfigMapNamespaceFromEnvVar) + if !envExists || value == "" { + return fmt.Errorf("ConfigMap namespace can't be found. Check the readme on how to set the required env variable") + } + c.configMapNamespace = value + } + + return nil +} + +func CreateDefaultConfig() Config { + return Config{ + APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount}, + ResourceAttributes: metadata.DefaultResourceAttributesConfig(), + } +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go new file mode 100644 index 000000000000..accfb5b144a1 --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go @@ -0,0 +1 @@ +package kubeadm diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/generated_package_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/generated_package_test.go new file mode 100644 index 000000000000..4dc8cc67e4da --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/generated_package_test.go @@ -0,0 +1,13 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package kubeadm + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config.go new file mode 100644 index 000000000000..cb9d4839877d --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config.go @@ -0,0 +1,39 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/confmap" +) + +// ResourceAttributeConfig provides common config for a particular resource attribute. +type ResourceAttributeConfig struct { + Enabled bool `mapstructure:"enabled"` + + enabledSetByUser bool +} + +func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error { + if parser == nil { + return nil + } + err := parser.Unmarshal(rac) + if err != nil { + return err + } + rac.enabledSetByUser = parser.IsSet("enabled") + return nil +} + +// ResourceAttributesConfig provides config for resourcedetectionprocessor/kubeadm resource attributes. +type ResourceAttributesConfig struct { + K8sClusterName ResourceAttributeConfig `mapstructure:"k8s.cluster.name"` +} + +func DefaultResourceAttributesConfig() ResourceAttributesConfig { + return ResourceAttributesConfig{ + K8sClusterName: ResourceAttributeConfig{ + Enabled: true, + }, + } +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource.go new file mode 100644 index 000000000000..83834dfd62c8 --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource.go @@ -0,0 +1,36 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/pdata/pcommon" +) + +// ResourceBuilder is a helper struct to build resources predefined in metadata.yaml. +// The ResourceBuilder is not thread-safe and must not to be used in multiple goroutines. +type ResourceBuilder struct { + config ResourceAttributesConfig + res pcommon.Resource +} + +// NewResourceBuilder creates a new ResourceBuilder. This method should be called on the start of the application. +func NewResourceBuilder(rac ResourceAttributesConfig) *ResourceBuilder { + return &ResourceBuilder{ + config: rac, + res: pcommon.NewResource(), + } +} + +// SetK8sClusterName sets provided value as "k8s.cluster.name" attribute. +func (rb *ResourceBuilder) SetK8sClusterName(val string) { + if rb.config.K8sClusterName.Enabled { + rb.res.Attributes().PutStr("k8s.cluster.name", val) + } +} + +// Emit returns the built resource and resets the internal builder state. +func (rb *ResourceBuilder) Emit() pcommon.Resource { + r := rb.res + rb.res = pcommon.NewResource() + return r +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/package_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/package_test.go new file mode 100644 index 000000000000..1aba5ec4bb0b --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package metadata + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/testdata/config.yaml b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/testdata/config.yaml new file mode 100644 index 000000000000..4017b2f2932c --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/testdata/config.yaml @@ -0,0 +1,9 @@ +default: +all_set: + resource_attributes: + k8s.cluster.name: + enabled: true +none_set: + resource_attributes: + k8s.cluster.name: + enabled: false diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go new file mode 100644 index 000000000000..4321c15e9ca4 --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go @@ -0,0 +1,62 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package kubeadm // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/k8snode" + +import ( + "context" + "fmt" + + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/processor" + conventions "go.opentelemetry.io/collector/semconv/v1.6.1" + "go.uber.org/zap" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/kubeadm" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata" +) + +const ( + TypeStr = "kubeadm" +) + +var _ internal.Detector = (*detector)(nil) + +type detector struct { + provider kubeadm.Provider + logger *zap.Logger + ra *metadata.ResourceAttributesConfig + rb *metadata.ResourceBuilder +} + +func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal.Detector, error) { + cfg := dcfg.(Config) + if err := cfg.UpdateDefaults(); err != nil { + return nil, err + } + + k8snodeProvider, err := kubeadm.NewProvider(cfg.configMapName, cfg.configMapNamespace, cfg.APIConfig) + if err != nil { + return nil, fmt.Errorf("failed creating kubeadm provider: %w", err) + } + + return &detector{ + provider: k8snodeProvider, + logger: set.Logger, + ra: &cfg.ResourceAttributes, + rb: metadata.NewResourceBuilder(cfg.ResourceAttributes), + }, nil +} + +func (d *detector) Detect(ctx context.Context) (resource pcommon.Resource, schemaURL string, err error) { + if d.ra.K8sClusterName.Enabled { + clusterName, err := d.provider.ClusterName(ctx) + if err != nil { + return pcommon.NewResource(), "", fmt.Errorf("failed getting k8s cluster name: %w", err) + } + d.rb.SetK8sClusterName(clusterName) + } + + return d.rb.Emit(), conventions.SchemaURL, nil +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go new file mode 100644 index 000000000000..accfb5b144a1 --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go @@ -0,0 +1 @@ +package kubeadm diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml b/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml new file mode 100644 index 000000000000..b3d129f6af84 --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml @@ -0,0 +1,14 @@ +type: resourcedetectionprocessor/kubeadm + +parent: resourcedetection + +status: + class: pkg + codeowners: + active: + +resource_attributes: + k8s.cluster.name: + description: The Kubernetes cluster name + type: string + enabled: true From bcf33b2fdb3645d4be72c66340caab94c006beac Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 11:20:19 +0200 Subject: [PATCH 02/28] add chlog Signed-off-by: odubajDT --- .../resourcedetection-local-cluster.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/resourcedetection-local-cluster.yaml diff --git a/.chloggen/resourcedetection-local-cluster.yaml b/.chloggen/resourcedetection-local-cluster.yaml new file mode 100644 index 000000000000..f76273fb32eb --- /dev/null +++ b/.chloggen/resourcedetection-local-cluster.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: resourcedetectionprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Introduce kubeadm detector to retrieve local cluster name. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35116] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From e4f7663a500577334072320127c04ba0208530f8 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 11:29:13 +0200 Subject: [PATCH 03/28] fix chlog Signed-off-by: odubajDT --- .chloggen/resourcedetection-local-cluster.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.chloggen/resourcedetection-local-cluster.yaml b/.chloggen/resourcedetection-local-cluster.yaml index f76273fb32eb..2227c7ef6d22 100644 --- a/.chloggen/resourcedetection-local-cluster.yaml +++ b/.chloggen/resourcedetection-local-cluster.yaml @@ -1,13 +1,13 @@ # Use this changelog template to create an entry for release notes. # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: +change_type: enhancement # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) component: resourcedetectionprocessor # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Introduce kubeadm detector to retrieve local cluster name. +note: "Introduce kubeadm detector to retrieve local cluster name." # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [35116] From 3eb6a0a33f9f6532ee7f9ba7ed331fd36b247441 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 13:46:23 +0200 Subject: [PATCH 04/28] polish config implementation Signed-off-by: odubajDT --- .../resourcedetectionprocessor/README.md | 1 - .../internal/kubeadm/config.go | 36 +++++-------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index e6ba1a7fb0fe..c138d902792e 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -465,7 +465,6 @@ rules: | Name | Type | Required | Default | Docs | | ---- | ---- |----------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | auth_type | string | No | `serviceAccount` | How to authenticate to the K8s API server. This can be one of `none` (for no auth), `serviceAccount` (to use the standard service account token provided to the agent pod), or `kubeConfig` to use credentials from `~/.kube/config`. | -| node_from_env_var | string | Yes | `K8S_NODE_NAME` | The environment variable name that holds the name of the node to retrieve metadata from. Default value is `K8S_NODE_NAME`. You can set the env dynamically on the workload definition using the downward API; see example ### K8S Node Metadata diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config.go b/processor/resourcedetectionprocessor/internal/kubeadm/config.go index 990816e729d0..45e3a24916e0 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config.go @@ -1,42 +1,24 @@ package kubeadm import ( - "fmt" - "os" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata" ) type Config struct { - k8sconfig.APIConfig `mapstructure:",squash"` - ConfigMapNameFromEnvVar string `mapstructure:"configmap_name_from_env_var"` - ConfigMapNamespaceFromEnvVar string `mapstructure:"configmap_namespace_from_env_var"` - ResourceAttributes metadata.ResourceAttributesConfig `mapstructure:"resource_attributes"` - configMapName string - configMapNamespace string + k8sconfig.APIConfig `mapstructure:",squash"` + ResourceAttributes metadata.ResourceAttributesConfig `mapstructure:"resource_attributes"` + configMapName string + configMapNamespace string } +const defaultConfigMapName = "kubeadm-config" +const defaultConfigMapNamespace = "kube-system" + // UpdateDefaults validates and update the default config with user's provided settings func (c *Config) UpdateDefaults() error { - c.configMapName = "kubeadm-config" - c.configMapNamespace = "kube-system" - - if c.ConfigMapNameFromEnvVar != "" { - value, envExists := os.LookupEnv(c.ConfigMapNameFromEnvVar) - if !envExists || value == "" { - return fmt.Errorf("ConfigMap name can't be found. Check the readme on how to set the required env variable") - } - c.configMapName = value - } - - if c.ConfigMapNamespaceFromEnvVar != "" { - value, envExists := os.LookupEnv(c.ConfigMapNamespaceFromEnvVar) - if !envExists || value == "" { - return fmt.Errorf("ConfigMap namespace can't be found. Check the readme on how to set the required env variable") - } - c.configMapNamespace = value - } + c.configMapName = defaultConfigMapName + c.configMapNamespace = defaultConfigMapNamespace return nil } From df3d293c9a47f618034641fedcd786b5ab439855 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 13:48:02 +0200 Subject: [PATCH 05/28] create test files Signed-off-by: odubajDT --- .../internal/kubeadm/internal/metadata/generated_config_test.go | 1 + .../kubeadm/internal/metadata/generated_resource_test.go | 1 + 2 files changed, 2 insertions(+) create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go new file mode 100644 index 000000000000..82c48461b5cf --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go @@ -0,0 +1 @@ +package metadata diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go new file mode 100644 index 000000000000..82c48461b5cf --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go @@ -0,0 +1 @@ +package metadata From 11caca755b23a67b3210240f647925ee1195e1b7 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 13:49:53 +0200 Subject: [PATCH 06/28] add test files to internal Signed-off-by: odubajDT --- .../metadataproviders/kubeadm/metadata_test.go | 1 + internal/metadataproviders/kubeadm/package_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 internal/metadataproviders/kubeadm/metadata_test.go create mode 100644 internal/metadataproviders/kubeadm/package_test.go diff --git a/internal/metadataproviders/kubeadm/metadata_test.go b/internal/metadataproviders/kubeadm/metadata_test.go new file mode 100644 index 000000000000..accfb5b144a1 --- /dev/null +++ b/internal/metadataproviders/kubeadm/metadata_test.go @@ -0,0 +1 @@ +package kubeadm diff --git a/internal/metadataproviders/kubeadm/package_test.go b/internal/metadataproviders/kubeadm/package_test.go new file mode 100644 index 000000000000..48baf7f293d0 --- /dev/null +++ b/internal/metadataproviders/kubeadm/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package kubeadm + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} From 02ee56c740c4b8e839d90126aeeaea713b9aad36 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 14:20:03 +0200 Subject: [PATCH 07/28] add tests for metadata Signed-off-by: odubajDT --- .../metadataproviders/kubeadm/metadata.go | 5 +- .../kubeadm/metadata_test.go | 92 +++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/internal/metadataproviders/kubeadm/metadata.go b/internal/metadataproviders/kubeadm/metadata.go index fdb50de5b405..3dd4253f33d3 100644 --- a/internal/metadataproviders/kubeadm/metadata.go +++ b/internal/metadataproviders/kubeadm/metadata.go @@ -40,9 +40,10 @@ func NewProvider(configMapName string, configMapNamespace string, apiConf k8scon } func (k *kubeadmProvider) ClusterName(ctx context.Context) (string, error) { - cluster, err := k.kubeadmClient.CoreV1().ConfigMaps(k.configMapNamespace).Get(ctx, k.configMapName, metav1.GetOptions{}) + configmap, err := k.kubeadmClient.CoreV1().ConfigMaps(k.configMapNamespace).Get(ctx, k.configMapName, metav1.GetOptions{}) if err != nil { return "", fmt.Errorf("failed to fetch ConfigMap with name %s and namespace %s from K8s API: %w", k.configMapName, k.configMapNamespace, err) } - return cluster.Name, nil + + return configmap.Data["clusterName"], nil } diff --git a/internal/metadataproviders/kubeadm/metadata_test.go b/internal/metadataproviders/kubeadm/metadata_test.go index accfb5b144a1..c255def71100 100644 --- a/internal/metadataproviders/kubeadm/metadata_test.go +++ b/internal/metadataproviders/kubeadm/metadata_test.go @@ -1 +1,93 @@ package kubeadm + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" +) + +func TestNewProvider(t *testing.T) { + // set k8s cluster env variables to make the API client happy + t.Setenv("KUBERNETES_SERVICE_HOST", "127.0.0.1") + t.Setenv("KUBERNETES_SERVICE_PORT", "6443") + + _, err := NewProvider("", "", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) + assert.EqualError(t, err, "configMapName and configMapNamespace can't be empty") + + _, err = NewProvider("", "ns", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) + assert.EqualError(t, err, "configMapName and configMapNamespace can't be empty") + + _, err = NewProvider("name", "", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) + assert.EqualError(t, err, "configMapName and configMapNamespace can't be empty") + + _, err = NewProvider("name", "ns", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) + assert.NoError(t, err) +} + +func TestClusterName(t *testing.T) { + client := fake.NewSimpleClientset() + err := setupConfigMap(client) + assert.NoError(t, err) + + tests := []struct { + testName string + CMname string + CMnamespace string + clusterName string + errMsg string + }{ + { + testName: "valid", + CMname: "cm", + CMnamespace: "ns", + clusterName: "myClusterName", + errMsg: "", + }, + { + testName: "configmap not found", + CMname: "cm2", + CMnamespace: "ns", + errMsg: "failed to fetch ConfigMap with name cm2 and namespace ns from K8s API: configmaps \"cm2\" not found", + }, + } + + for _, tt := range tests { + t.Run(tt.testName, func(t *testing.T) { + kubeadmP := &kubeadmProvider{ + kubeadmClient: client, + configMapName: tt.CMname, + configMapNamespace: tt.CMnamespace, + } + clusterName, err := kubeadmP.ClusterName(context.Background()) + if tt.errMsg != "" { + assert.EqualError(t, err, tt.errMsg) + } else { + assert.NoError(t, err) + assert.Equal(t, clusterName, tt.clusterName) + } + }) + } +} + +func setupConfigMap(client *fake.Clientset) error { + cm := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cm", + Namespace: "ns", + }, + Data: map[string]string{ + "clusterName": "myClusterName", + }, + } + _, err := client.CoreV1().ConfigMaps("ns").Create(context.Background(), cm, metav1.CreateOptions{}) + if err != nil { + return err + } + return nil +} From 07fe87917e2df652727a51001b3fa82b415c2c8d Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 14:33:32 +0200 Subject: [PATCH 08/28] add unit tests Signed-off-by: odubajDT --- .../internal/kubeadm/config_test.go | 14 +++++ .../metadata/generated_config_test.go | 56 +++++++++++++++++++ .../metadata/generated_resource_test.go | 39 +++++++++++++ 3 files changed, 109 insertions(+) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go index accfb5b144a1..d0fb1a4bdc71 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go @@ -1 +1,15 @@ package kubeadm + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSetCustomEnvVar(t *testing.T) { + cfg := CreateDefaultConfig() + err := cfg.UpdateDefaults() + assert.NoError(t, err) + assert.Equal(t, defaultConfigMapName, cfg.configMapName) + assert.Equal(t, defaultConfigMapNamespace, cfg.configMapNamespace) +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go index 82c48461b5cf..dfe3858a83f3 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go @@ -1 +1,57 @@ +// Code generated by mdatagen. DO NOT EDIT. + package metadata + +import ( + "path/filepath" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/confmap/confmaptest" +) + +func TestResourceAttributesConfig(t *testing.T) { + tests := []struct { + name string + want ResourceAttributesConfig + }{ + { + name: "default", + want: DefaultResourceAttributesConfig(), + }, + { + name: "all_set", + want: ResourceAttributesConfig{ + K8sClusterName: ResourceAttributeConfig{Enabled: true}, + }, + }, + { + name: "none_set", + want: ResourceAttributesConfig{ + K8sClusterName: ResourceAttributeConfig{Enabled: false}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := loadResourceAttributesConfig(t, tt.name) + if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" { + t.Errorf("Config mismatch (-expected +actual):\n%s", diff) + } + }) + } +} + +func loadResourceAttributesConfig(t *testing.T, name string) ResourceAttributesConfig { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) + sub, err := cm.Sub(name) + require.NoError(t, err) + sub, err = sub.Sub("resource_attributes") + require.NoError(t, err) + cfg := DefaultResourceAttributesConfig() + require.NoError(t, sub.Unmarshal(&cfg)) + return cfg +} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go index 82c48461b5cf..c43337278947 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_resource_test.go @@ -1 +1,40 @@ +// Code generated by mdatagen. DO NOT EDIT. + package metadata + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestResourceBuilder(t *testing.T) { + for _, tt := range []string{"default", "all_set", "none_set"} { + t.Run(tt, func(t *testing.T) { + cfg := loadResourceAttributesConfig(t, tt) + rb := NewResourceBuilder(cfg) + rb.SetK8sClusterName("k8s.cluster.name-val") + + res := rb.Emit() + assert.Equal(t, 0, rb.Emit().Attributes().Len()) // Second call should return empty Resource + + switch tt { + case "default": + assert.Equal(t, 1, res.Attributes().Len()) + case "all_set": + assert.Equal(t, 1, res.Attributes().Len()) + case "none_set": + assert.Equal(t, 0, res.Attributes().Len()) + return + default: + assert.Failf(t, "unexpected test case: %s", tt) + } + + val, ok := res.Attributes().Get("k8s.cluster.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.cluster.name-val", val.Str()) + } + }) + } +} From 6a666811606aa8f10c070e198b80fa016a73fe11 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 27 Sep 2024 14:40:19 +0200 Subject: [PATCH 09/28] more unit tests Signed-off-by: odubajDT --- .../internal/kubeadm/kubeadm_test.go | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go index accfb5b144a1..a7125552bc2a 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm_test.go @@ -1 +1,75 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + package kubeadm + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/processor/processortest" + conventions "go.opentelemetry.io/collector/semconv/v1.6.1" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/kubeadm" +) + +var _ kubeadm.Provider = (*mockMetadata)(nil) + +type mockMetadata struct { + mock.Mock +} + +func (m *mockMetadata) ClusterName(_ context.Context) (string, error) { + args := m.MethodCalled("ClusterName") + return args.String(0), args.Error(1) +} + +func TestDetect(t *testing.T) { + md := &mockMetadata{} + md.On("ClusterName").Return("cluster-1", nil) + cfg := CreateDefaultConfig() + // set k8s cluster env variables and auth type to create a dummy API client + cfg.APIConfig.AuthType = k8sconfig.AuthTypeNone + t.Setenv("KUBERNETES_SERVICE_HOST", "127.0.0.1") + t.Setenv("KUBERNETES_SERVICE_PORT", "6443") + + k8sDetector, err := NewDetector(processortest.NewNopSettings(), cfg) + require.NoError(t, err) + k8sDetector.(*detector).provider = md + res, schemaURL, err := k8sDetector.Detect(context.Background()) + require.NoError(t, err) + assert.Equal(t, conventions.SchemaURL, schemaURL) + md.AssertExpectations(t) + + expected := map[string]any{ + conventions.AttributeK8SClusterName: "cluster-1", + } + + assert.Equal(t, expected, res.Attributes().AsRaw()) +} + +func TestDetectDisabledResourceAttributes(t *testing.T) { + md := &mockMetadata{} + cfg := CreateDefaultConfig() + cfg.ResourceAttributes.K8sClusterName.Enabled = false + // set k8s cluster env variables and auth type to create a dummy API client + cfg.APIConfig.AuthType = k8sconfig.AuthTypeNone + t.Setenv("KUBERNETES_SERVICE_HOST", "127.0.0.1") + t.Setenv("KUBERNETES_SERVICE_PORT", "6443") + + k8sDetector, err := NewDetector(processortest.NewNopSettings(), cfg) + require.NoError(t, err) + k8sDetector.(*detector).provider = md + res, schemaURL, err := k8sDetector.Detect(context.Background()) + require.NoError(t, err) + assert.Equal(t, conventions.SchemaURL, schemaURL) + md.AssertExpectations(t) + + expected := map[string]any{} + + assert.Equal(t, expected, res.Attributes().AsRaw()) +} From 78c1575a3a4100d2ae154f06e3deafa06437c755 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 30 Sep 2024 08:05:15 +0200 Subject: [PATCH 10/28] rename function Signed-off-by: odubajDT --- .../resourcedetectionprocessor/internal/kubeadm/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go index d0fb1a4bdc71..7c31b81f298c 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSetCustomEnvVar(t *testing.T) { +func TestUpdateDefaults(t *testing.T) { cfg := CreateDefaultConfig() err := cfg.UpdateDefaults() assert.NoError(t, err) From 30edf8b62b6915b08d2c1490c4c6455dcaf06524 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 30 Sep 2024 08:49:29 +0200 Subject: [PATCH 11/28] add licence Signed-off-by: odubajDT --- .../resourcedetectionprocessor/internal/kubeadm/config.go | 3 +++ .../resourcedetectionprocessor/internal/kubeadm/config_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config.go b/processor/resourcedetectionprocessor/internal/kubeadm/config.go index 45e3a24916e0..4e5b8e2ae7ca 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config.go @@ -1,3 +1,6 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + package kubeadm import ( diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go index 7c31b81f298c..c034ff524d44 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go @@ -1,3 +1,6 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + package kubeadm import ( From ee229c761748e62cbecce0135dd1facdebf3ff81 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 30 Sep 2024 09:08:09 +0200 Subject: [PATCH 12/28] add licence Signed-off-by: odubajDT --- internal/metadataproviders/kubeadm/metadata_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/metadataproviders/kubeadm/metadata_test.go b/internal/metadataproviders/kubeadm/metadata_test.go index c255def71100..42d7f41ec40c 100644 --- a/internal/metadataproviders/kubeadm/metadata_test.go +++ b/internal/metadataproviders/kubeadm/metadata_test.go @@ -1,3 +1,6 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + package kubeadm import ( From 1b63790bec8f8ae347b24194fd6bf3f40a69f443 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 30 Sep 2024 09:19:48 +0200 Subject: [PATCH 13/28] fix lint Signed-off-by: odubajDT --- processor/resourcedetectionprocessor/internal/kubeadm/config.go | 2 +- .../resourcedetectionprocessor/internal/kubeadm/kubeadm.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config.go b/processor/resourcedetectionprocessor/internal/kubeadm/config.go index 4e5b8e2ae7ca..5b3d10cd4692 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package kubeadm +package kubeadm // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm" import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go index 4321c15e9ca4..086a5e6997e4 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package kubeadm // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/k8snode" +package kubeadm // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm" import ( "context" From 9ad0fe61185e30dda858e3816f05e97dc13e4fd7 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 30 Sep 2024 09:46:27 +0200 Subject: [PATCH 14/28] add new detector to processor factory Signed-off-by: odubajDT --- .github/CODEOWNERS | 1 + processor/resourcedetectionprocessor/config.go | 7 +++++++ processor/resourcedetectionprocessor/doc.go | 1 + processor/resourcedetectionprocessor/factory.go | 2 ++ 4 files changed, 11 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f0aeb83d3281..31871169e303 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -199,6 +199,7 @@ processor/resourcedetectionprocessor/internal/docker/ @open-teleme processor/resourcedetectionprocessor/internal/gcp/ @open-telemetry/collector-contrib-approvers processor/resourcedetectionprocessor/internal/heroku/ @open-telemetry/collector-contrib-approvers @atoulme processor/resourcedetectionprocessor/internal/k8snode/ @open-telemetry/collector-contrib-approvers +processor/resourcedetectionprocessor/internal/kubeadm/ @open-telemetry/collector-contrib-approvers processor/resourcedetectionprocessor/internal/openshift/ @open-telemetry/collector-contrib-approvers @frzifus processor/resourcedetectionprocessor/internal/system/ @open-telemetry/collector-contrib-approvers processor/resourceprocessor/ @open-telemetry/collector-contrib-approvers @dmitryax diff --git a/processor/resourcedetectionprocessor/config.go b/processor/resourcedetectionprocessor/config.go index 8dd1c1f10c8b..1f2e8a73bbdf 100644 --- a/processor/resourcedetectionprocessor/config.go +++ b/processor/resourcedetectionprocessor/config.go @@ -19,6 +19,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/gcp" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/heroku" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/k8snode" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/openshift" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/system" ) @@ -86,6 +87,9 @@ type DetectorConfig struct { // K8SNode contains user-specified configurations for the K8SNode detector K8SNodeConfig k8snode.Config `mapstructure:"k8snode"` + + // Kubeadm contains user-specified configurations for the Kubeadm detector + KubeadmConfig kubeadm.Config `mapstructure:"kubeadm"` } func detectorCreateDefaultConfig() DetectorConfig { @@ -104,6 +108,7 @@ func detectorCreateDefaultConfig() DetectorConfig { SystemConfig: system.CreateDefaultConfig(), OpenShiftConfig: openshift.CreateDefaultConfig(), K8SNodeConfig: k8snode.CreateDefaultConfig(), + KubeadmConfig: kubeadm.CreateDefaultConfig(), } } @@ -137,6 +142,8 @@ func (d *DetectorConfig) GetConfigFromType(detectorType internal.DetectorType) i return d.OpenShiftConfig case k8snode.TypeStr: return d.K8SNodeConfig + case kubeadm.TypeStr: + return d.KubeadmConfig default: return nil } diff --git a/processor/resourcedetectionprocessor/doc.go b/processor/resourcedetectionprocessor/doc.go index 67a30eb31cf3..91c606b11568 100644 --- a/processor/resourcedetectionprocessor/doc.go +++ b/processor/resourcedetectionprocessor/doc.go @@ -16,6 +16,7 @@ //go:generate mdatagen internal/openshift/metadata.yaml //go:generate mdatagen internal/system/metadata.yaml //go:generate mdatagen internal/k8snode/metadata.yaml +//go:generate mdatagen internal/kubeadm/metadata.yaml // package resourcedetectionprocessor implements a processor // which can be used to detect resource information from the host, diff --git a/processor/resourcedetectionprocessor/factory.go b/processor/resourcedetectionprocessor/factory.go index f1ae4b11ac35..bf431605c803 100644 --- a/processor/resourcedetectionprocessor/factory.go +++ b/processor/resourcedetectionprocessor/factory.go @@ -29,6 +29,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/gcp" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/heroku" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/k8snode" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/kubeadm" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/openshift" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/system" @@ -63,6 +64,7 @@ func NewFactory() processor.Factory { system.TypeStr: system.NewDetector, openshift.TypeStr: openshift.NewDetector, k8snode.TypeStr: k8snode.NewDetector, + kubeadm.TypeStr: kubeadm.NewDetector, }) f := &factory{ From f250022288e4d6d7e73ae6b4aa467d3d5616e32d Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 1 Oct 2024 09:19:13 +0200 Subject: [PATCH 15/28] PR review Signed-off-by: odubajDT --- internal/metadataproviders/kubeadm/metadata.go | 2 +- .../resourcedetectionprocessor/internal/kubeadm/kubeadm.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/metadataproviders/kubeadm/metadata.go b/internal/metadataproviders/kubeadm/metadata.go index 3dd4253f33d3..96096484307d 100644 --- a/internal/metadataproviders/kubeadm/metadata.go +++ b/internal/metadataproviders/kubeadm/metadata.go @@ -14,7 +14,7 @@ import ( ) type Provider interface { - // ClusterName returns the current K8S Node Name + // ClusterName returns the current K8S cluster name ClusterName(ctx context.Context) (string, error) } diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go index 086a5e6997e4..854671ed4950 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go @@ -36,13 +36,13 @@ func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal return nil, err } - k8snodeProvider, err := kubeadm.NewProvider(cfg.configMapName, cfg.configMapNamespace, cfg.APIConfig) + kubeadmProvider, err := kubeadm.NewProvider(cfg.configMapName, cfg.configMapNamespace, cfg.APIConfig) if err != nil { return nil, fmt.Errorf("failed creating kubeadm provider: %w", err) } return &detector{ - provider: k8snodeProvider, + provider: kubeadmProvider, logger: set.Logger, ra: &cfg.ResourceAttributes, rb: metadata.NewResourceBuilder(cfg.ResourceAttributes), From d079091c045d1416ea93d0d3b388c17167132626 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Wed, 2 Oct 2024 09:45:13 +0200 Subject: [PATCH 16/28] remove updateDefaults() function Signed-off-by: odubajDT --- .../internal/kubeadm/config.go | 10 ++-------- .../internal/kubeadm/config_test.go | 2 -- .../internal/kubeadm/kubeadm.go | 3 --- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config.go b/processor/resourcedetectionprocessor/internal/kubeadm/config.go index 5b3d10cd4692..66d7155adf60 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config.go @@ -18,17 +18,11 @@ type Config struct { const defaultConfigMapName = "kubeadm-config" const defaultConfigMapNamespace = "kube-system" -// UpdateDefaults validates and update the default config with user's provided settings -func (c *Config) UpdateDefaults() error { - c.configMapName = defaultConfigMapName - c.configMapNamespace = defaultConfigMapNamespace - - return nil -} - func CreateDefaultConfig() Config { return Config{ APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount}, ResourceAttributes: metadata.DefaultResourceAttributesConfig(), + configMapName: defaultConfigMapName, + configMapNamespace: defaultConfigMapNamespace, } } diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go index c034ff524d44..8f07cc90febb 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go @@ -11,8 +11,6 @@ import ( func TestUpdateDefaults(t *testing.T) { cfg := CreateDefaultConfig() - err := cfg.UpdateDefaults() - assert.NoError(t, err) assert.Equal(t, defaultConfigMapName, cfg.configMapName) assert.Equal(t, defaultConfigMapNamespace, cfg.configMapNamespace) } diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go index 854671ed4950..41bf2d995763 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go @@ -32,9 +32,6 @@ type detector struct { func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal.Detector, error) { cfg := dcfg.(Config) - if err := cfg.UpdateDefaults(); err != nil { - return nil, err - } kubeadmProvider, err := kubeadm.NewProvider(cfg.configMapName, cfg.configMapNamespace, cfg.APIConfig) if err != nil { From 4731b2915007b24b7e9d0bbe9265d3b48518a553 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 3 Oct 2024 07:29:04 +0200 Subject: [PATCH 17/28] fix readme Signed-off-by: odubajDT --- processor/resourcedetectionprocessor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index c138d902792e..9f5d90af8c12 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -447,7 +447,7 @@ processors: ### Kubeadm Metadata -Queries the K8S api server to retrieve the following node resource attributes: +Queries the K8S API server to retrieve the following resource attributes: * k8s.cluster.name From 4cbbeb31c2a67b67b7ccfa747e51ca19d1d4395c Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 3 Oct 2024 07:33:24 +0200 Subject: [PATCH 18/28] fir err msg Signed-off-by: odubajDT --- internal/metadataproviders/kubeadm/metadata.go | 3 --- internal/metadataproviders/kubeadm/metadata_test.go | 11 +---------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/internal/metadataproviders/kubeadm/metadata.go b/internal/metadataproviders/kubeadm/metadata.go index 96096484307d..84c419ddcb5e 100644 --- a/internal/metadataproviders/kubeadm/metadata.go +++ b/internal/metadataproviders/kubeadm/metadata.go @@ -25,9 +25,6 @@ type kubeadmProvider struct { } func NewProvider(configMapName string, configMapNamespace string, apiConf k8sconfig.APIConfig) (Provider, error) { - if configMapName == "" || configMapNamespace == "" { - return nil, fmt.Errorf("configMapName and configMapNamespace can't be empty") - } k8sAPIClient, err := k8sconfig.MakeClient(apiConf) if err != nil { return nil, fmt.Errorf("failed to create K8s API client: %w", err) diff --git a/internal/metadataproviders/kubeadm/metadata_test.go b/internal/metadataproviders/kubeadm/metadata_test.go index 42d7f41ec40c..7f383b203a7e 100644 --- a/internal/metadataproviders/kubeadm/metadata_test.go +++ b/internal/metadataproviders/kubeadm/metadata_test.go @@ -20,16 +20,7 @@ func TestNewProvider(t *testing.T) { t.Setenv("KUBERNETES_SERVICE_HOST", "127.0.0.1") t.Setenv("KUBERNETES_SERVICE_PORT", "6443") - _, err := NewProvider("", "", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) - assert.EqualError(t, err, "configMapName and configMapNamespace can't be empty") - - _, err = NewProvider("", "ns", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) - assert.EqualError(t, err, "configMapName and configMapNamespace can't be empty") - - _, err = NewProvider("name", "", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) - assert.EqualError(t, err, "configMapName and configMapNamespace can't be empty") - - _, err = NewProvider("name", "ns", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) + _, err := NewProvider("name", "ns", k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}) assert.NoError(t, err) } From 023406d7f4e548c0321c864bd1466890c235ff5b Mon Sep 17 00:00:00 2001 From: odubajDT Date: Fri, 4 Oct 2024 07:50:14 +0200 Subject: [PATCH 19/28] move default values to kubeadm.go Signed-off-by: odubajDT --- .../internal/kubeadm/config.go | 7 ------- .../internal/kubeadm/config_test.go | 16 ---------------- .../internal/kubeadm/kubeadm.go | 6 ++++-- 3 files changed, 4 insertions(+), 25 deletions(-) delete mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/config_test.go diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config.go b/processor/resourcedetectionprocessor/internal/kubeadm/config.go index 66d7155adf60..c9932dc332d5 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/config.go @@ -11,18 +11,11 @@ import ( type Config struct { k8sconfig.APIConfig `mapstructure:",squash"` ResourceAttributes metadata.ResourceAttributesConfig `mapstructure:"resource_attributes"` - configMapName string - configMapNamespace string } -const defaultConfigMapName = "kubeadm-config" -const defaultConfigMapNamespace = "kube-system" - func CreateDefaultConfig() Config { return Config{ APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount}, ResourceAttributes: metadata.DefaultResourceAttributesConfig(), - configMapName: defaultConfigMapName, - configMapNamespace: defaultConfigMapNamespace, } } diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go deleted file mode 100644 index 8f07cc90febb..000000000000 --- a/processor/resourcedetectionprocessor/internal/kubeadm/config_test.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package kubeadm - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestUpdateDefaults(t *testing.T) { - cfg := CreateDefaultConfig() - assert.Equal(t, defaultConfigMapName, cfg.configMapName) - assert.Equal(t, defaultConfigMapNamespace, cfg.configMapNamespace) -} diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go index 41bf2d995763..ca39c6dde262 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/kubeadm.go @@ -18,7 +18,9 @@ import ( ) const ( - TypeStr = "kubeadm" + TypeStr = "kubeadm" + defaultConfigMapName = "kubeadm-config" + defaultConfigMapNamespace = "kube-system" ) var _ internal.Detector = (*detector)(nil) @@ -33,7 +35,7 @@ type detector struct { func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal.Detector, error) { cfg := dcfg.(Config) - kubeadmProvider, err := kubeadm.NewProvider(cfg.configMapName, cfg.configMapNamespace, cfg.APIConfig) + kubeadmProvider, err := kubeadm.NewProvider(defaultConfigMapName, defaultConfigMapNamespace, cfg.APIConfig) if err != nil { return nil, fmt.Errorf("failed creating kubeadm provider: %w", err) } From b8cd07c082343df99609e9c0026492383a91d8e5 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Wed, 9 Oct 2024 08:29:30 +0200 Subject: [PATCH 20/28] make generate Signed-off-by: odubajDT --- .../internal/kubeadm/documentation.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 processor/resourcedetectionprocessor/internal/kubeadm/documentation.md diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/documentation.md b/processor/resourcedetectionprocessor/internal/kubeadm/documentation.md new file mode 100644 index 000000000000..5e2c0561a2ad --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/kubeadm/documentation.md @@ -0,0 +1,11 @@ +[comment]: <> (Code generated by mdatagen. DO NOT EDIT.) + +# resourcedetectionprocessor/kubeadm + +**Parent Component:** resourcedetection + +## Resource Attributes + +| Name | Description | Values | Enabled | +| ---- | ----------- | ------ | ------- | +| k8s.cluster.name | The Kubernetes cluster name | Any Str | true | From 9b0389f67e035e5deee22ab890e010dd84600fbb Mon Sep 17 00:00:00 2001 From: odubajDT Date: Wed, 6 Nov 2024 07:10:23 +0100 Subject: [PATCH 21/28] fix after rebase Signed-off-by: odubajDT --- .../resourcedetectionprocessor/README.md | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index 9f5d90af8c12..eda0f235ef9c 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -424,27 +424,6 @@ processors: override: false ``` -### Heroku - -** You must first enable the [Heroku metadata feature](https://devcenter.heroku.com/articles/dyno-metadata) on the application ** - -Queries [Heroku metadata](https://devcenter.heroku.com/articles/dyno-metadata) to retrieve the following resource attributes: - -* heroku.release.version (identifier for the current release) -* heroku.release.creation_timestamp (time and date the release was created) -* heroku.release.commit (commit hash for the current release) -* heroku.app.name (application name) -* heroku.app.id (unique identifier for the application) -* heroku.dyno.id (dyno identifier. Used as host name) - -```yaml -processors: - resourcedetection/heroku: - detectors: [env, heroku] - timeout: 2s - override: false -``` - ### Kubeadm Metadata Queries the K8S API server to retrieve the following resource attributes: From e6f31819997e758db83061d19c0cc7e420b8685c Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 7 Nov 2024 13:36:08 +0100 Subject: [PATCH 22/28] fix after rebase Signed-off-by: odubajDT --- .../resourcedetectionprocessor/generated_package_test.go | 3 +-- .../internal/kubeadm/metadata.yaml | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/processor/resourcedetectionprocessor/generated_package_test.go b/processor/resourcedetectionprocessor/generated_package_test.go index a6e8915ade36..eeb978adf266 100644 --- a/processor/resourcedetectionprocessor/generated_package_test.go +++ b/processor/resourcedetectionprocessor/generated_package_test.go @@ -3,9 +3,8 @@ package resourcedetectionprocessor import ( - "testing" - "go.uber.org/goleak" + "testing" ) func TestMain(m *testing.M) { diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml b/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml index b3d129f6af84..ed2518a06686 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml +++ b/processor/resourcedetectionprocessor/internal/kubeadm/metadata.yaml @@ -2,11 +2,6 @@ type: resourcedetectionprocessor/kubeadm parent: resourcedetection -status: - class: pkg - codeowners: - active: - resource_attributes: k8s.cluster.name: description: The Kubernetes cluster name From 94177fdc8c4b8ab6f25ad96839248a6694270eef Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 7 Nov 2024 14:07:15 +0100 Subject: [PATCH 23/28] make generate Signed-off-by: odubajDT --- processor/resourcedetectionprocessor/generated_package_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/processor/resourcedetectionprocessor/generated_package_test.go b/processor/resourcedetectionprocessor/generated_package_test.go index eeb978adf266..a6e8915ade36 100644 --- a/processor/resourcedetectionprocessor/generated_package_test.go +++ b/processor/resourcedetectionprocessor/generated_package_test.go @@ -3,8 +3,9 @@ package resourcedetectionprocessor import ( - "go.uber.org/goleak" "testing" + + "go.uber.org/goleak" ) func TestMain(m *testing.M) { From f72e1bf13f5ab6dec0f015fad3b8785a84e225ae Mon Sep 17 00:00:00 2001 From: odubajDT Date: Wed, 20 Nov 2024 07:55:42 +0100 Subject: [PATCH 24/28] make generate Signed-off-by: odubajDT --- .../kubeadm/internal/metadata/generated_config_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go index dfe3858a83f3..c2ed830cc2ad 100644 --- a/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go +++ b/processor/resourcedetectionprocessor/internal/kubeadm/internal/metadata/generated_config_test.go @@ -37,9 +37,8 @@ func TestResourceAttributesConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := loadResourceAttributesConfig(t, tt.name) - if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" { - t.Errorf("Config mismatch (-expected +actual):\n%s", diff) - } + diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})) + require.Emptyf(t, diff, "Config mismatch (-expected +actual):\n%s", diff) }) } } From 5a5fb6ab2454d1bc3f3bce37eb240136068c84cd Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 26 Nov 2024 13:08:00 +0100 Subject: [PATCH 25/28] pr review Signed-off-by: odubajDT --- internal/metadataproviders/kubeadm/metadata.go | 10 ++++++++++ processor/resourcedetectionprocessor/README.md | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/metadataproviders/kubeadm/metadata.go b/internal/metadataproviders/kubeadm/metadata.go index 84c419ddcb5e..98c7b5487a0a 100644 --- a/internal/metadataproviders/kubeadm/metadata.go +++ b/internal/metadataproviders/kubeadm/metadata.go @@ -18,10 +18,15 @@ type Provider interface { ClusterName(ctx context.Context) (string, error) } +type LocalCache struct { + ClusterName string +} + type kubeadmProvider struct { kubeadmClient kubernetes.Interface configMapName string configMapNamespace string + cache LocalCache } func NewProvider(configMapName string, configMapNamespace string, apiConf k8sconfig.APIConfig) (Provider, error) { @@ -37,10 +42,15 @@ func NewProvider(configMapName string, configMapNamespace string, apiConf k8scon } func (k *kubeadmProvider) ClusterName(ctx context.Context) (string, error) { + if k.cache.ClusterName != "" { + return k.cache.ClusterName, nil + } configmap, err := k.kubeadmClient.CoreV1().ConfigMaps(k.configMapNamespace).Get(ctx, k.configMapName, metav1.GetOptions{}) if err != nil { return "", fmt.Errorf("failed to fetch ConfigMap with name %s and namespace %s from K8s API: %w", k.configMapName, k.configMapNamespace, err) } + k.cache.ClusterName = configmap.Data["clusterName"] + return configmap.Data["clusterName"], nil } diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index 62d3932c774e..ee612b087898 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -434,13 +434,14 @@ Queries the K8S API server to retrieve the following resource attributes: The following permissions are required: ```yaml -kind: ClusterRole +kind: Role metadata: name: otel-collector rules: - apiGroups: [""] resources: ["configmaps"] - verbs: ["get", "list"] + resourceNames: ["kubeadm-config"] + verbs: ["get"] ``` | Name | Type | Required | Default | Docs | From cb48fdc668a59cdb3e974a5cc0f697bacb4cc672 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 26 Nov 2024 15:28:47 +0100 Subject: [PATCH 26/28] add rolebinding in readme Signed-off-by: odubajDT --- processor/resourcedetectionprocessor/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index ee612b087898..37d176fc0d73 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -437,11 +437,26 @@ The following permissions are required: kind: Role metadata: name: otel-collector + namespace: kube-system rules: - apiGroups: [""] resources: ["configmaps"] resourceNames: ["kubeadm-config"] verbs: ["get"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: otel-collector-rolebinding + namespace: kube-system +subjects: +- kind: ServiceAccount + name: default + namespace: default +roleRef: + kind: Role + name: otel-collector + apiGroup: rbac.authorization.k8s.io ``` | Name | Type | Required | Default | Docs | From 09b1548af4f356ac803e4e94f5ba18f9e7179778 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 26 Nov 2024 15:51:54 +0100 Subject: [PATCH 27/28] polishing Signed-off-by: odubajDT --- internal/metadataproviders/kubeadm/metadata.go | 2 +- processor/resourcedetectionprocessor/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/metadataproviders/kubeadm/metadata.go b/internal/metadataproviders/kubeadm/metadata.go index 98c7b5487a0a..2b594e54614c 100644 --- a/internal/metadataproviders/kubeadm/metadata.go +++ b/internal/metadataproviders/kubeadm/metadata.go @@ -52,5 +52,5 @@ func (k *kubeadmProvider) ClusterName(ctx context.Context) (string, error) { k.cache.ClusterName = configmap.Data["clusterName"] - return configmap.Data["clusterName"], nil + return k.cache.ClusterName, nil } diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index 37d176fc0d73..52551cd17be7 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -430,7 +430,7 @@ processors: Queries the K8S API server to retrieve the following resource attributes: - * k8s.cluster.name +The list of the populated resource attributes can be found at [kubeadm Detector Resource Attributes](./internal/kubeadm/documentation.md). The following permissions are required: ```yaml From 0057fc5b45885da3b14838da9592ee03ee45e59e Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:53:07 +0100 Subject: [PATCH 28/28] Update processor/resourcedetectionprocessor/README.md --- processor/resourcedetectionprocessor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index 52551cd17be7..ba5820ecf854 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -428,7 +428,7 @@ processors: ### Kubeadm Metadata -Queries the K8S API server to retrieve the following resource attributes: +Queries the K8S API server to retrieve kubeadm resource attributes: The list of the populated resource attributes can be found at [kubeadm Detector Resource Attributes](./internal/kubeadm/documentation.md).