Skip to content

Commit 219011b

Browse files
authored
[receiver/hostmetrics]: change uptime scraper to system scraper (#36123)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR makes some changes that I had hoped to suggest on #35954, however I was unable to make my comment in time before the PR was merged. The changes this PR makes are: * The `uptime` scraper is changed to be named `system` * The scraper is registered using the scraper name when adding to the scrapercontroller <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Amends the fix to #31627 (following a comment I made on #35932) <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation The documentation that was added for the `uptime` scraper was renamed accordingly, and the description adjusted. <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 740d9aa commit 219011b

20 files changed

+65
-36
lines changed

.chloggen/add-hostmetric-system-uptime.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ change_type: enhancement
55
component: hostmetricsreceiver
66

77
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8-
note: Add an uptime scraper in the hostmetrics receiver
8+
note: Add the system.uptime metric in the hostmetrics receiver
99

1010
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
1111
issues: [31627]
1212

1313
# (Optional) One or more lines of additional information to render under the primary note.
1414
# These lines will be padded with 2 spaces and then inserted directly into the document.
1515
# Use pipe (|) for multiline entries.
16-
subtext:
16+
subtext: This metric is provided by the new `system` scraper.
1717

1818
# If your change doesn't affect end users or the exported elements of any package,
1919
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

receiver/hostmetricsreceiver/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!-- end autogenerated section -->
1818

1919
The Host Metrics receiver generates metrics about the host system scraped
20-
from various sources and host entity event as log. This is intended to be
20+
from various sources and host entity event as log. This is intended to be
2121
used when the collector is deployed as an agent.
2222

2323
## Getting Started
@@ -49,7 +49,7 @@ The available scrapers are:
4949
| [paging] | All | Paging/Swap space utilization and I/O metrics |
5050
| [processes] | Linux, Mac | Process count metrics |
5151
| [process] | Linux, Windows, Mac | Per process CPU, Memory, and Disk I/O metrics |
52-
| [uptime] | Linux, Windows, Mac | Uptime metric |
52+
| [system] | Linux, Windows, Mac | Miscellaneous system metrics |
5353

5454
[cpu]: ./internal/scraper/cpuscraper/documentation.md
5555
[disk]: ./internal/scraper/diskscraper/documentation.md
@@ -60,7 +60,7 @@ The available scrapers are:
6060
[paging]: ./internal/scraper/pagingscraper/documentation.md
6161
[processes]: ./internal/scraper/processesscraper/documentation.md
6262
[process]: ./internal/scraper/processscraper/documentation.md
63-
[uptime]: ./internal/scraper/uptimescraper/documentation.md
63+
[system]: ./internal/scraper/systemscraper/documentation.md
6464

6565
### Notes
6666

@@ -172,14 +172,14 @@ service:
172172

173173
Host metrics are collected from the Linux system directories on the filesystem.
174174
You likely want to collect metrics about the host system and not the container.
175-
This is achievable by following these steps:
175+
This is achievable by following these steps:
176176

177177
#### 1. Bind mount the host filesystem
178178

179-
The simplest configuration is to mount the entire host filesystem when running
179+
The simplest configuration is to mount the entire host filesystem when running
180180
the container. e.g. `docker run -v /:/hostfs ...`.
181181

182-
You can also choose which parts of the host filesystem to mount, if you know
182+
You can also choose which parts of the host filesystem to mount, if you know
183183
exactly what you'll need. e.g. `docker run -v /proc:/hostfs/proc`.
184184

185185
#### 2. Configure `root_path`

receiver/hostmetricsreceiver/config_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
2828
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
2929
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
30-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
30+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
3131
)
3232

3333
func TestLoadConfig(t *testing.T) {
@@ -119,8 +119,8 @@ func TestLoadConfig(t *testing.T) {
119119
cfg.SetEnvMap(common.EnvMap{})
120120
return cfg
121121
})(),
122-
uptimescraper.TypeStr: (func() internal.Config {
123-
cfg := (&uptimescraper.Factory{}).CreateDefaultConfig()
122+
systemscraper.TypeStr: (func() internal.Config {
123+
cfg := (&systemscraper.Factory{}).CreateDefaultConfig()
124124
cfg.SetEnvMap(common.EnvMap{})
125125
return cfg
126126
})(),

receiver/hostmetricsreceiver/factory.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
2828
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
2929
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
30-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
30+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
3131
)
3232

3333
const (
@@ -46,7 +46,7 @@ var (
4646
pagingscraper.TypeStr: &pagingscraper.Factory{},
4747
processesscraper.TypeStr: &processesscraper.Factory{},
4848
processscraper.TypeStr: &processscraper.Factory{},
49-
uptimescraper.TypeStr: &uptimescraper.Factory{},
49+
systemscraper.TypeStr: &systemscraper.Factory{},
5050
}
5151
)
5252

receiver/hostmetricsreceiver/hostmetrics_receiver_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
3535
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
3636
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
37-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
37+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
3838
)
3939

