From 5f53e33dd7ad4f0ccc797d5eb9145f4fc6749fdf Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 30 May 2024 09:44:47 -0700 Subject: [PATCH] [processor/k8sattributes] Move feature gate k8sattr.rfc3339 to stable (#33304) **Description:** Move feature gate k8sattr.rfc3339 to stable --- .chloggen/k8sattr.rfc3339.stable.yaml | 27 ++++ processor/k8sattributesprocessor/README.md | 7 +- .../internal/kube/client.go | 4 +- .../internal/kube/client_test.go | 137 +----------------- .../namespacedrbac/collector/deployment.yaml | 1 - 5 files changed, 36 insertions(+), 140 deletions(-) create mode 100644 .chloggen/k8sattr.rfc3339.stable.yaml diff --git a/.chloggen/k8sattr.rfc3339.stable.yaml b/.chloggen/k8sattr.rfc3339.stable.yaml new file mode 100644 index 000000000000..329a0035dc25 --- /dev/null +++ b/.chloggen/k8sattr.rfc3339.stable.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: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: k8sattributesprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Move `k8sattr.rfc3339` feature gate to stable. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [33304] + +# (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: [] diff --git a/processor/k8sattributesprocessor/README.md b/processor/k8sattributesprocessor/README.md index 172be772ec86..a8dfeb684d5e 100644 --- a/processor/k8sattributesprocessor/README.md +++ b/processor/k8sattributesprocessor/README.md @@ -330,8 +330,5 @@ as tags. ## Timestamp Format -By default, the `k8s.pod.start_time` uses [Time.String()](https://pkg.go.dev/time#Time.String) to format the -timestamp value. - -The `k8sattr.rfc3339` feature gate can be enabled to format the `k8s.pod.start_time` timestamp value with an RFC3339 -compliant timestamp. See [Time.MarshalText()](https://pkg.go.dev/time#Time.MarshalText) for more information. +By default, the `k8s.pod.start_time` uses [Time.MarshalText()](https://pkg.go.dev/time#Time.MarshalText) to format the +timestamp value as an RFC3339 compliant timestamp. diff --git a/processor/k8sattributesprocessor/internal/kube/client.go b/processor/k8sattributesprocessor/internal/kube/client.go index 466755d25f70..7488519dd925 100644 --- a/processor/k8sattributesprocessor/internal/kube/client.go +++ b/processor/k8sattributesprocessor/internal/kube/client.go @@ -26,12 +26,12 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/observability" ) -// Upgrade to StageStable in v0.92.0 var enableRFC3339Timestamp = featuregate.GlobalRegistry().MustRegister( "k8sattr.rfc3339", - featuregate.StageBeta, + featuregate.StageStable, featuregate.WithRegisterDescription("When enabled, uses RFC3339 format for k8s.pod.start_time value"), featuregate.WithRegisterFromVersion("v0.82.0"), + featuregate.WithRegisterToVersion("v0.102.0"), ) // WatchClient is the main interface provided by this package to a kubernetes cluster. diff --git a/processor/k8sattributesprocessor/internal/kube/client_test.go b/processor/k8sattributesprocessor/internal/kube/client_test.go index 4640dbbd8273..e92d47fa3f38 100644 --- a/processor/k8sattributesprocessor/internal/kube/client_test.go +++ b/processor/k8sattributesprocessor/internal/kube/client_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/featuregate" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" @@ -643,136 +642,6 @@ func TestHandlerWrongType(t *testing.T) { } } -func TestRFC3339FeatureGate(t *testing.T) { - err := featuregate.GlobalRegistry().Set(enableRFC3339Timestamp.ID(), true) - require.NoError(t, err) - - c, _ := newTestClientWithRulesAndFilters(t, Filters{}) - // Disable saving ip into k8s.pod.ip - c.Associations[0].Sources[0].Name = "" - - pod := &api_v1.Pod{ - ObjectMeta: meta_v1.ObjectMeta{ - Name: "auth-service-abc12-xyz3", - UID: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", - Namespace: "ns1", - CreationTimestamp: meta_v1.Now(), - Labels: map[string]string{ - "label1": "lv1", - "label2": "k1=v1 k5=v5 extra!", - }, - Annotations: map[string]string{ - "annotation1": "av1", - }, - OwnerReferences: []meta_v1.OwnerReference{ - { - APIVersion: "apps/v1", - Kind: "ReplicaSet", - Name: "auth-service-66f5996c7c", - UID: "207ea729-c779-401d-8347-008ecbc137e3", - }, - { - APIVersion: "apps/v1", - Kind: "DaemonSet", - Name: "auth-daemonset", - UID: "c94d3814-2253-427a-ab13-2cf609e4dafa", - }, - { - APIVersion: "batch/v1", - Kind: "Job", - Name: "auth-cronjob-27667920", - UID: "59f27ac1-5c71-42e5-abe9-2c499d603706", - }, - { - APIVersion: "apps/v1", - Kind: "StatefulSet", - Name: "pi-statefulset", - UID: "03755eb1-6175-47d5-afd5-05cfc30244d7", - }, - }, - }, - Spec: api_v1.PodSpec{ - NodeName: "node1", - Hostname: "host1", - }, - Status: api_v1.PodStatus{ - PodIP: "1.1.1.1", - }, - } - - isController := true - replicaset := &apps_v1.ReplicaSet{ - ObjectMeta: meta_v1.ObjectMeta{ - Name: "auth-service-66f5996c7c", - Namespace: "ns1", - UID: "207ea729-c779-401d-8347-008ecbc137e3", - OwnerReferences: []meta_v1.OwnerReference{ - { - Name: "auth-service", - Kind: "Deployment", - UID: "ffff-gggg-hhhh-iiii-eeeeeeeeeeee", - Controller: &isController, - }, - }, - }, - } - - rfc3339ts, err := pod.GetCreationTimestamp().MarshalText() - require.NoError(t, err) - - testCases := []struct { - name string - rules ExtractionRules - attributes map[string]string - }{{ - name: "metadata", - rules: ExtractionRules{ - DeploymentName: true, - DeploymentUID: true, - Namespace: true, - PodName: true, - PodUID: true, - PodHostName: true, - Node: true, - StartTime: true, - }, - attributes: map[string]string{ - "k8s.deployment.name": "auth-service", - "k8s.deployment.uid": "ffff-gggg-hhhh-iiii-eeeeeeeeeeee", - "k8s.namespace.name": "ns1", - "k8s.node.name": "node1", - "k8s.pod.name": "auth-service-abc12-xyz3", - "k8s.pod.hostname": "host1", - "k8s.pod.uid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", - "k8s.pod.start_time": string(rfc3339ts), - }, - }, - } - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - c.Rules = tc.rules - - // manually call the data removal functions here - // normally the informer does this, but fully emulating the informer in this test is annoying - transformedPod := removeUnnecessaryPodData(pod, c.Rules) - transformedReplicaset := removeUnnecessaryReplicaSetData(replicaset) - c.handleReplicaSetAdd(transformedReplicaset) - c.handlePodAdd(transformedPod) - p, ok := c.GetPod(newPodIdentifier("connection", "", pod.Status.PodIP)) - require.True(t, ok) - - assert.Equal(t, len(tc.attributes), len(p.Attributes)) - for k, v := range tc.attributes { - got, ok := p.Attributes[k] - assert.True(t, ok) - assert.Equal(t, v, got) - } - }) - } - err = featuregate.GlobalRegistry().Set(enableRFC3339Timestamp.ID(), false) - require.NoError(t, err) -} - func TestExtractionRules(t *testing.T) { c, _ := newTestClientWithRulesAndFilters(t, Filters{}) @@ -955,7 +824,11 @@ func TestExtractionRules(t *testing.T) { "k8s.pod.name": "auth-service-abc12-xyz3", "k8s.pod.hostname": "host1", "k8s.pod.uid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", - "k8s.pod.start_time": pod.GetCreationTimestamp().String(), + "k8s.pod.start_time": func() string { + b, err := pod.GetCreationTimestamp().MarshalText() + require.NoError(t, err) + return string(b) + }(), }, }, { name: "labels", diff --git a/processor/k8sattributesprocessor/testdata/e2e/namespacedrbac/collector/deployment.yaml b/processor/k8sattributesprocessor/testdata/e2e/namespacedrbac/collector/deployment.yaml index c4c54829bf68..b7ae9cb34342 100644 --- a/processor/k8sattributesprocessor/testdata/e2e/namespacedrbac/collector/deployment.yaml +++ b/processor/k8sattributesprocessor/testdata/e2e/namespacedrbac/collector/deployment.yaml @@ -21,7 +21,6 @@ spec: command: - /otelcontribcol - --config=/conf/relay.yaml - - --feature-gates=k8sattr.rfc3339 image: "otelcontribcol:latest" imagePullPolicy: Never ports: