Skip to content

Commit

Permalink
[receiver/hostmetrics]: change uptime scraper to system scraper (open…
Browse files Browse the repository at this point in the history
…-telemetry#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 open-telemetry#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. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Amends the fix to open-telemetry#31627 (following a comment I made on open-telemetry#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.-->
  • Loading branch information
braydonk authored and michael-burt committed Nov 7, 2024
1 parent f29f09b commit 0173f45
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .chloggen/add-hostmetric-system-uptime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ change_type: enhancement
component: hostmetricsreceiver

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

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

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

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
Expand Down
12 changes: 6 additions & 6 deletions receiver/hostmetricsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- end autogenerated section -->

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

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

[cpu]: ./internal/scraper/cpuscraper/documentation.md
[disk]: ./internal/scraper/diskscraper/documentation.md
Expand All @@ -60,7 +60,7 @@ The available scrapers are:
[paging]: ./internal/scraper/pagingscraper/documentation.md
[processes]: ./internal/scraper/processesscraper/documentation.md
[process]: ./internal/scraper/processscraper/documentation.md
[uptime]: ./internal/scraper/uptimescraper/documentation.md
[system]: ./internal/scraper/systemscraper/documentation.md

### Notes

Expand Down Expand Up @@ -172,14 +172,14 @@ service:

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

#### 1. Bind mount the host filesystem

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

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

#### 2. Configure `root_path`
Expand Down
6 changes: 3 additions & 3 deletions receiver/hostmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
)

func TestLoadConfig(t *testing.T) {
Expand Down Expand Up @@ -119,8 +119,8 @@ func TestLoadConfig(t *testing.T) {
cfg.SetEnvMap(common.EnvMap{})
return cfg
})(),
uptimescraper.TypeStr: (func() internal.Config {
cfg := (&uptimescraper.Factory{}).CreateDefaultConfig()
systemscraper.TypeStr: (func() internal.Config {
cfg := (&systemscraper.Factory{}).CreateDefaultConfig()
cfg.SetEnvMap(common.EnvMap{})
return cfg
})(),
Expand Down
4 changes: 2 additions & 2 deletions receiver/hostmetricsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
)

const (
Expand All @@ -46,7 +46,7 @@ var (
pagingscraper.TypeStr: &pagingscraper.Factory{},
processesscraper.TypeStr: &processesscraper.Factory{},
processscraper.TypeStr: &processscraper.Factory{},
uptimescraper.TypeStr: &uptimescraper.Factory{},
systemscraper.TypeStr: &systemscraper.Factory{},
}
)

Expand Down
7 changes: 4 additions & 3 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
)

var allMetrics = []string{
Expand Down Expand Up @@ -82,7 +82,7 @@ var factories = map[string]internal.ScraperFactory{
pagingscraper.TypeStr: &pagingscraper.Factory{},
processesscraper.TypeStr: &processesscraper.Factory{},
processscraper.TypeStr: &processscraper.Factory{},
uptimescraper.TypeStr: &uptimescraper.Factory{},
systemscraper.TypeStr: &systemscraper.Factory{},
}

type testEnv struct {
Expand Down Expand Up @@ -404,7 +404,7 @@ func Benchmark_ScrapeUptimeMetrics(b *testing.B) {

cfg := &Config{
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
Scrapers: map[string]internal.Config{uptimescraper.TypeStr: (&uptimescraper.Factory{}).CreateDefaultConfig()},
Scrapers: map[string]internal.Config{systemscraper.TypeStr: (&systemscraper.Factory{}).CreateDefaultConfig()},
}

benchmarkScrapeMetrics(b, cfg)
Expand Down Expand Up @@ -444,6 +444,7 @@ func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) {
networkscraper.TypeStr: &networkscraper.Config{},
pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig(),
processesscraper.TypeStr: &processesscraper.Config{},
systemscraper.TypeStr: &systemscraper.Config{},
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
)

// Config relating to Uptime Metric Scraper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

//go:generate mdatagen metadata.yaml

package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# hostmetricsreceiver/uptime
# hostmetricsreceiver/system

**Parent Component:** hostmetrics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"context"
"errors"
"runtime"

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

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
hostmeta "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
)

// This file implements Factory for Uptime scraper.
// This file implements Factory for System scraper.

const (
// TypeStr the value of "type" key in configuration.
TypeStr = "uptime"
TypeStr = "system"
)

var (
// scraperType is the component type used for the built scraper.
scraperType component.Type = component.MustNewType(TypeStr)
)

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

return scraperhelper.NewScraper(
hostmeta.Type,
scraperType,
uptimeScraper.scrape,
scraperhelper.WithStart(uptimeScraper.start),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package systemscraper

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/receiver/receivertest"
)

func TestCreateSystemScraper(t *testing.T) {
factory := &Factory{}
cfg := &Config{}

scraper, err := factory.CreateMetricsScraper(context.Background(), receivertest.NewNopSettings(), cfg)

assert.NoError(t, err)
assert.NotNil(t, scraper)
assert.Equal(t, scraperType.String(), scraper.ID().String())
}

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

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
@@ -1,4 +1,4 @@
type: hostmetricsreceiver/uptime
type: hostmetricsreceiver/system

parent: hostmetrics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package uptimescraper
package systemscraper

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"context"
Expand All @@ -14,7 +14,7 @@ import (
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver"

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

// scraper for Uptime Metrics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package uptimescraper
package systemscraper

import (
"context"
Expand All @@ -14,7 +14,7 @@ import (
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"

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

func TestScrape(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ receivers:
include:
names: ["test2", "test3"]
match_type: "regexp"
uptime:
system:

processors:
nop:
Expand Down

0 comments on commit 0173f45

Please sign in to comment.