4040
var allMetrics = []string{
@@ -82,7 +82,7 @@ var factories = map[string]internal.ScraperFactory{
8282
pagingscraper.TypeStr: &pagingscraper.Factory{},
8383
processesscraper.TypeStr: &processesscraper.Factory{},
8484
processscraper.TypeStr: &processscraper.Factory{},
85-
uptimescraper.TypeStr: &uptimescraper.Factory{},
85+
systemscraper.TypeStr: &systemscraper.Factory{},
8686
}
8787

8888
type testEnv struct {
@@ -404,7 +404,7 @@ func Benchmark_ScrapeUptimeMetrics(b *testing.B) {
404404

405405
cfg := &Config{
406406
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
407-
Scrapers: map[string]internal.Config{uptimescraper.TypeStr: (&uptimescraper.Factory{}).CreateDefaultConfig()},
407+
Scrapers: map[string]internal.Config{systemscraper.TypeStr: (&systemscraper.Factory{}).CreateDefaultConfig()},
408408
}
409409

410410
benchmarkScrapeMetrics(b, cfg)
@@ -444,6 +444,7 @@ func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) {
444444
networkscraper.TypeStr: &networkscraper.Config{},
445445
pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig(),
446446
processesscraper.TypeStr: &processesscraper.Config{},
447+
systemscraper.TypeStr: &systemscraper.Config{},
447448
},
448449
}
449450

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/config.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
4+
package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
55

66
import (
77
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
8-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
8+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
99
)
1010

1111
// Config relating to Uptime Metric Scraper.

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/doc.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
//go:generate mdatagen metadata.yaml
55

6-
package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
6+
package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/documentation.md renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/documentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)
22

3-
# hostmetricsreceiver/uptime
3+
# hostmetricsreceiver/system
44

55
**Parent Component:** hostmetrics
66

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/factory.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
4+
package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
55

66
import (
77
"context"
88
"errors"
99
"runtime"
1010

11+
"go.opentelemetry.io/collector/component"
1112
"go.opentelemetry.io/collector/receiver"
1213
"go.opentelemetry.io/collector/receiver/scraperhelper"
1314

1415
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
15-
hostmeta "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata"
16-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
16+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
1717
)
1818

19-
// This file implements Factory for Uptime scraper.
19+
// This file implements Factory for System scraper.
2020

2121
const (
2222
// TypeStr the value of "type" key in configuration.
23-
TypeStr = "uptime"
23+
TypeStr = "system"
24+
)
25+
26+
var (
27+
// scraperType is the component type used for the built scraper.
28+
scraperType component.Type = component.MustNewType(TypeStr)
2429
)
2530

2631
// Factory is the Factory for scraper.
@@ -47,7 +52,7 @@ func (f *Factory) CreateMetricsScraper(
4752
uptimeScraper := newUptimeScraper(ctx, settings, cfg.(*Config))
4853

4954
return scraperhelper.NewScraper(
50-
hostmeta.Type,
55+
scraperType,
5156
uptimeScraper.scrape,
5257
scraperhelper.WithStart(uptimeScraper.start),
5358
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package systemscraper
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"go.opentelemetry.io/collector/receiver/receivertest"
12+
)
13+
14+
func TestCreateSystemScraper(t *testing.T) {
15+
factory := &Factory{}
16+
cfg := &Config{}
17+
18+
scraper, err := factory.CreateMetricsScraper(context.Background(), receivertest.NewNopSettings(), cfg)
19+
20+
assert.NoError(t, err)
21+
assert.NotNil(t, scraper)
22+
assert.Equal(t, scraperType.String(), scraper.ID().String())
23+
}

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_config.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_config.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_metrics.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_metrics.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/metadata.yaml renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type: hostmetricsreceiver/uptime
1+
type: hostmetricsreceiver/system
22

33
parent: hostmetrics
44

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/package_test.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/package_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package uptimescraper
4+
package systemscraper
55

66
import (
77
"testing"

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
4+
package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
55

66
import (
77
"context"
@@ -14,7 +14,7 @@ import (
1414
"go.opentelemetry.io/collector/pdata/pmetric"
1515
"go.opentelemetry.io/collector/receiver"
1616

17-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
17+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
1818
)
1919

2020
// scraper for Uptime Metrics

receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime_test.go renamed to receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package uptimescraper
4+
package systemscraper
55

66
import (
77
"context"
@@ -14,7 +14,7 @@ import (
1414
"go.opentelemetry.io/collector/pdata/pmetric"
1515
"go.opentelemetry.io/collector/receiver/receivertest"
1616

17-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
17+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
1818
)
1919

2020
func TestScrape(t *testing.T) {

receiver/hostmetricsreceiver/testdata/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ receivers:
2121
include:
2222
names: ["test2", "test3"]
2323
match_type: "regexp"
24-
uptime:
24+
system:
2525

2626
processors:
2727
nop:

0 commit comments

Comments
 (0)