Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/kubeletstats] remove direction feature gate #14961

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/rm-direction-kubeletstats.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: kubeletstatsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "remove direction feature gate"

# One or more tracking issues related to the change
issues: [14961]

# (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:
12 changes: 0 additions & 12 deletions receiver/kubeletstatsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,5 @@ with detailed sample configurations [here](./testdata/config.yaml).

Details about the metrics produced by this receiver can be found in [metadata.yaml](./metadata.yaml) with further documentation in [documentation.md](./documentation.md)

### Feature gate configurations

#### Transition from metrics with "direction" attribute

The proposal to change metrics from being reported with a `direction` attribute has been reverted in the specification. As a result, the
following feature gates will be removed in v0.62.0:

- **receiver.kubeletstatsreceiver.emitMetricsWithoutDirectionAttribute**
- **receiver.kubeletstatsreceiver.emitMetricsWithDirectionAttribute**

For additional information, see https://github.com/open-telemetry/opentelemetry-specification/issues/2726.

[beta]:https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]:https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
8 changes: 0 additions & 8 deletions receiver/kubeletstatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ These are the metrics available for this scraper.
| **k8s.node.memory.usage** | Node memory usage | By | Gauge(Int) | <ul> </ul> |
| **k8s.node.memory.working_set** | Node memory working_set | By | Gauge(Int) | <ul> </ul> |
| **k8s.node.network.errors** | Node network errors | 1 | Sum(Int) | <ul> <li>interface</li> <li>direction</li> </ul> |
| **k8s.node.network.errors.receive** | Node network receive errors | 1 | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.node.network.errors.transmit** | Node network transmission errors | 1 | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.node.network.io** | Node network IO | By | Sum(Int) | <ul> <li>interface</li> <li>direction</li> </ul> |
| **k8s.node.network.io.receive** | Node network IO received | By | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.node.network.io.transmit** | Node network IO transmitted | By | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.pod.cpu.time** | Pod CPU time | s | Sum(Double) | <ul> </ul> |
| **k8s.pod.cpu.utilization** | Pod CPU utilization | 1 | Gauge(Double) | <ul> </ul> |
| **k8s.pod.filesystem.available** | Pod filesystem available | By | Gauge(Int) | <ul> </ul> |
Expand All @@ -48,11 +44,7 @@ These are the metrics available for this scraper.
| **k8s.pod.memory.usage** | Pod memory usage | By | Gauge(Int) | <ul> </ul> |
| **k8s.pod.memory.working_set** | Pod memory working_set | By | Gauge(Int) | <ul> </ul> |
| **k8s.pod.network.errors** | Pod network errors | 1 | Sum(Int) | <ul> <li>interface</li> <li>direction</li> </ul> |
| **k8s.pod.network.errors.receive** | Pod network receive errors | 1 | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.pod.network.errors.transmit** | Pod network transmission errors | 1 | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.pod.network.io** | Pod network IO | By | Sum(Int) | <ul> <li>interface</li> <li>direction</li> </ul> |
| **k8s.pod.network.io.receive** | Pod network IO received | By | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.pod.network.io.transmit** | Pod network IO transmitted | By | Sum(Int) | <ul> <li>interface</li> </ul> |
| **k8s.volume.available** | The number of available bytes in the volume. | By | Gauge(Int) | <ul> </ul> |
| **k8s.volume.capacity** | The total capacity in bytes of the volume. | By | Gauge(Int) | <ul> </ul> |
| **k8s.volume.inodes** | The total inodes in the filesystem. | 1 | Gauge(Int) | <ul> </ul> |
Expand Down
28 changes: 8 additions & 20 deletions receiver/kubeletstatsreceiver/internal/kubelet/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ var ValidMetricGroups = map[MetricGroup]bool{
}

type metricDataAccumulator struct {
m []pmetric.Metrics
metadata Metadata
logger *zap.Logger
metricGroupsToCollect map[MetricGroup]bool
time time.Time
mbs *metadata.MetricsBuilders
emitMetricsWithDirectionAttribute bool
emitMetricsWithoutDirectionAttribute bool
m []pmetric.Metrics
metadata Metadata
logger *zap.Logger
metricGroupsToCollect map[MetricGroup]bool
time time.Time
mbs *metadata.MetricsBuilders
}

