Skip to content

Commit 106e2a3

Browse files
authored
[chore](receiver/hostmetricsreceiver) move feature gates for metadata… (#47336)
….yaml Part of [46116](#46116) - add `hostmetrics.process.bootTimeCache`, `hostmetrics.process.onWindowsUseNewGetProcesses` and `receiver.hostmetricsreceiver.UseLinuxMemAvailable` feature gates to `metadata.yaml` - remove manual feature gate initialization - modify references to use feature gates from `metadata.yaml` --------- Signed-off-by: eferreyra <eferreyra@newrelic.com>
1 parent c19f0ed commit 106e2a3

File tree

7 files changed

+55
-33
lines changed

7 files changed

+55
-33
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)
2+
3+
# hostmetrics
4+
5+
## Feature Gates
6+
7+
This component has the following feature gates:
8+
9+
| Feature Gate | Stage | Description | From Version | To Version | Reference |
10+
| ------------ | ----- | ----------- | ------------ | ---------- | --------- |
11+
| `hostmetrics.process.bootTimeCache` | beta | When enabled, all process scrapes will use the boot time value that is cached at the start of the process. | v0.98.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/28849) |
12+
| `receiver.hostmetricsreceiver.UseLinuxMemAvailable` | beta | When enabled, the used value for the system.memory.usage and system.memory.utilization metrics will be based on the Linux kernel's MemAvailable statistic instead of MemFree, Buffers, and Cached. | v0.137.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42221) |
13+
14+
For more information about feature gates, see the [Feature Gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md) documentation.

receiver/hostmetricsreceiver/internal/metadata/generated_feature_gates.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@ package memoryscraper // import "github.com/open-telemetry/opentelemetry-collect
77

88
import (
99
"github.com/shirou/gopsutil/v4/mem"
10-
"go.opentelemetry.io/collector/featuregate"
1110
"go.opentelemetry.io/collector/pdata/pcommon"
1211

12+
hostmetricsmetadata "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata"
1313
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/precision"
1414
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata"
1515
)
1616

