Skip to content

Commit

Permalink
[processor/k8sattributes] Move feature gate k8sattr.rfc3339 to stable (
Browse files Browse the repository at this point in the history
…open-telemetry#33304)

**Description:**
Move feature gate k8sattr.rfc3339 to stable
  • Loading branch information
atoulme authored May 30, 2024
1 parent fc08be9 commit 5f53e33
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 140 deletions.
27 changes: 27 additions & 0 deletions .chloggen/k8sattr.rfc3339.stable.yaml
Original file line number Diff line number Diff line change
@@ -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: []
7 changes: 2 additions & 5 deletions processor/k8sattributesprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions processor/k8sattributesprocessor/internal/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
137 changes: 5 additions & 132 deletions processor/k8sattributesprocessor/internal/kube/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ spec:
command:
- /otelcontribcol
- --config=/conf/relay.yaml
- --feature-gates=k8sattr.rfc3339
image: "otelcontribcol:latest"
imagePullPolicy: Never
ports:
Expand Down

0 comments on commit 5f53e33

Please sign in to comment.