From e9f71d12b664958cbfb973d61663d70f53a24ad4 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 29 Jun 2022 10:41:30 -0700 Subject: [PATCH 1/4] [receiver/hostmetrics/networkscraper] remove direction The following change adds the direction to the metric name, removing the `direction` attribute. Fixes #11817 --- .../hostmetrics_receiver_test.go | 12 +- .../scraper/networkscraper/documentation.md | 13 +- .../internal/metadata/generated_metrics_v2.go | 456 +++++++++++++----- .../scraper/networkscraper/metadata.yaml | 68 ++- .../scraper/networkscraper/network_scraper.go | 16 +- .../networkscraper/network_scraper_test.go | 20 +- 6 files changed, 429 insertions(+), 156 deletions(-) diff --git a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go index ff58c3d4d90f..18fc3f045a06 100644 --- a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go +++ b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go @@ -58,10 +58,14 @@ var standardMetrics = []string{ "system.filesystem.usage", "system.memory.usage", "system.network.connections", - "system.network.dropped", - "system.network.errors", - "system.network.io", - "system.network.packets", + "system.network.dropped.receive", + "system.network.dropped.transmit", + "system.network.errors.receive", + "system.network.errors.transmit", + "system.network.io.receive", + "system.network.io.transmit", + "system.network.packets.receive", + "system.network.packets.transmit", "system.paging.operations", "system.paging.usage", } diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md index 681f1adab581..378b24fa0d68 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md @@ -9,10 +9,14 @@ These are the metrics available for this scraper. | Name | Description | Unit | Type | Attributes | | ---- | ----------- | ---- | ---- | ---------- | | **system.network.connections** | The number of connections. | {connections} | Sum(Int) | | -| **system.network.dropped** | The number of packets dropped. | {packets} | Sum(Int) | | -| **system.network.errors** | The number of errors encountered. | {errors} | Sum(Int) | | -| **system.network.io** | The number of bytes transmitted and received. | By | Sum(Int) | | -| **system.network.packets** | The number of packets transferred. | {packets} | Sum(Int) | | +| **system.network.dropped.receive** | The number of packets dropped on receive. | {packets} | Sum(Int) | | +| **system.network.dropped.transmit** | The number of packets dropped on transmit. | {packets} | Sum(Int) | | +| **system.network.errors.receive** | The number of errors encountered on receive. | {errors} | Sum(Int) | | +| **system.network.errors.transmit** | The number of errors encountered on transmit. | {errors} | Sum(Int) | | +| **system.network.io.receive** | The number of bytes received. | By | Sum(Int) | | +| **system.network.io.transmit** | The number of bytes transmitted. | By | Sum(Int) | | +| **system.network.packets.receive** | The number of packets received. | {packets} | Sum(Int) | | +| **system.network.packets.transmit** | The number of packets transmitted. | {packets} | Sum(Int) | | **Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default. Any metric can be enabled or disabled with the following scraper configuration: @@ -28,6 +32,5 @@ metrics: | Name | Description | Values | | ---- | ----------- | ------ | | device | Name of the network interface. | | -| direction | Direction of flow of bytes/operations (receive or transmit). | receive, transmit | | protocol | Network protocol, e.g. TCP or UDP. | tcp | | state | State of the network connection. | | diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go index 0b2759dd9e45..28128ffdd1c4 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go @@ -18,11 +18,15 @@ type MetricSettings struct { // MetricsSettings provides settings for hostmetricsreceiver/network metrics. type MetricsSettings struct { - SystemNetworkConnections MetricSettings `mapstructure:"system.network.connections"` - SystemNetworkDropped MetricSettings `mapstructure:"system.network.dropped"` - SystemNetworkErrors MetricSettings `mapstructure:"system.network.errors"` - SystemNetworkIo MetricSettings `mapstructure:"system.network.io"` - SystemNetworkPackets MetricSettings `mapstructure:"system.network.packets"` + SystemNetworkConnections MetricSettings `mapstructure:"system.network.connections"` + SystemNetworkDroppedReceive MetricSettings `mapstructure:"system.network.dropped.receive"` + SystemNetworkDroppedTransmit MetricSettings `mapstructure:"system.network.dropped.transmit"` + SystemNetworkErrorsReceive MetricSettings `mapstructure:"system.network.errors.receive"` + SystemNetworkErrorsTransmit MetricSettings `mapstructure:"system.network.errors.transmit"` + SystemNetworkIoReceive MetricSettings `mapstructure:"system.network.io.receive"` + SystemNetworkIoTransmit MetricSettings `mapstructure:"system.network.io.transmit"` + SystemNetworkPacketsReceive MetricSettings `mapstructure:"system.network.packets.receive"` + SystemNetworkPacketsTransmit MetricSettings `mapstructure:"system.network.packets.transmit"` } func DefaultMetricsSettings() MetricsSettings { @@ -30,47 +34,33 @@ func DefaultMetricsSettings() MetricsSettings { SystemNetworkConnections: MetricSettings{ Enabled: true, }, - SystemNetworkDropped: MetricSettings{ + SystemNetworkDroppedReceive: MetricSettings{ Enabled: true, }, - SystemNetworkErrors: MetricSettings{ + SystemNetworkDroppedTransmit: MetricSettings{ Enabled: true, }, - SystemNetworkIo: MetricSettings{ + SystemNetworkErrorsReceive: MetricSettings{ Enabled: true, }, - SystemNetworkPackets: MetricSettings{ + SystemNetworkErrorsTransmit: MetricSettings{ + Enabled: true, + }, + SystemNetworkIoReceive: MetricSettings{ + Enabled: true, + }, + SystemNetworkIoTransmit: MetricSettings{ + Enabled: true, + }, + SystemNetworkPacketsReceive: MetricSettings{ + Enabled: true, + }, + SystemNetworkPacketsTransmit: MetricSettings{ Enabled: true, }, } } -// AttributeDirection specifies the a value direction attribute. -type AttributeDirection int - -const ( - _ AttributeDirection = iota - AttributeDirectionReceive - AttributeDirectionTransmit -) - -// String returns the string representation of the AttributeDirection. -func (av AttributeDirection) String() string { - switch av { - case AttributeDirectionReceive: - return "receive" - case AttributeDirectionTransmit: - return "transmit" - } - return "" -} - -// MapAttributeDirection is a helper map of string to AttributeDirection attribute value. -var MapAttributeDirection = map[string]AttributeDirection{ - "receive": AttributeDirectionReceive, - "transmit": AttributeDirectionTransmit, -} - // AttributeProtocol specifies the a value protocol attribute. type AttributeProtocol int @@ -147,16 +137,69 @@ func newMetricSystemNetworkConnections(settings MetricSettings) metricSystemNetw return m } -type metricSystemNetworkDropped struct { +type metricSystemNetworkDroppedReceive struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.dropped.receive metric with initial data. +func (m *metricSystemNetworkDroppedReceive) init() { + m.data.SetName("system.network.dropped.receive") + m.data.SetDescription("The number of packets dropped on receive.") + m.data.SetUnit("{packets}") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkDroppedReceive) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkDroppedReceive) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkDroppedReceive) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkDroppedReceive(settings MetricSettings) metricSystemNetworkDroppedReceive { + m := metricSystemNetworkDroppedReceive{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricSystemNetworkDroppedTransmit struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. capacity int // max observed number of data points added to the metric. } -// init fills system.network.dropped metric with initial data. -func (m *metricSystemNetworkDropped) init() { - m.data.SetName("system.network.dropped") - m.data.SetDescription("The number of packets dropped.") +// init fills system.network.dropped.transmit metric with initial data. +func (m *metricSystemNetworkDroppedTransmit) init() { + m.data.SetName("system.network.dropped.transmit") + m.data.SetDescription("The number of packets dropped on transmit.") m.data.SetUnit("{packets}") m.data.SetDataType(pmetric.MetricDataTypeSum) m.data.Sum().SetIsMonotonic(true) @@ -164,7 +207,7 @@ func (m *metricSystemNetworkDropped) init() { m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricSystemNetworkDropped) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { +func (m *metricSystemNetworkDroppedTransmit) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { if !m.settings.Enabled { return } @@ -173,18 +216,17 @@ func (m *metricSystemNetworkDropped) recordDataPoint(start pcommon.Timestamp, ts dp.SetTimestamp(ts) dp.SetIntVal(val) dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) - dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricSystemNetworkDropped) updateCapacity() { +func (m *metricSystemNetworkDroppedTransmit) updateCapacity() { if m.data.Sum().DataPoints().Len() > m.capacity { m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricSystemNetworkDropped) emit(metrics pmetric.MetricSlice) { +func (m *metricSystemNetworkDroppedTransmit) emit(metrics pmetric.MetricSlice) { if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -192,8 +234,8 @@ func (m *metricSystemNetworkDropped) emit(metrics pmetric.MetricSlice) { } } -func newMetricSystemNetworkDropped(settings MetricSettings) metricSystemNetworkDropped { - m := metricSystemNetworkDropped{settings: settings} +func newMetricSystemNetworkDroppedTransmit(settings MetricSettings) metricSystemNetworkDroppedTransmit { + m := metricSystemNetworkDroppedTransmit{settings: settings} if settings.Enabled { m.data = pmetric.NewMetric() m.init() @@ -201,16 +243,16 @@ func newMetricSystemNetworkDropped(settings MetricSettings) metricSystemNetworkD return m } -type metricSystemNetworkErrors struct { +type metricSystemNetworkErrorsReceive struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. capacity int // max observed number of data points added to the metric. } -// init fills system.network.errors metric with initial data. -func (m *metricSystemNetworkErrors) init() { - m.data.SetName("system.network.errors") - m.data.SetDescription("The number of errors encountered.") +// init fills system.network.errors.receive metric with initial data. +func (m *metricSystemNetworkErrorsReceive) init() { + m.data.SetName("system.network.errors.receive") + m.data.SetDescription("The number of errors encountered on receive.") m.data.SetUnit("{errors}") m.data.SetDataType(pmetric.MetricDataTypeSum) m.data.Sum().SetIsMonotonic(true) @@ -218,7 +260,7 @@ func (m *metricSystemNetworkErrors) init() { m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricSystemNetworkErrors) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { +func (m *metricSystemNetworkErrorsReceive) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { if !m.settings.Enabled { return } @@ -227,18 +269,17 @@ func (m *metricSystemNetworkErrors) recordDataPoint(start pcommon.Timestamp, ts dp.SetTimestamp(ts) dp.SetIntVal(val) dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) - dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricSystemNetworkErrors) updateCapacity() { +func (m *metricSystemNetworkErrorsReceive) updateCapacity() { if m.data.Sum().DataPoints().Len() > m.capacity { m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricSystemNetworkErrors) emit(metrics pmetric.MetricSlice) { +func (m *metricSystemNetworkErrorsReceive) emit(metrics pmetric.MetricSlice) { if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -246,8 +287,8 @@ func (m *metricSystemNetworkErrors) emit(metrics pmetric.MetricSlice) { } } -func newMetricSystemNetworkErrors(settings MetricSettings) metricSystemNetworkErrors { - m := metricSystemNetworkErrors{settings: settings} +func newMetricSystemNetworkErrorsReceive(settings MetricSettings) metricSystemNetworkErrorsReceive { + m := metricSystemNetworkErrorsReceive{settings: settings} if settings.Enabled { m.data = pmetric.NewMetric() m.init() @@ -255,16 +296,122 @@ func newMetricSystemNetworkErrors(settings MetricSettings) metricSystemNetworkEr return m } -type metricSystemNetworkIo struct { +type metricSystemNetworkErrorsTransmit struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. capacity int // max observed number of data points added to the metric. } -// init fills system.network.io metric with initial data. -func (m *metricSystemNetworkIo) init() { - m.data.SetName("system.network.io") - m.data.SetDescription("The number of bytes transmitted and received.") +// init fills system.network.errors.transmit metric with initial data. +func (m *metricSystemNetworkErrorsTransmit) init() { + m.data.SetName("system.network.errors.transmit") + m.data.SetDescription("The number of errors encountered on transmit.") + m.data.SetUnit("{errors}") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkErrorsTransmit) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkErrorsTransmit) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkErrorsTransmit) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkErrorsTransmit(settings MetricSettings) metricSystemNetworkErrorsTransmit { + m := metricSystemNetworkErrorsTransmit{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricSystemNetworkIoReceive struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.io.receive metric with initial data. +func (m *metricSystemNetworkIoReceive) init() { + m.data.SetName("system.network.io.receive") + m.data.SetDescription("The number of bytes received.") + m.data.SetUnit("By") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkIoReceive) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkIoReceive) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkIoReceive) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkIoReceive(settings MetricSettings) metricSystemNetworkIoReceive { + m := metricSystemNetworkIoReceive{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricSystemNetworkIoTransmit struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.io.transmit metric with initial data. +func (m *metricSystemNetworkIoTransmit) init() { + m.data.SetName("system.network.io.transmit") + m.data.SetDescription("The number of bytes transmitted.") m.data.SetUnit("By") m.data.SetDataType(pmetric.MetricDataTypeSum) m.data.Sum().SetIsMonotonic(true) @@ -272,7 +419,7 @@ func (m *metricSystemNetworkIo) init() { m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricSystemNetworkIo) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { +func (m *metricSystemNetworkIoTransmit) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { if !m.settings.Enabled { return } @@ -281,18 +428,17 @@ func (m *metricSystemNetworkIo) recordDataPoint(start pcommon.Timestamp, ts pcom dp.SetTimestamp(ts) dp.SetIntVal(val) dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) - dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricSystemNetworkIo) updateCapacity() { +func (m *metricSystemNetworkIoTransmit) updateCapacity() { if m.data.Sum().DataPoints().Len() > m.capacity { m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricSystemNetworkIo) emit(metrics pmetric.MetricSlice) { +func (m *metricSystemNetworkIoTransmit) emit(metrics pmetric.MetricSlice) { if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -300,8 +446,8 @@ func (m *metricSystemNetworkIo) emit(metrics pmetric.MetricSlice) { } } -func newMetricSystemNetworkIo(settings MetricSettings) metricSystemNetworkIo { - m := metricSystemNetworkIo{settings: settings} +func newMetricSystemNetworkIoTransmit(settings MetricSettings) metricSystemNetworkIoTransmit { + m := metricSystemNetworkIoTransmit{settings: settings} if settings.Enabled { m.data = pmetric.NewMetric() m.init() @@ -309,16 +455,16 @@ func newMetricSystemNetworkIo(settings MetricSettings) metricSystemNetworkIo { return m } -type metricSystemNetworkPackets struct { +type metricSystemNetworkPacketsReceive struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. capacity int // max observed number of data points added to the metric. } -// init fills system.network.packets metric with initial data. -func (m *metricSystemNetworkPackets) init() { - m.data.SetName("system.network.packets") - m.data.SetDescription("The number of packets transferred.") +// init fills system.network.packets.receive metric with initial data. +func (m *metricSystemNetworkPacketsReceive) init() { + m.data.SetName("system.network.packets.receive") + m.data.SetDescription("The number of packets received.") m.data.SetUnit("{packets}") m.data.SetDataType(pmetric.MetricDataTypeSum) m.data.Sum().SetIsMonotonic(true) @@ -326,7 +472,7 @@ func (m *metricSystemNetworkPackets) init() { m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricSystemNetworkPackets) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { +func (m *metricSystemNetworkPacketsReceive) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { if !m.settings.Enabled { return } @@ -335,18 +481,17 @@ func (m *metricSystemNetworkPackets) recordDataPoint(start pcommon.Timestamp, ts dp.SetTimestamp(ts) dp.SetIntVal(val) dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) - dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricSystemNetworkPackets) updateCapacity() { +func (m *metricSystemNetworkPacketsReceive) updateCapacity() { if m.data.Sum().DataPoints().Len() > m.capacity { m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricSystemNetworkPackets) emit(metrics pmetric.MetricSlice) { +func (m *metricSystemNetworkPacketsReceive) emit(metrics pmetric.MetricSlice) { if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -354,8 +499,61 @@ func (m *metricSystemNetworkPackets) emit(metrics pmetric.MetricSlice) { } } -func newMetricSystemNetworkPackets(settings MetricSettings) metricSystemNetworkPackets { - m := metricSystemNetworkPackets{settings: settings} +func newMetricSystemNetworkPacketsReceive(settings MetricSettings) metricSystemNetworkPacketsReceive { + m := metricSystemNetworkPacketsReceive{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricSystemNetworkPacketsTransmit struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.packets.transmit metric with initial data. +func (m *metricSystemNetworkPacketsTransmit) init() { + m.data.SetName("system.network.packets.transmit") + m.data.SetDescription("The number of packets transmitted.") + m.data.SetUnit("{packets}") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkPacketsTransmit) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkPacketsTransmit) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkPacketsTransmit) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkPacketsTransmit(settings MetricSettings) metricSystemNetworkPacketsTransmit { + m := metricSystemNetworkPacketsTransmit{settings: settings} if settings.Enabled { m.data = pmetric.NewMetric() m.init() @@ -366,16 +564,20 @@ func newMetricSystemNetworkPackets(settings MetricSettings) metricSystemNetworkP // MetricsBuilder provides an interface for scrapers to report metrics while taking care of all the transformations // required to produce metric representation defined in metadata and user settings. type MetricsBuilder struct { - startTime pcommon.Timestamp // start time that will be applied to all recorded data points. - metricsCapacity int // maximum observed number of metrics per resource. - resourceCapacity int // maximum observed number of resource attributes. - metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. - buildInfo component.BuildInfo // contains version information - metricSystemNetworkConnections metricSystemNetworkConnections - metricSystemNetworkDropped metricSystemNetworkDropped - metricSystemNetworkErrors metricSystemNetworkErrors - metricSystemNetworkIo metricSystemNetworkIo - metricSystemNetworkPackets metricSystemNetworkPackets + startTime pcommon.Timestamp // start time that will be applied to all recorded data points. + metricsCapacity int // maximum observed number of metrics per resource. + resourceCapacity int // maximum observed number of resource attributes. + metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. + buildInfo component.BuildInfo // contains version information + metricSystemNetworkConnections metricSystemNetworkConnections + metricSystemNetworkDroppedReceive metricSystemNetworkDroppedReceive + metricSystemNetworkDroppedTransmit metricSystemNetworkDroppedTransmit + metricSystemNetworkErrorsReceive metricSystemNetworkErrorsReceive + metricSystemNetworkErrorsTransmit metricSystemNetworkErrorsTransmit + metricSystemNetworkIoReceive metricSystemNetworkIoReceive + metricSystemNetworkIoTransmit metricSystemNetworkIoTransmit + metricSystemNetworkPacketsReceive metricSystemNetworkPacketsReceive + metricSystemNetworkPacketsTransmit metricSystemNetworkPacketsTransmit } // metricBuilderOption applies changes to default metrics builder. @@ -390,14 +592,18 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { func NewMetricsBuilder(settings MetricsSettings, buildInfo component.BuildInfo, options ...metricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ - startTime: pcommon.NewTimestampFromTime(time.Now()), - metricsBuffer: pmetric.NewMetrics(), - buildInfo: buildInfo, - metricSystemNetworkConnections: newMetricSystemNetworkConnections(settings.SystemNetworkConnections), - metricSystemNetworkDropped: newMetricSystemNetworkDropped(settings.SystemNetworkDropped), - metricSystemNetworkErrors: newMetricSystemNetworkErrors(settings.SystemNetworkErrors), - metricSystemNetworkIo: newMetricSystemNetworkIo(settings.SystemNetworkIo), - metricSystemNetworkPackets: newMetricSystemNetworkPackets(settings.SystemNetworkPackets), + startTime: pcommon.NewTimestampFromTime(time.Now()), + metricsBuffer: pmetric.NewMetrics(), + buildInfo: buildInfo, + metricSystemNetworkConnections: newMetricSystemNetworkConnections(settings.SystemNetworkConnections), + metricSystemNetworkDroppedReceive: newMetricSystemNetworkDroppedReceive(settings.SystemNetworkDroppedReceive), + metricSystemNetworkDroppedTransmit: newMetricSystemNetworkDroppedTransmit(settings.SystemNetworkDroppedTransmit), + metricSystemNetworkErrorsReceive: newMetricSystemNetworkErrorsReceive(settings.SystemNetworkErrorsReceive), + metricSystemNetworkErrorsTransmit: newMetricSystemNetworkErrorsTransmit(settings.SystemNetworkErrorsTransmit), + metricSystemNetworkIoReceive: newMetricSystemNetworkIoReceive(settings.SystemNetworkIoReceive), + metricSystemNetworkIoTransmit: newMetricSystemNetworkIoTransmit(settings.SystemNetworkIoTransmit), + metricSystemNetworkPacketsReceive: newMetricSystemNetworkPacketsReceive(settings.SystemNetworkPacketsReceive), + metricSystemNetworkPacketsTransmit: newMetricSystemNetworkPacketsTransmit(settings.SystemNetworkPacketsTransmit), } for _, op := range options { op(mb) @@ -452,10 +658,14 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemNetworkConnections.emit(ils.Metrics()) - mb.metricSystemNetworkDropped.emit(ils.Metrics()) - mb.metricSystemNetworkErrors.emit(ils.Metrics()) - mb.metricSystemNetworkIo.emit(ils.Metrics()) - mb.metricSystemNetworkPackets.emit(ils.Metrics()) + mb.metricSystemNetworkDroppedReceive.emit(ils.Metrics()) + mb.metricSystemNetworkDroppedTransmit.emit(ils.Metrics()) + mb.metricSystemNetworkErrorsReceive.emit(ils.Metrics()) + mb.metricSystemNetworkErrorsTransmit.emit(ils.Metrics()) + mb.metricSystemNetworkIoReceive.emit(ils.Metrics()) + mb.metricSystemNetworkIoTransmit.emit(ils.Metrics()) + mb.metricSystemNetworkPacketsReceive.emit(ils.Metrics()) + mb.metricSystemNetworkPacketsTransmit.emit(ils.Metrics()) for _, op := range rmo { op(rm) } @@ -480,24 +690,44 @@ func (mb *MetricsBuilder) RecordSystemNetworkConnectionsDataPoint(ts pcommon.Tim mb.metricSystemNetworkConnections.recordDataPoint(mb.startTime, ts, val, protocolAttributeValue.String(), stateAttributeValue) } -// RecordSystemNetworkDroppedDataPoint adds a data point to system.network.dropped metric. -func (mb *MetricsBuilder) RecordSystemNetworkDroppedDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { - mb.metricSystemNetworkDropped.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +// RecordSystemNetworkDroppedReceiveDataPoint adds a data point to system.network.dropped.receive metric. +func (mb *MetricsBuilder) RecordSystemNetworkDroppedReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkDroppedReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) +} + +// RecordSystemNetworkDroppedTransmitDataPoint adds a data point to system.network.dropped.transmit metric. +func (mb *MetricsBuilder) RecordSystemNetworkDroppedTransmitDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkDroppedTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) +} + +// RecordSystemNetworkErrorsReceiveDataPoint adds a data point to system.network.errors.receive metric. +func (mb *MetricsBuilder) RecordSystemNetworkErrorsReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkErrorsReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) +} + +// RecordSystemNetworkErrorsTransmitDataPoint adds a data point to system.network.errors.transmit metric. +func (mb *MetricsBuilder) RecordSystemNetworkErrorsTransmitDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkErrorsTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) +} + +// RecordSystemNetworkIoReceiveDataPoint adds a data point to system.network.io.receive metric. +func (mb *MetricsBuilder) RecordSystemNetworkIoReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkIoReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } -// RecordSystemNetworkErrorsDataPoint adds a data point to system.network.errors metric. -func (mb *MetricsBuilder) RecordSystemNetworkErrorsDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { - mb.metricSystemNetworkErrors.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +// RecordSystemNetworkIoTransmitDataPoint adds a data point to system.network.io.transmit metric. +func (mb *MetricsBuilder) RecordSystemNetworkIoTransmitDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkIoTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } -// RecordSystemNetworkIoDataPoint adds a data point to system.network.io metric. -func (mb *MetricsBuilder) RecordSystemNetworkIoDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { - mb.metricSystemNetworkIo.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +// RecordSystemNetworkPacketsReceiveDataPoint adds a data point to system.network.packets.receive metric. +func (mb *MetricsBuilder) RecordSystemNetworkPacketsReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkPacketsReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } -// RecordSystemNetworkPacketsDataPoint adds a data point to system.network.packets metric. -func (mb *MetricsBuilder) RecordSystemNetworkPacketsDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { - mb.metricSystemNetworkPackets.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +// RecordSystemNetworkPacketsTransmitDataPoint adds a data point to system.network.packets.transmit metric. +func (mb *MetricsBuilder) RecordSystemNetworkPacketsTransmitDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { + mb.metricSystemNetworkPacketsTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml index 9522a8053cdb..10f1e1cffa8c 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml @@ -6,10 +6,6 @@ attributes: device: description: Name of the network interface. - direction: - description: Direction of flow of bytes/operations (receive or transmit). - enum: [receive, transmit] - protocol: description: Network protocol, e.g. TCP or UDP. enum: [tcp] @@ -18,45 +14,85 @@ attributes: description: State of the network connection. metrics: - system.network.packets: + system.network.packets.transmit: + enabled: true + description: The number of packets transmitted. + unit: "{packets}" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device] + + system.network.packets.receive: + enabled: true + description: The number of packets received. + unit: "{packets}" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device] + + system.network.dropped.transmit: enabled: true - description: The number of packets transferred. + description: The number of packets dropped on transmit. unit: "{packets}" sum: value_type: int aggregation: cumulative monotonic: true - attributes: [device, direction] + attributes: [device] - system.network.dropped: + system.network.dropped.receive: enabled: true - description: The number of packets dropped. + description: The number of packets dropped on receive. unit: "{packets}" sum: value_type: int aggregation: cumulative monotonic: true - attributes: [device, direction] + attributes: [device] - system.network.errors: + system.network.errors.transmit: enabled: true - description: The number of errors encountered. + description: The number of errors encountered on transmit. unit: "{errors}" sum: value_type: int aggregation: cumulative monotonic: true - attributes: [device, direction] + attributes: [device] + + system.network.errors.receive: + enabled: true + description: The number of errors encountered on receive. + unit: "{errors}" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device] + + system.network.io.transmit: + enabled: true + description: The number of bytes transmitted. + unit: "By" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device] - system.network.io: + system.network.io.receive: enabled: true - description: The number of bytes transmitted and received. + description: The number of bytes received. unit: "By" sum: value_type: int aggregation: cumulative monotonic: true - attributes: [device, direction] + attributes: [device] system.network.connections: enabled: true diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go index f769d173e790..e832937f07c3 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go @@ -124,29 +124,29 @@ func (s *scraper) recordNetworkCounterMetrics() error { func (s *scraper) recordNetworkPacketsMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkPacketsDataPoint(now, int64(ioCounters.PacketsSent), ioCounters.Name, metadata.AttributeDirectionTransmit) - s.mb.RecordSystemNetworkPacketsDataPoint(now, int64(ioCounters.PacketsRecv), ioCounters.Name, metadata.AttributeDirectionReceive) + s.mb.RecordSystemNetworkPacketsTransmitDataPoint(now, int64(ioCounters.PacketsSent), ioCounters.Name) + s.mb.RecordSystemNetworkPacketsReceiveDataPoint(now, int64(ioCounters.PacketsRecv), ioCounters.Name) } } func (s *scraper) recordNetworkDroppedPacketsMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkDroppedDataPoint(now, int64(ioCounters.Dropout), ioCounters.Name, metadata.AttributeDirectionTransmit) - s.mb.RecordSystemNetworkDroppedDataPoint(now, int64(ioCounters.Dropin), ioCounters.Name, metadata.AttributeDirectionReceive) + s.mb.RecordSystemNetworkDroppedTransmitDataPoint(now, int64(ioCounters.Dropout), ioCounters.Name) + s.mb.RecordSystemNetworkDroppedReceiveDataPoint(now, int64(ioCounters.Dropin), ioCounters.Name) } } func (s *scraper) recordNetworkErrorPacketsMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkErrorsDataPoint(now, int64(ioCounters.Errout), ioCounters.Name, metadata.AttributeDirectionTransmit) - s.mb.RecordSystemNetworkErrorsDataPoint(now, int64(ioCounters.Errin), ioCounters.Name, metadata.AttributeDirectionReceive) + s.mb.RecordSystemNetworkErrorsTransmitDataPoint(now, int64(ioCounters.Errout), ioCounters.Name) + s.mb.RecordSystemNetworkErrorsReceiveDataPoint(now, int64(ioCounters.Errin), ioCounters.Name) } } func (s *scraper) recordNetworkIOMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkIoDataPoint(now, int64(ioCounters.BytesSent), ioCounters.Name, metadata.AttributeDirectionTransmit) - s.mb.RecordSystemNetworkIoDataPoint(now, int64(ioCounters.BytesRecv), ioCounters.Name, metadata.AttributeDirectionReceive) + s.mb.RecordSystemNetworkIoTransmitDataPoint(now, int64(ioCounters.BytesSent), ioCounters.Name) + s.mb.RecordSystemNetworkIoReceiveDataPoint(now, int64(ioCounters.BytesRecv), ioCounters.Name) } } diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go index 562558f5ce74..db6fe354bf65 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go @@ -152,7 +152,7 @@ func TestScrape(t *testing.T) { expectedMetricCount := 1 if test.expectNetworkMetrics { - expectedMetricCount += 4 + expectedMetricCount += 8 } assert.Equal(t, expectedMetricCount, md.MetricCount()) @@ -160,10 +160,14 @@ func TestScrape(t *testing.T) { idx := 0 assertNetworkConnectionsMetricValid(t, metrics.At(idx)) if test.expectNetworkMetrics { - assertNetworkIOMetricValid(t, metrics.At(idx+1), "system.network.dropped", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+2), "system.network.errors", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+3), "system.network.io", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+4), "system.network.packets", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+1), "system.network.dropped.receive", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+2), "system.network.dropped.transmit", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+3), "system.network.errors.receive", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+4), "system.network.errors.transmit", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+5), "system.network.io.receive", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+6), "system.network.io.transmit", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+7), "system.network.packets.receive", test.expectedStartTime) + assertNetworkIOMetricValid(t, metrics.At(idx+8), "system.network.packets.transmit", test.expectedStartTime) internal.AssertSameTimeStampForMetrics(t, metrics, 1, 5) idx += 4 } @@ -178,12 +182,8 @@ func assertNetworkIOMetricValid(t *testing.T, metric pmetric.Metric, expectedNam if startTime != 0 { internal.AssertSumMetricStartTimeEquals(t, metric, startTime) } - assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 2) + assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 1) internal.AssertSumMetricHasAttribute(t, metric, 0, "device") - internal.AssertSumMetricHasAttributeValue(t, metric, 0, "direction", - pcommon.NewValueString(metadata.AttributeDirectionTransmit.String())) - internal.AssertSumMetricHasAttributeValue(t, metric, 1, "direction", - pcommon.NewValueString(metadata.AttributeDirectionReceive.String())) } func assertNetworkConnectionsMetricValid(t *testing.T, metric pmetric.Metric) { From 4b26ad373fde26b30d441354af071cb81b0094d2 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 29 Jun 2022 11:38:38 -0700 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f12723aa6eb..0c62fddd2681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,19 @@ - If users were disabling this feature gate, they may have to update monitoring for a few Kubernetes cpu metrics. For more details see [feature-gate-configurations](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.54.0/receiver/k8sclusterreceiver#feature-gate-configurations). - `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950) +- `hostmetricsreceiver`: remove direction attribute (#11820) + - `system.network.dropped` becomes: + - `system.network.dropped.receive` + - `system.network.dropped.transmit` + - `system.network.errors` becomes: + - `system.network.errors.receive` + - `system.network.errors.transmit` + - `system.network.io` becomes: + - `system.network.io.receive` + - `system.network.io.transmit` + - `system.network.packets` becomes: + - `system.network.packets.receive` + - `system.network.packets.transmit` ### 🚩 Deprecations 🚩 From c9e63c4ac3d2068ae61de2423783ee7ce9543492 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 29 Jun 2022 14:16:59 -0700 Subject: [PATCH 3/4] put direction change behind feature gate --- CHANGELOG.md | 18 +- receiver/hostmetricsreceiver/README.md | 50 ++- .../hostmetrics_receiver_test.go | 12 +- .../scraper/networkscraper/documentation.md | 5 + .../internal/metadata/generated_metrics_v2.go | 290 ++++++++++++++++++ .../scraper/networkscraper/metadata.yaml | 44 +++ .../scraper/networkscraper/network_scraper.go | 62 +++- .../networkscraper/network_scraper_test.go | 73 +++-- 8 files changed, 504 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c62fddd2681..025ea3fde7a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,24 +8,24 @@ - If users were disabling this feature gate, they may have to update monitoring for a few Kubernetes cpu metrics. For more details see [feature-gate-configurations](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.54.0/receiver/k8sclusterreceiver#feature-gate-configurations). - `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950) -- `hostmetricsreceiver`: remove direction attribute (#11820) - - `system.network.dropped` becomes: + +### 🚩 Deprecations 🚩 + +- `logzioexporter`: Announcing `custom_endpoint`, `drain_interval`, `queue_capacity`, `queue_max_length` configuration options will be deprecated in upcoming releases (#10821) +- `hostmetricsreceiver`: remove direction attribute. The feature gate: `receiver.hostmetricsreceiver.removeDirectionAttribute` can be set to apply the following (#11820) + - `system.network.dropped` will become: - `system.network.dropped.receive` - `system.network.dropped.transmit` - - `system.network.errors` becomes: + - `system.network.errors` will become: - `system.network.errors.receive` - `system.network.errors.transmit` - - `system.network.io` becomes: + - `system.network.io` will become: - `system.network.io.receive` - `system.network.io.transmit` - - `system.network.packets` becomes: + - `system.network.packets` will become: - `system.network.packets.receive` - `system.network.packets.transmit` -### 🚩 Deprecations 🚩 - -- `logzioexporter`: Announcing `custom_endpoint`, `drain_interval`, `queue_capacity`, `queue_max_length` configuration options will be deprecated in upcoming releases (#10821) - ### 🚀 New components 🚀 ### 💡 Enhancements 💡 diff --git a/receiver/hostmetricsreceiver/README.md b/receiver/hostmetricsreceiver/README.md index 57d04160744e..4afd77cb6b7b 100644 --- a/receiver/hostmetricsreceiver/README.md +++ b/receiver/hostmetricsreceiver/README.md @@ -1,7 +1,7 @@ # Host Metrics Receiver | Status | | -| ------------------------ |-------------------| +| ------------------------ | ----------------- | | Stability | [beta] | | Supported pipeline types | metrics | | Distributions | [core], [contrib] | @@ -27,14 +27,14 @@ hostmetrics: The available scrapers are: | Scraper | Supported OSs | Description | -|------------|------------------------------|--------------------------------------------------------| +| ---------- | ---------------------------- | ------------------------------------------------------ | | cpu | All except Mac[1] | CPU utilization metrics | | disk | All except Mac[1] | Disk I/O metrics | | load | All | CPU load metrics | | filesystem | All | File System utilization metrics | | memory | All | Memory utilization metrics | | network | All | Network interface I/O metrics & TCP connection metrics | -| paging | All | Paging/Swap space utilization and I/O metrics +| paging | All | Paging/Swap space utilization and I/O metrics | | processes | Linux | Process count metrics | | process | Linux & Windows | Per process CPU, Memory, and Disk I/O metrics | @@ -130,6 +130,50 @@ service: receivers: [hostmetrics, hostmetrics/disk] ``` +### Feature gate configurations + +- `receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics` + - Description + - Some network metrics reported by the hostmetricsreceiver are transitioning from being reported + with a direction attribute to being reported with the direction included in the metric name to adhere to the + OpenTelemetry specification. Please update any monitoring this might affect. + - Affected Metrics + - `system.network.dropped` will become: + - `system.network.dropped.receive` + - `system.network.dropped.transmit` + - `system.network.errors` will become: + - `system.network.errors.receive` + - `system.network.errors.transmit` + - `system.network.io` will become: + - `system.network.io.receive` + - `system.network.io.transmit` + - `system.network.packets` will become: + - `system.network.packets.receive` + - `system.network.packets.transmit` + - Stages and Timeline + - Alpha (current stage) + - In this stage the feature gate is disabled by default and must be enabled by the user. This allows users to preemptively opt in and start using the bug fix by enabling the feature gate. + - Collector version: v0.55.0 + - Release Date: Early July 2022 + - Beta + - In this stage the feature gate is enabled by default and can be disabled by the user. + - Collector version: v0.57.0 + - Release Date: Early August 2022 + - Generally Available + - In this stage the feature gate is permanently enabled and the feature gate is no longer available for anyone. + - Users could experience some friction in this stage, they may have to update monitoring for the affected metrics or be blocked from upgrading the collector to versions v0.59.0 and newer. + - Collector version: v0.59.0 + - Release Date: Early September 2022 + - Usage + - Feature gate identifiers prefixed with - will disable the gate and prefixing with + or with no prefix will enable the gate. + - Start the otelcol with the feature gate enabled: + - otelcol {other_arguments} --feature-gates=receiver.k8sclusterreceiver.reportCpuMetricsAsDouble + - Start the otelcol with the feature gate disabled: + - otelcol {other_arguments} --feature-gates=-receiver.k8sclusterreceiver.reportCpuMetricsAsDouble + - More information: + - https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/11815 + - https://github.com/open-telemetry/opentelemetry-specification/pull/2617 + [beta]: https://github.com/open-telemetry/opentelemetry-collector#beta [contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib [core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol diff --git a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go index 18fc3f045a06..ff58c3d4d90f 100644 --- a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go +++ b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go @@ -58,14 +58,10 @@ var standardMetrics = []string{ "system.filesystem.usage", "system.memory.usage", "system.network.connections", - "system.network.dropped.receive", - "system.network.dropped.transmit", - "system.network.errors.receive", - "system.network.errors.transmit", - "system.network.io.receive", - "system.network.io.transmit", - "system.network.packets.receive", - "system.network.packets.transmit", + "system.network.dropped", + "system.network.errors", + "system.network.io", + "system.network.packets", "system.paging.operations", "system.paging.usage", } diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md index 378b24fa0d68..7ce6bc26f6cb 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md @@ -9,12 +9,16 @@ These are the metrics available for this scraper. | Name | Description | Unit | Type | Attributes | | ---- | ----------- | ---- | ---- | ---------- | | **system.network.connections** | The number of connections. | {connections} | Sum(Int) |
  • protocol
  • state
