Skip to content

Commit

Permalink
[receiver/hostmetrics] remove direction from process scraper (#12091)
Browse files Browse the repository at this point in the history
* [receiver/hostmetrics] remove direction from process scraper

Fix #11819

* add changelog

* Update unreleased/hostmetrics-rm-direction-process.yaml

Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com>
  • Loading branch information
Alex Boten and djaglowski authored Jul 5, 2022
1 parent d6c57ab commit 6722d9b
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 37 deletions.
32 changes: 32 additions & 0 deletions receiver/hostmetricsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,38 @@ service:
- More information:
- https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/11815
- https://github.com/open-telemetry/opentelemetry-specification/pull/2617
- `receiver.hostmetricsreceiver.removeDirectionAttributeProcessMetrics`
- Description
- Some process 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
- `process.disk.io` will become:
- `process.disk.io.read`
- `process.disk.io.write`
- 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.hostmetricsreceiver.removeDirectionAttributeProcessMetrics
- Start the otelcol with the feature gate disabled:
- otelcol {other_arguments} --feature-gates=-receiver.hostmetricsreceiver.removeDirectionAttributeProcessMetrics
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ These are the metrics available for this scraper.
| ---- | ----------- | ---- | ---- | ---------- |
| **process.cpu.time** | Total CPU seconds broken down by different states. | s | Sum(Double) | <ul> <li>state</li> </ul> |
| **process.disk.io** | Disk bytes transferred. | By | Sum(Int) | <ul> <li>direction</li> </ul> |
| **process.disk.io.read** | Disk bytes read. | By | Sum(Int) | <ul> </ul> |
| **process.disk.io.write** | Disk bytes written. | By | Sum(Int) | <ul> </ul> |
| **process.memory.physical_usage** | The amount of physical memory in use. | By | Sum(Int) | <ul> </ul> |
| **process.memory.virtual_usage** | Virtual memory size. | By | Sum(Int) | <ul> </ul> |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.opentelemetry.io/collector/service/featuregate"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata"
Expand All @@ -31,8 +32,24 @@ import (
const (
// TypeStr the value of "type" key in configuration.
TypeStr = "process"
// ID for a temporary feature gate"
removeDirectionAttributeFeatureGateID = "receiver.hostmetricsreceiver.removeDirectionAttributeProcessMetrics"
)

var removeDirectionAttributeFeatureGate = featuregate.Gate{
ID: removeDirectionAttributeFeatureGateID,
Enabled: false,
Description: "Some process 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)
}

// Factory is the Factory for scraper.
type Factory struct {
}
Expand All @@ -58,10 +75,22 @@ func (f *Factory) CreateMetricsScraper(
if err != nil {
return nil, err
}
logFeatureGateMessage(settings)

return scraperhelper.NewScraper(
TypeStr,
s.scrape,
scraperhelper.WithStart(s.start),
)
}

func logFeatureGateMessage(settings component.ReceiverCreateSettings) {
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")
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,23 @@ metrics:
aggregation: cumulative
monotonic: true
attributes: [direction]

# produced when receiver.hostmetricsreceiver.removeDirectionAttributeProcessMetrics feature gate is enabled
process.disk.io.read:
enabled: true
description: Disk bytes read.
unit: By
sum:
value_type: int
aggregation: cumulative
monotonic: true

# produced when receiver.hostmetricsreceiver.removeDirectionAttributeProcessMetrics feature gate is enabled
process.disk.io.write:
enabled: true
description: Disk bytes written.
unit: By
sum:
value_type: int
aggregation: cumulative
monotonic: true
Original file line number Diff line number Diff line change
Expand Up @@ -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/processscraper/internal/metadata"
Expand Down Expand Up @@ -200,7 +201,12 @@ func (s *scraper) scrapeAndAppendDiskIOMetric(now pcommon.Timestamp, handle proc
return err
}

s.mb.RecordProcessDiskIoDataPoint(now, int64(io.ReadBytes), metadata.AttributeDirectionRead)
s.mb.RecordProcessDiskIoDataPoint(now, int64(io.WriteBytes), metadata.AttributeDirectionWrite)
if featuregate.GetRegistry().IsEnabled(removeDirectionAttributeFeatureGateID) {
s.mb.RecordProcessDiskIoReadDataPoint(now, int64(io.ReadBytes))
s.mb.RecordProcessDiskIoWriteDataPoint(now, int64(io.WriteBytes))
} else {
s.mb.RecordProcessDiskIoDataPoint(now, int64(io.ReadBytes), metadata.AttributeDirectionRead)
s.mb.RecordProcessDiskIoDataPoint(now, int64(io.WriteBytes), metadata.AttributeDirectionWrite)
}
return nil
}
Loading

0 comments on commit 6722d9b

Please sign in to comment.