17-
var useMemAvailable = featuregate.GlobalRegistry().MustRegister(
18-
"receiver.hostmetricsreceiver.UseLinuxMemAvailable",
19-
featuregate.StageBeta,
20-
featuregate.WithRegisterFromVersion("v0.137.0"),
21-
featuregate.WithRegisterDescription("When enabled, the used value for the system.memory.usage and system.memory.utilization metrics will be based on the Linux kernel’s MemAvailable statistic instead of MemFree, Buffers, and Cached."),
22-
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42221"),
23-
)
24-
2517
func (s *memoryScraper) recordMemoryUsageMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) {
2618
// TODO: rely on memInfo.Used value once https://github.com/shirou/gopsutil/pull/1882 is released
2719
// gopsutil formula: https://github.com/shirou/gopsutil/pull/1882/files#diff-5af8322731595fb792b48f3c38f31ddb24f596cf11a74a9c37b19734597baef6R321
28-
if useMemAvailable.IsEnabled() {
20+
if hostmetricsmetadata.ReceiverHostmetricsreceiverUseLinuxMemAvailableFeatureGate.IsEnabled() {
2921
s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Total-memInfo.Available), metadata.AttributeStateUsed)
3022
} else {
3123
// gopsutil legacy "Used" memory formula = Total - Free - Buffers - Cache
@@ -45,7 +37,7 @@ func (s *memoryScraper) recordMemoryLinuxSharedMetric(now pcommon.Timestamp, mem
4537
func (s *memoryScraper) recordMemoryUtilizationMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) {
4638
// TODO: rely on memInfo.Used value once https://github.com/shirou/gopsutil/pull/1882 is released
4739
// gopsutil formula: https://github.com/shirou/gopsutil/pull/1882/files#diff-5af8322731595fb792b48f3c38f31ddb24f596cf11a74a9c37b19734597baef6R321
48-
if useMemAvailable.IsEnabled() {
40+
if hostmetricsmetadata.ReceiverHostmetricsreceiverUseLinuxMemAvailableFeatureGate.IsEnabled() {
4941
s.mb.RecordSystemMemoryUtilizationDataPoint(now, precision.Ratio(memInfo.Total-memInfo.Available, memInfo.Total), metadata.AttributeStateUsed)
5042
} else {
5143
// gopsutil legacy "Used" memory formula = Total - Free - Buffers - Cache

receiver/hostmetricsreceiver/internal/scraper/processscraper/factory.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,11 @@ import (
99
"runtime"
1010

1111
"go.opentelemetry.io/collector/component"
12-
"go.opentelemetry.io/collector/featuregate"
1312
"go.opentelemetry.io/collector/scraper"
1413

1514
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata"
1615
)
1716

18-
var (
19-
bootTimeCacheFeaturegateID = "hostmetrics.process.bootTimeCache"
20-
bootTimeCacheFeaturegate = featuregate.GlobalRegistry().MustRegister(
21-
bootTimeCacheFeaturegateID,
22-
featuregate.StageBeta,
23-
featuregate.WithRegisterDescription("When enabled, all process scrapes will use the boot time value that is cached at the start of the process."),
24-
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/28849"),
25-
featuregate.WithRegisterFromVersion("v0.98.0"),
26-
)
27-
)
28-
2917
// NewFactory for Process scraper.
3018
func NewFactory() scraper.Factory {
3119
return scraper.NewFactory(metadata.Type, createDefaultConfig, scraper.WithMetrics(createMetricsScraper, metadata.MetricsStability))

receiver/hostmetricsreceiver/internal/scraper/processscraper/get_process_handles_windows.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,9 @@ import (
1111
"unsafe"
1212

1313
"github.com/shirou/gopsutil/v4/process"
14-
"go.opentelemetry.io/collector/featuregate"
1514
"golang.org/x/sys/windows"
1615
)
1716

18-
var _ = featuregate.GlobalRegistry().MustRegister(
19-
"hostmetrics.process.onWindowsUseNewGetProcesses",
20-
featuregate.StageStable,
21-
featuregate.WithRegisterDescription("If disabled, the scraper will use the legacy implementation to retrieve process handles."),
22-
featuregate.WithRegisterFromVersion("v0.123.0"),
23-
featuregate.WithRegisterToVersion("v0.127.0"),
24-
)
25-
2617
func getGopsutilProcessHandles(ctx context.Context) (processHandles, error) {
2718
snap, err := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0)
2819
if err != nil {

receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"go.opentelemetry.io/collector/scraper/scrapererror"
2222

2323
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset"
24+
hostmetricsmetadata "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata"
2425
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata"
2526
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/ucal"
2627
)
@@ -106,7 +107,7 @@ func (s *processScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
106107
// cached boot time value for use in the current scrape. This functionally
107108
// replicates the previous functionality in all but the most extreme
108109
// cases of boot time changing in the middle of a scrape.
109-
if !bootTimeCacheFeaturegate.IsEnabled() {
110+
if !hostmetricsmetadata.HostmetricsProcessBootTimeCacheFeatureGate.IsEnabled() {
110111
host.EnableBootTimeCache(false)
111112
_, err := host.BootTimeWithContext(ctx)
112113
if err != nil {

receiver/hostmetricsreceiver/metadata.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,18 @@ status:
1414
distributions: [core, contrib, k8s]
1515
codeowners:
1616
active: [dmitryax, braydonk, rogercoll]
17+
18+
feature_gates:
19+
- id: hostmetrics.process.bootTimeCache
20+
description: When enabled, all process scrapes will use the boot time value that is cached at the start of the process.
21+
stage: beta
22+
from_version: "v0.98.0"
23+
reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/28849
24+
- id: receiver.hostmetricsreceiver.UseLinuxMemAvailable
25+
description: When enabled, the used value for the system.memory.usage and system.memory.utilization metrics will be based on the Linux kernel's MemAvailable statistic instead of MemFree, Buffers, and Cached.
26+
stage: beta
27+
from_version: "v0.137.0"
28+
reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42221
29+
1730
tests:
1831
config:

0 commit comments

Comments
 (0)