| +| **system.network.dropped** | The number of packets dropped. (Deprecated) | {packets} | Sum(Int) |
  • device
  • direction
| | **system.network.dropped.receive** | The number of packets dropped on receive. | {packets} | Sum(Int) |
  • device
| | **system.network.dropped.transmit** | The number of packets dropped on transmit. | {packets} | Sum(Int) |
  • device
| +| **system.network.errors** | The number of errors encountered. (Deprecated) | {errors} | Sum(Int) |
  • device
  • direction
| | **system.network.errors.receive** | The number of errors encountered on receive. | {errors} | Sum(Int) |
  • device
| | **system.network.errors.transmit** | The number of errors encountered on transmit. | {errors} | Sum(Int) |
  • device
| +| **system.network.io** | The number of bytes transmitted and received. (Deprecated) | By | Sum(Int) |
  • device
  • direction
| | **system.network.io.receive** | The number of bytes received. | By | Sum(Int) |
  • device
| | **system.network.io.transmit** | The number of bytes transmitted. | By | Sum(Int) |
  • device
| +| **system.network.packets** | The number of packets transferred. (Deprecated) | {packets} | Sum(Int) |
  • device
  • direction
| | **system.network.packets.receive** | The number of packets received. | {packets} | Sum(Int) |
  • device