func (a *metricDataAccumulator) nodeStats(s stats.NodeStats) {
Expand All @@ -63,12 +61,7 @@ func (a *metricDataAccumulator) nodeStats(s stats.NodeStats) {
addCPUMetrics(a.mbs.NodeMetricsBuilder, metadata.NodeCPUMetrics, s.CPU, currentTime)
addMemoryMetrics(a.mbs.NodeMetricsBuilder, metadata.NodeMemoryMetrics, s.Memory, currentTime)
addFilesystemMetrics(a.mbs.NodeMetricsBuilder, metadata.NodeFilesystemMetrics, s.Fs, currentTime)
if a.emitMetricsWithDirectionAttribute {
addNetworkMetricsWithDirection(a.mbs.NodeMetricsBuilder, metadata.NodeNetworkMetricsWithDirection, s.Network, currentTime)
}
if a.emitMetricsWithoutDirectionAttribute {
addNetworkMetrics(a.mbs.NodeMetricsBuilder, metadata.NodeNetworkMetrics, s.Network, currentTime)
}
addNetworkMetricsWithDirection(a.mbs.NodeMetricsBuilder, metadata.NodeNetworkMetricsWithDirection, s.Network, currentTime)
// todo s.Runtime.ImageFs

a.m = append(a.m, a.mbs.NodeMetricsBuilder.Emit(
Expand All @@ -86,12 +79,7 @@ func (a *metricDataAccumulator) podStats(s stats.PodStats) {
addCPUMetrics(a.mbs.PodMetricsBuilder, metadata.PodCPUMetrics, s.CPU, currentTime)
addMemoryMetrics(a.mbs.PodMetricsBuilder, metadata.PodMemoryMetrics, s.Memory, currentTime)
addFilesystemMetrics(a.mbs.PodMetricsBuilder, metadata.PodFilesystemMetrics, s.EphemeralStorage, currentTime)
if a.emitMetricsWithDirectionAttribute {
addNetworkMetricsWithDirection(a.mbs.PodMetricsBuilder, metadata.PodNetworkMetricsWithDirection, s.Network, currentTime)
}
if a.emitMetricsWithoutDirectionAttribute {
addNetworkMetrics(a.mbs.PodMetricsBuilder, metadata.PodNetworkMetrics, s.Network, currentTime)
}
addNetworkMetricsWithDirection(a.mbs.PodMetricsBuilder, metadata.PodNetworkMetricsWithDirection, s.Network, currentTime)

a.m = append(a.m, a.mbs.PodMetricsBuilder.Emit(
metadata.WithStartTimeOverride(pcommon.NewTimestampFromTime(s.StartTime.Time)),
Expand Down
16 changes: 6 additions & 10 deletions receiver/kubeletstatsreceiver/internal/kubelet/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ func MetricsData(
logger *zap.Logger, summary *stats.Summary,
metadata Metadata,
metricGroupsToCollect map[MetricGroup]bool,
mbs *metadata.MetricsBuilders,
emitMetricsWithDirectionAttribute,
emitMetricsWithoutDirectionAttribute bool) []pmetric.Metrics {
mbs *metadata.MetricsBuilders) []pmetric.Metrics {
acc := &metricDataAccumulator{
metadata: metadata,
logger: logger,
metricGroupsToCollect: metricGroupsToCollect,
time: time.Now(),
mbs: mbs,
emitMetricsWithDirectionAttribute: emitMetricsWithDirectionAttribute,
emitMetricsWithoutDirectionAttribute: emitMetricsWithoutDirectionAttribute,
metadata: metadata,
logger: logger,
metricGroupsToCollect: metricGroupsToCollect,
time: time.Now(),
mbs: mbs,
}
acc.nodeStats(summary.Node)
for _, podStats := range summary.Pods {
Expand Down
43 changes: 10 additions & 33 deletions receiver/kubeletstatsreceiver/internal/kubelet/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func TestMetricAccumulator(t *testing.T) {
ContainerMetricsBuilder: metadata.NewMetricsBuilder(metadata.DefaultMetricsSettings(), componenttest.NewNopReceiverCreateSettings().BuildInfo),
OtherMetricsBuilder: metadata.NewMetricsBuilder(metadata.DefaultMetricsSettings(), componenttest.NewNopReceiverCreateSettings().BuildInfo),
}
requireMetricsOk(t, MetricsData(zap.NewNop(), summary, k8sMetadata, ValidMetricGroups, mbs, true, false))
requireMetricsOk(t, MetricsData(zap.NewNop(), summary, k8sMetadata, ValidMetricGroups, mbs))
// Disable all groups
mbs.NodeMetricsBuilder.Reset()
mbs.PodMetricsBuilder.Reset()
mbs.OtherMetricsBuilder.Reset()
require.Equal(t, 0, len(MetricsData(zap.NewNop(), summary, k8sMetadata, map[MetricGroup]bool{}, mbs, true, false)))
require.Equal(t, 0, len(MetricsData(zap.NewNop(), summary, k8sMetadata, map[MetricGroup]bool{}, mbs)))
}

func requireMetricsOk(t *testing.T, mds []pmetric.Metrics) {
Expand Down Expand Up @@ -112,7 +112,7 @@ func requireResourceOk(t *testing.T, resource pcommon.Resource) {
}

func TestWorkingSetMem(t *testing.T) {
metrics := indexedFakeMetrics(true, false)
metrics := indexedFakeMetrics()
requireContains(t, metrics, "k8s.pod.memory.working_set")
requireContains(t, metrics, "container.memory.working_set")

Expand All @@ -122,7 +122,7 @@ func TestWorkingSetMem(t *testing.T) {
}

func TestPageFaults(t *testing.T) {
metrics := indexedFakeMetrics(true, false)
metrics := indexedFakeMetrics()
requireContains(t, metrics, "k8s.pod.memory.page_faults")
requireContains(t, metrics, "container.memory.page_faults")

Expand All @@ -132,7 +132,7 @@ func TestPageFaults(t *testing.T) {
}

func TestMajorPageFaults(t *testing.T) {
metrics := indexedFakeMetrics(true, false)
metrics := indexedFakeMetrics()
requireContains(t, metrics, "k8s.pod.memory.major_page_faults")
requireContains(t, metrics, "container.memory.major_page_faults")

Expand All @@ -142,7 +142,7 @@ func TestMajorPageFaults(t *testing.T) {
}

func TestEmitMetricsWithDirectionAttribute(t *testing.T) {
metrics := indexedFakeMetrics(true, false)
metrics := indexedFakeMetrics()
metricNamesWithDirectionAttr := []string{
"k8s.node.network.io",
"k8s.node.network.errors",
Expand All @@ -160,36 +160,13 @@ func TestEmitMetricsWithDirectionAttribute(t *testing.T) {
}
}

func TestEmitMetricsWithoutDirectionAttribute(t *testing.T) {
metrics := indexedFakeMetrics(false, true)
metricNamesWithoutDirectionAttr := []string{
"k8s.node.network.io.receive",
"k8s.node.network.io.transmit",
"k8s.node.network.errors.receive",
"k8s.node.network.errors.transmit",
"k8s.pod.network.io.receive",
"k8s.pod.network.io.transmit",
"k8s.pod.network.errors.receive",
"k8s.pod.network.errors.transmit",
}
for _, name := range metricNamesWithoutDirectionAttr {
requireContains(t, metrics, name)
metric := metrics[name][0]
for i := 0; i < metric.Sum().DataPoints().Len(); i++ {
dp := metric.Sum().DataPoints().At(i)
_, found := dp.Attributes().Get("direction")
require.False(t, found, "unexpected direction attribute")
}
}
}

func requireContains(t *testing.T, metrics map[string][]pmetric.Metric, metricName string) {
_, found := metrics[metricName]
require.True(t, found)
}

func indexedFakeMetrics(emitMetricsWithDirectionAttribute, emitMetricsWithoutDirectionAttribute bool) map[string][]pmetric.Metric {
mds := fakeMetrics(emitMetricsWithDirectionAttribute, emitMetricsWithoutDirectionAttribute)
func indexedFakeMetrics() map[string][]pmetric.Metric {
mds := fakeMetrics()
metrics := make(map[string][]pmetric.Metric)
for _, md := range mds {
for i := 0; i < md.ResourceMetrics().Len(); i++ {
Expand All @@ -209,7 +186,7 @@ func indexedFakeMetrics(emitMetricsWithDirectionAttribute, emitMetricsWithoutDir
return metrics
}

func fakeMetrics(emitMetricsWithDirectionAttribute, emitMetricsWithoutDirectionAttribute bool) []pmetric.Metrics {
func fakeMetrics() []pmetric.Metrics {
rc := &fakeRestClient{}
statsProvider := NewStatsProvider(rc)
summary, _ := statsProvider.StatsSummary()
Expand All @@ -224,5 +201,5 @@ func fakeMetrics(emitMetricsWithDirectionAttribute, emitMetricsWithoutDirectionA
ContainerMetricsBuilder: metadata.NewMetricsBuilder(metadata.DefaultMetricsSettings(), componenttest.NewNopReceiverCreateSettings().BuildInfo),
OtherMetricsBuilder: metadata.NewMetricsBuilder(metadata.DefaultMetricsSettings(), componenttest.NewNopReceiverCreateSettings().BuildInfo),
}
return MetricsData(zap.NewNop(), summary, Metadata{}, mgs, mbs, emitMetricsWithDirectionAttribute, emitMetricsWithoutDirectionAttribute)
return MetricsData(zap.NewNop(), summary, Metadata{}, mgs, mbs)
}
21 changes: 0 additions & 21 deletions receiver/kubeletstatsreceiver/internal/kubelet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ import (

type getNetworkDataFunc func(s *stats.NetworkStats) (rx *uint64, tx *uint64)

func addNetworkMetrics(mb *metadata.MetricsBuilder, networkMetrics metadata.NetworkMetrics, s *stats.NetworkStats, currentTime pcommon.Timestamp) {
if s == nil {
return
}

recordNetworkDataPoint(mb, networkMetrics.IO, s, getNetworkIO, currentTime)
recordNetworkDataPoint(mb, networkMetrics.Errors, s, getNetworkErrors, currentTime)
}

func recordNetworkDataPoint(mb *metadata.MetricsBuilder, r metadata.NetworkMetricsRecorder, s *stats.NetworkStats, getData getNetworkDataFunc, currentTime pcommon.Timestamp) {
rx, tx := getData(s)

if rx != nil {
r.RecordReceiveDataPoint(mb, currentTime, int64(*rx), s.Name)
}

if tx != nil {
r.RecordTransmitDataPoint(mb, currentTime, int64(*tx), s.Name)
}
}

func addNetworkMetricsWithDirection(mb *metadata.MetricsBuilder, networkMetrics metadata.NetworkMetricsWithDirection, s *stats.NetworkStats, currentTime pcommon.Timestamp) {
if s == nil {
return
Expand Down
Loading