| | **system.network.packets.transmit** | The number of packets transmitted. | {packets} | Sum(Int) |
  • device
| @@ -32,5 +36,6 @@ metrics: | Name | Description | Values | | ---- | ----------- | ------ | | device | Name of the network interface. | | +| direction | Direction of flow of bytes/operations (receive or transmit). | receive, transmit | | protocol | Network protocol, e.g. TCP or UDP. | tcp | | state | State of the network connection. | | diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go index 28128ffdd1c4..ef38b3e7fa11 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go @@ -19,12 +19,16 @@ type MetricSettings struct { // MetricsSettings provides settings for hostmetricsreceiver/network metrics. type MetricsSettings struct { SystemNetworkConnections MetricSettings `mapstructure:"system.network.connections"` + SystemNetworkDropped MetricSettings `mapstructure:"system.network.dropped"` SystemNetworkDroppedReceive MetricSettings `mapstructure:"system.network.dropped.receive"` SystemNetworkDroppedTransmit MetricSettings `mapstructure:"system.network.dropped.transmit"` + SystemNetworkErrors MetricSettings `mapstructure:"system.network.errors"` SystemNetworkErrorsReceive MetricSettings `mapstructure:"system.network.errors.receive"` SystemNetworkErrorsTransmit MetricSettings `mapstructure:"system.network.errors.transmit"` + SystemNetworkIo MetricSettings `mapstructure:"system.network.io"` SystemNetworkIoReceive MetricSettings `mapstructure:"system.network.io.receive"` SystemNetworkIoTransmit MetricSettings `mapstructure:"system.network.io.transmit"` + SystemNetworkPackets MetricSettings `mapstructure:"system.network.packets"` SystemNetworkPacketsReceive MetricSettings `mapstructure:"system.network.packets.receive"` SystemNetworkPacketsTransmit MetricSettings `mapstructure:"system.network.packets.transmit"` } @@ -34,24 +38,36 @@ func DefaultMetricsSettings() MetricsSettings { SystemNetworkConnections: MetricSettings{ Enabled: true, }, + SystemNetworkDropped: MetricSettings{ + Enabled: true, + }, SystemNetworkDroppedReceive: MetricSettings{ Enabled: true, }, SystemNetworkDroppedTransmit: MetricSettings{ Enabled: true, }, + SystemNetworkErrors: MetricSettings{ + Enabled: true, + }, SystemNetworkErrorsReceive: MetricSettings{ Enabled: true, }, SystemNetworkErrorsTransmit: MetricSettings{ Enabled: true, }, + SystemNetworkIo: MetricSettings{ + Enabled: true, + }, SystemNetworkIoReceive: MetricSettings{ Enabled: true, }, SystemNetworkIoTransmit: MetricSettings{ Enabled: true, }, + SystemNetworkPackets: MetricSettings{ + Enabled: true, + }, SystemNetworkPacketsReceive: MetricSettings{ Enabled: true, }, @@ -61,6 +77,32 @@ func DefaultMetricsSettings() MetricsSettings { } } +// AttributeDirection specifies the a value direction attribute. +type AttributeDirection int + +const ( + _ AttributeDirection = iota + AttributeDirectionReceive + AttributeDirectionTransmit +) + +// String returns the string representation of the AttributeDirection. +func (av AttributeDirection) String() string { + switch av { + case AttributeDirectionReceive: + return "receive" + case AttributeDirectionTransmit: + return "transmit" + } + return "" +} + +// MapAttributeDirection is a helper map of string to AttributeDirection attribute value. +var MapAttributeDirection = map[string]AttributeDirection{ + "receive": AttributeDirectionReceive, + "transmit": AttributeDirectionTransmit, +} + // AttributeProtocol specifies the a value protocol attribute. type AttributeProtocol int @@ -137,6 +179,60 @@ func newMetricSystemNetworkConnections(settings MetricSettings) metricSystemNetw return m } +type metricSystemNetworkDropped struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.dropped metric with initial data. +func (m *metricSystemNetworkDropped) init() { + m.data.SetName("system.network.dropped") + m.data.SetDescription("The number of packets dropped. (Deprecated)") + m.data.SetUnit("{packets}") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkDropped) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) + dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkDropped) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkDropped) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkDropped(settings MetricSettings) metricSystemNetworkDropped { + m := metricSystemNetworkDropped{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricSystemNetworkDroppedReceive struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. @@ -243,6 +339,60 @@ func newMetricSystemNetworkDroppedTransmit(settings MetricSettings) metricSystem return m } +type metricSystemNetworkErrors struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.errors metric with initial data. +func (m *metricSystemNetworkErrors) init() { + m.data.SetName("system.network.errors") + m.data.SetDescription("The number of errors encountered. (Deprecated)") + m.data.SetUnit("{errors}") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkErrors) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) + dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkErrors) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkErrors) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkErrors(settings MetricSettings) metricSystemNetworkErrors { + m := metricSystemNetworkErrors{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricSystemNetworkErrorsReceive struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. @@ -349,6 +499,60 @@ func newMetricSystemNetworkErrorsTransmit(settings MetricSettings) metricSystemN return m } +type metricSystemNetworkIo struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.io metric with initial data. +func (m *metricSystemNetworkIo) init() { + m.data.SetName("system.network.io") + m.data.SetDescription("The number of bytes transmitted and received. (Deprecated)") + m.data.SetUnit("By") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkIo) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) + dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkIo) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkIo) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkIo(settings MetricSettings) metricSystemNetworkIo { + m := metricSystemNetworkIo{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricSystemNetworkIoReceive struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. @@ -455,6 +659,60 @@ func newMetricSystemNetworkIoTransmit(settings MetricSettings) metricSystemNetwo return m } +type metricSystemNetworkPackets struct { + data pmetric.Metric // data buffer for generated metric. + settings MetricSettings // metric settings provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills system.network.packets metric with initial data. +func (m *metricSystemNetworkPackets) init() { + m.data.SetName("system.network.packets") + m.data.SetDescription("The number of packets transferred. (Deprecated)") + m.data.SetUnit("{packets}") + m.data.SetDataType(pmetric.MetricDataTypeSum) + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSystemNetworkPackets) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().Insert("device", pcommon.NewValueString(deviceAttributeValue)) + dp.Attributes().Insert("direction", pcommon.NewValueString(directionAttributeValue)) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemNetworkPackets) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSystemNetworkPackets) emit(metrics pmetric.MetricSlice) { + if m.settings.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemNetworkPackets(settings MetricSettings) metricSystemNetworkPackets { + m := metricSystemNetworkPackets{settings: settings} + if settings.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricSystemNetworkPacketsReceive struct { data pmetric.Metric // data buffer for generated metric. settings MetricSettings // metric settings provided by user. @@ -570,12 +828,16 @@ type MetricsBuilder struct { metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. buildInfo component.BuildInfo // contains version information metricSystemNetworkConnections metricSystemNetworkConnections + metricSystemNetworkDropped metricSystemNetworkDropped metricSystemNetworkDroppedReceive metricSystemNetworkDroppedReceive metricSystemNetworkDroppedTransmit metricSystemNetworkDroppedTransmit + metricSystemNetworkErrors metricSystemNetworkErrors metricSystemNetworkErrorsReceive metricSystemNetworkErrorsReceive metricSystemNetworkErrorsTransmit metricSystemNetworkErrorsTransmit + metricSystemNetworkIo metricSystemNetworkIo metricSystemNetworkIoReceive metricSystemNetworkIoReceive metricSystemNetworkIoTransmit metricSystemNetworkIoTransmit + metricSystemNetworkPackets metricSystemNetworkPackets metricSystemNetworkPacketsReceive metricSystemNetworkPacketsReceive metricSystemNetworkPacketsTransmit metricSystemNetworkPacketsTransmit } @@ -596,12 +858,16 @@ func NewMetricsBuilder(settings MetricsSettings, buildInfo component.BuildInfo, metricsBuffer: pmetric.NewMetrics(), buildInfo: buildInfo, metricSystemNetworkConnections: newMetricSystemNetworkConnections(settings.SystemNetworkConnections), + metricSystemNetworkDropped: newMetricSystemNetworkDropped(settings.SystemNetworkDropped), metricSystemNetworkDroppedReceive: newMetricSystemNetworkDroppedReceive(settings.SystemNetworkDroppedReceive), metricSystemNetworkDroppedTransmit: newMetricSystemNetworkDroppedTransmit(settings.SystemNetworkDroppedTransmit), + metricSystemNetworkErrors: newMetricSystemNetworkErrors(settings.SystemNetworkErrors), metricSystemNetworkErrorsReceive: newMetricSystemNetworkErrorsReceive(settings.SystemNetworkErrorsReceive), metricSystemNetworkErrorsTransmit: newMetricSystemNetworkErrorsTransmit(settings.SystemNetworkErrorsTransmit), + metricSystemNetworkIo: newMetricSystemNetworkIo(settings.SystemNetworkIo), metricSystemNetworkIoReceive: newMetricSystemNetworkIoReceive(settings.SystemNetworkIoReceive), metricSystemNetworkIoTransmit: newMetricSystemNetworkIoTransmit(settings.SystemNetworkIoTransmit), + metricSystemNetworkPackets: newMetricSystemNetworkPackets(settings.SystemNetworkPackets), metricSystemNetworkPacketsReceive: newMetricSystemNetworkPacketsReceive(settings.SystemNetworkPacketsReceive), metricSystemNetworkPacketsTransmit: newMetricSystemNetworkPacketsTransmit(settings.SystemNetworkPacketsTransmit), } @@ -658,12 +924,16 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemNetworkConnections.emit(ils.Metrics()) + mb.metricSystemNetworkDropped.emit(ils.Metrics()) mb.metricSystemNetworkDroppedReceive.emit(ils.Metrics()) mb.metricSystemNetworkDroppedTransmit.emit(ils.Metrics()) + mb.metricSystemNetworkErrors.emit(ils.Metrics()) mb.metricSystemNetworkErrorsReceive.emit(ils.Metrics()) mb.metricSystemNetworkErrorsTransmit.emit(ils.Metrics()) + mb.metricSystemNetworkIo.emit(ils.Metrics()) mb.metricSystemNetworkIoReceive.emit(ils.Metrics()) mb.metricSystemNetworkIoTransmit.emit(ils.Metrics()) + mb.metricSystemNetworkPackets.emit(ils.Metrics()) mb.metricSystemNetworkPacketsReceive.emit(ils.Metrics()) mb.metricSystemNetworkPacketsTransmit.emit(ils.Metrics()) for _, op := range rmo { @@ -690,6 +960,11 @@ func (mb *MetricsBuilder) RecordSystemNetworkConnectionsDataPoint(ts pcommon.Tim mb.metricSystemNetworkConnections.recordDataPoint(mb.startTime, ts, val, protocolAttributeValue.String(), stateAttributeValue) } +// RecordSystemNetworkDroppedDataPoint adds a data point to system.network.dropped metric. +func (mb *MetricsBuilder) RecordSystemNetworkDroppedDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { + mb.metricSystemNetworkDropped.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +} + // RecordSystemNetworkDroppedReceiveDataPoint adds a data point to system.network.dropped.receive metric. func (mb *MetricsBuilder) RecordSystemNetworkDroppedReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { mb.metricSystemNetworkDroppedReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) @@ -700,6 +975,11 @@ func (mb *MetricsBuilder) RecordSystemNetworkDroppedTransmitDataPoint(ts pcommon mb.metricSystemNetworkDroppedTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } +// RecordSystemNetworkErrorsDataPoint adds a data point to system.network.errors metric. +func (mb *MetricsBuilder) RecordSystemNetworkErrorsDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { + mb.metricSystemNetworkErrors.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +} + // RecordSystemNetworkErrorsReceiveDataPoint adds a data point to system.network.errors.receive metric. func (mb *MetricsBuilder) RecordSystemNetworkErrorsReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { mb.metricSystemNetworkErrorsReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) @@ -710,6 +990,11 @@ func (mb *MetricsBuilder) RecordSystemNetworkErrorsTransmitDataPoint(ts pcommon. mb.metricSystemNetworkErrorsTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } +// RecordSystemNetworkIoDataPoint adds a data point to system.network.io metric. +func (mb *MetricsBuilder) RecordSystemNetworkIoDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { + mb.metricSystemNetworkIo.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +} + // RecordSystemNetworkIoReceiveDataPoint adds a data point to system.network.io.receive metric. func (mb *MetricsBuilder) RecordSystemNetworkIoReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { mb.metricSystemNetworkIoReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) @@ -720,6 +1005,11 @@ func (mb *MetricsBuilder) RecordSystemNetworkIoTransmitDataPoint(ts pcommon.Time mb.metricSystemNetworkIoTransmit.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) } +// RecordSystemNetworkPacketsDataPoint adds a data point to system.network.packets metric. +func (mb *MetricsBuilder) RecordSystemNetworkPacketsDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string, directionAttributeValue AttributeDirection) { + mb.metricSystemNetworkPackets.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue, directionAttributeValue.String()) +} + // RecordSystemNetworkPacketsReceiveDataPoint adds a data point to system.network.packets.receive metric. func (mb *MetricsBuilder) RecordSystemNetworkPacketsReceiveDataPoint(ts pcommon.Timestamp, val int64, deviceAttributeValue string) { mb.metricSystemNetworkPacketsReceive.recordDataPoint(mb.startTime, ts, val, deviceAttributeValue) diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml index 10f1e1cffa8c..d1340e893a12 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml @@ -6,6 +6,10 @@ attributes: device: description: Name of the network interface. + direction: + description: Direction of flow of bytes/operations (receive or transmit). + enum: [receive, transmit] + protocol: description: Network protocol, e.g. TCP or UDP. enum: [tcp] @@ -14,6 +18,16 @@ attributes: description: State of the network connection. metrics: + system.network.packets: + enabled: true + description: The number of packets transferred. (Deprecated) + unit: "{packets}" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device, direction] + system.network.packets.transmit: enabled: true description: The number of packets transmitted. @@ -34,6 +48,16 @@ metrics: monotonic: true attributes: [device] + system.network.dropped: + enabled: true + description: The number of packets dropped. (Deprecated) + unit: "{packets}" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device, direction] + system.network.dropped.transmit: enabled: true description: The number of packets dropped on transmit. @@ -54,6 +78,16 @@ metrics: monotonic: true attributes: [device] + system.network.errors: + enabled: true + description: The number of errors encountered. (Deprecated) + unit: "{errors}" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device, direction] + system.network.errors.transmit: enabled: true description: The number of errors encountered on transmit. @@ -74,6 +108,16 @@ metrics: monotonic: true attributes: [device] + system.network.io: + enabled: true + description: The number of bytes transmitted and received. (Deprecated) + unit: "By" + sum: + value_type: int + aggregation: cumulative + monotonic: true + attributes: [device, direction] + system.network.io.transmit: enabled: true description: The number of bytes transmitted. diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go index e832937f07c3..1fa47582c9eb 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/scrapererror" + "go.opentelemetry.io/collector/service/featuregate" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata" @@ -33,6 +34,8 @@ import ( const ( networkMetricsLen = 4 connectionsMetricsLen = 1 + // ID for a temporary feature gate" + removeDirectionAttributeFeatureGateID = "receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics" ) // scraper for Network Metrics @@ -50,12 +53,35 @@ type scraper struct { connections func(string) ([]net.ConnectionStat, error) } +var removeDirectionAttributeFeatureGate = featuregate.Gate{ + ID: removeDirectionAttributeFeatureGateID, + Enabled: false, + Description: "Some network metrics reported by the hostmetricsreceiver are transitioning from being reported " + + "with a direction attribute to being reported with the direction included in the metric name to adhere to the " + + "OpenTelemetry specification. You can control whether the hostmetricsreceiver reports metrics with a direction " + + "attribute using the " + removeDirectionAttributeFeatureGateID + " feature gate. For more details, see: " + + "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md#feature-gate-configurations", +} + +func init() { + featuregate.GetRegistry().MustRegister(removeDirectionAttributeFeatureGate) +} + // newNetworkScraper creates a set of Network related metrics func newNetworkScraper(_ context.Context, settings component.ReceiverCreateSettings, cfg *Config) (*scraper, error) { scraper := &scraper{settings: settings, config: cfg, bootTime: host.BootTime, ioCounters: net.IOCounters, connections: net.Connections} var err error + if featuregate.GetRegistry().IsEnabled(removeDirectionAttributeFeatureGateID) { + settings.Logger.Info("The " + removeDirectionAttributeFeatureGateID + " featre gate is enabled. This " + + "otel collector will report metrics without a direction attribute, which is good for future support") + } else { + settings.Logger.Info("WARNING - Breaking Change: " + removeDirectionAttributeFeatureGate.Description) + settings.Logger.Info("The feature gate " + removeDirectionAttributeFeatureGateID + " is disabled. This " + + "otel collector will report metrics with a direction attribute, be aware this will not be supported in the future") + } + if len(cfg.Include.Interfaces) > 0 { scraper.includeFS, err = filterset.CreateFilterSet(cfg.Include.Interfaces, &cfg.Include.Config) if err != nil { @@ -124,29 +150,49 @@ func (s *scraper) recordNetworkCounterMetrics() error { func (s *scraper) recordNetworkPacketsMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkPacketsTransmitDataPoint(now, int64(ioCounters.PacketsSent), ioCounters.Name) - s.mb.RecordSystemNetworkPacketsReceiveDataPoint(now, int64(ioCounters.PacketsRecv), ioCounters.Name) + if featuregate.GetRegistry().IsEnabled(removeDirectionAttributeFeatureGateID) { + s.mb.RecordSystemNetworkPacketsTransmitDataPoint(now, int64(ioCounters.PacketsSent), ioCounters.Name) + s.mb.RecordSystemNetworkPacketsReceiveDataPoint(now, int64(ioCounters.PacketsRecv), ioCounters.Name) + } else { + s.mb.RecordSystemNetworkPacketsDataPoint(now, int64(ioCounters.PacketsSent), ioCounters.Name, metadata.AttributeDirectionTransmit) + s.mb.RecordSystemNetworkPacketsDataPoint(now, int64(ioCounters.PacketsRecv), ioCounters.Name, metadata.AttributeDirectionReceive) + } } } func (s *scraper) recordNetworkDroppedPacketsMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkDroppedTransmitDataPoint(now, int64(ioCounters.Dropout), ioCounters.Name) - s.mb.RecordSystemNetworkDroppedReceiveDataPoint(now, int64(ioCounters.Dropin), ioCounters.Name) + if featuregate.GetRegistry().IsEnabled(removeDirectionAttributeFeatureGateID) { + s.mb.RecordSystemNetworkDroppedTransmitDataPoint(now, int64(ioCounters.Dropout), ioCounters.Name) + s.mb.RecordSystemNetworkDroppedReceiveDataPoint(now, int64(ioCounters.Dropin), ioCounters.Name) + } else { + s.mb.RecordSystemNetworkDroppedDataPoint(now, int64(ioCounters.Dropout), ioCounters.Name, metadata.AttributeDirectionTransmit) + s.mb.RecordSystemNetworkDroppedDataPoint(now, int64(ioCounters.Dropin), ioCounters.Name, metadata.AttributeDirectionReceive) + } } } func (s *scraper) recordNetworkErrorPacketsMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkErrorsTransmitDataPoint(now, int64(ioCounters.Errout), ioCounters.Name) - s.mb.RecordSystemNetworkErrorsReceiveDataPoint(now, int64(ioCounters.Errin), ioCounters.Name) + if featuregate.GetRegistry().IsEnabled(removeDirectionAttributeFeatureGateID) { + s.mb.RecordSystemNetworkErrorsTransmitDataPoint(now, int64(ioCounters.Errout), ioCounters.Name) + s.mb.RecordSystemNetworkErrorsReceiveDataPoint(now, int64(ioCounters.Errin), ioCounters.Name) + } else { + s.mb.RecordSystemNetworkErrorsDataPoint(now, int64(ioCounters.Errout), ioCounters.Name, metadata.AttributeDirectionTransmit) + s.mb.RecordSystemNetworkErrorsDataPoint(now, int64(ioCounters.Errin), ioCounters.Name, metadata.AttributeDirectionReceive) + } } } func (s *scraper) recordNetworkIOMetric(now pcommon.Timestamp, ioCountersSlice []net.IOCountersStat) { for _, ioCounters := range ioCountersSlice { - s.mb.RecordSystemNetworkIoTransmitDataPoint(now, int64(ioCounters.BytesSent), ioCounters.Name) - s.mb.RecordSystemNetworkIoReceiveDataPoint(now, int64(ioCounters.BytesRecv), ioCounters.Name) + if featuregate.GetRegistry().IsEnabled(removeDirectionAttributeFeatureGateID) { + s.mb.RecordSystemNetworkIoTransmitDataPoint(now, int64(ioCounters.BytesSent), ioCounters.Name) + s.mb.RecordSystemNetworkIoReceiveDataPoint(now, int64(ioCounters.BytesRecv), ioCounters.Name) + } else { + s.mb.RecordSystemNetworkIoDataPoint(now, int64(ioCounters.BytesSent), ioCounters.Name, metadata.AttributeDirectionTransmit) + s.mb.RecordSystemNetworkIoDataPoint(now, int64(ioCounters.BytesRecv), ioCounters.Name, metadata.AttributeDirectionReceive) + } } } diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go index db6fe354bf65..9b22d77b937b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go @@ -26,6 +26,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/scrapererror" + "go.opentelemetry.io/collector/service/featuregate" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" @@ -34,17 +35,18 @@ import ( func TestScrape(t *testing.T) { type testCase struct { - name string - config Config - bootTimeFunc func() (uint64, error) - ioCountersFunc func(bool) ([]net.IOCountersStat, error) - connectionsFunc func(string) ([]net.ConnectionStat, error) - expectNetworkMetrics bool - expectedStartTime pcommon.Timestamp - newErrRegex string - initializationErr string - expectedErr string - expectedErrCount int + name string + config Config + bootTimeFunc func() (uint64, error) + ioCountersFunc func(bool) ([]net.IOCountersStat, error) + connectionsFunc func(string) ([]net.ConnectionStat, error) + expectNetworkMetrics bool + expectedStartTime pcommon.Timestamp + newErrRegex string + initializationErr string + expectedErr string + expectedErrCount int + removeDirectionAttributeFeatureGateEnabled bool } testCases := []testCase{ @@ -55,6 +57,14 @@ func TestScrape(t *testing.T) { }, expectNetworkMetrics: true, }, + { + name: "Standard with direction removed", + config: Config{ + Metrics: metadata.DefaultMetricsSettings(), + }, + expectNetworkMetrics: true, + removeDirectionAttributeFeatureGateEnabled: true, + }, { name: "Validate Start Time", config: Config{ @@ -109,6 +119,7 @@ func TestScrape(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { + featuregate.GetRegistry().Apply(map[string]bool{removeDirectionAttributeFeatureGateID: test.removeDirectionAttributeFeatureGateEnabled}) scraper, err := newNetworkScraper(context.Background(), componenttest.NewNopReceiverCreateSettings(), &test.config) if test.newErrRegex != "" { require.Error(t, err) @@ -152,7 +163,11 @@ func TestScrape(t *testing.T) { expectedMetricCount := 1 if test.expectNetworkMetrics { - expectedMetricCount += 8 + if test.removeDirectionAttributeFeatureGateEnabled { + expectedMetricCount += 8 + } else { + expectedMetricCount += 4 + } } assert.Equal(t, expectedMetricCount, md.MetricCount()) @@ -160,14 +175,21 @@ func TestScrape(t *testing.T) { idx := 0 assertNetworkConnectionsMetricValid(t, metrics.At(idx)) if test.expectNetworkMetrics { - assertNetworkIOMetricValid(t, metrics.At(idx+1), "system.network.dropped.receive", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+2), "system.network.dropped.transmit", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+3), "system.network.errors.receive", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+4), "system.network.errors.transmit", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+5), "system.network.io.receive", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+6), "system.network.io.transmit", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+7), "system.network.packets.receive", test.expectedStartTime) - assertNetworkIOMetricValid(t, metrics.At(idx+8), "system.network.packets.transmit", test.expectedStartTime) + if test.removeDirectionAttributeFeatureGateEnabled { + assertNetworkIOMetricValid(t, metrics.At(idx+1), "system.network.dropped.receive", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+2), "system.network.dropped.transmit", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+3), "system.network.errors.receive", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+4), "system.network.errors.transmit", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+5), "system.network.io.receive", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+6), "system.network.io.transmit", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+7), "system.network.packets.receive", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+8), "system.network.packets.transmit", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + } else { + assertNetworkIOMetricValid(t, metrics.At(idx+1), "system.network.dropped", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+2), "system.network.errors", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+3), "system.network.io", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + assertNetworkIOMetricValid(t, metrics.At(idx+4), "system.network.packets", test.expectedStartTime, test.removeDirectionAttributeFeatureGateEnabled) + } internal.AssertSameTimeStampForMetrics(t, metrics, 1, 5) idx += 4 } @@ -177,13 +199,20 @@ func TestScrape(t *testing.T) { } } -func assertNetworkIOMetricValid(t *testing.T, metric pmetric.Metric, expectedName string, startTime pcommon.Timestamp) { +func assertNetworkIOMetricValid(t *testing.T, metric pmetric.Metric, expectedName string, startTime pcommon.Timestamp, expectDirectionRemoved bool) { assert.Equal(t, expectedName, metric.Name()) if startTime != 0 { internal.AssertSumMetricStartTimeEquals(t, metric, startTime) } - assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 1) + if expectDirectionRemoved { + assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 1) + } else { + assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 2) + } internal.AssertSumMetricHasAttribute(t, metric, 0, "device") + if !expectDirectionRemoved { + internal.AssertSumMetricHasAttribute(t, metric, 0, "direction") + } } func assertNetworkConnectionsMetricValid(t *testing.T, metric pmetric.Metric) { From 850f1d8a01b62b1291e5e12d329ee0b135897e12 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 30 Jun 2022 10:14:37 -0700 Subject: [PATCH 4/4] add comment --- .../internal/scraper/networkscraper/metadata.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml index d1340e893a12..8b5060dbffc5 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/metadata.yaml @@ -28,6 +28,7 @@ metrics: monotonic: true attributes: [device, direction] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.packets.transmit: enabled: true description: The number of packets transmitted. @@ -38,6 +39,7 @@ metrics: monotonic: true attributes: [device] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.packets.receive: enabled: true description: The number of packets received. @@ -58,6 +60,7 @@ metrics: monotonic: true attributes: [device, direction] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.dropped.transmit: enabled: true description: The number of packets dropped on transmit. @@ -68,6 +71,7 @@ metrics: monotonic: true attributes: [device] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.dropped.receive: enabled: true description: The number of packets dropped on receive. @@ -88,6 +92,7 @@ metrics: monotonic: true attributes: [device, direction] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.errors.transmit: enabled: true description: The number of errors encountered on transmit. @@ -98,6 +103,7 @@ metrics: monotonic: true attributes: [device] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.errors.receive: enabled: true description: The number of errors encountered on receive. @@ -118,6 +124,7 @@ metrics: monotonic: true attributes: [device, direction] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.io.transmit: enabled: true description: The number of bytes transmitted. @@ -128,6 +135,7 @@ metrics: monotonic: true attributes: [device] +# produced when receiver.hostmetricsreceiver.removeDirectionAttributeNetworkMetrics feature gate is enabled system.network.io.receive: enabled: true description: The number of bytes received.