Skip to content

Commit

Permalink
[podmanreceiver] Add metrics and resource metadata (#30232)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
- Adds "metadata.yml" file to autogenerate metrics and resources.
- [Update: not done in this PR] Fixes invalid network metrics: "rx ->
input" and "tx -> output"

**Link to tracking Issue:**
#28640

**Testing:** Previous tests preserved.

**Documentation:** <Describe the documentation added.>

---------

Co-authored-by: Mackenzie <63265430+mackjmr@users.noreply.github.com>
  • Loading branch information
rogercoll and mackjmr authored Apr 9, 2024
1 parent 4edca20 commit fe59abb
Show file tree
Hide file tree
Showing 20 changed files with 1,881 additions and 168 deletions.
27 changes: 27 additions & 0 deletions .chloggen/add_podman_metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: podmanreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adds metrics and resources metadata and sets seconds precision for cpu metrics"

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

# (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:

# 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.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
6 changes: 6 additions & 0 deletions receiver/podmanreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following settings are optional:
- `collection_interval` (default = `10s`): The interval at which to gather container stats.
- `initial_delay` (default = `1s`): defines how long this receiver waits before starting.
- `timeout` (default = `5s`): The maximum amount of time to wait for Podman API responses.
- `metrics` (defaults at [./documentation.md](./documentation.md)): Enables/disables individual metrics. See [./documentation.md](./documentation.md) for full detail.

Example:

Expand All @@ -42,6 +43,9 @@ receivers:
timeout: 10s
collection_interval: 10s
initial_delay: 1s
metrics:
container.cpu.usage.system:
enabled: false
```
The full list of settings exposed for this receiver are documented [here](./config.go)
Expand Down Expand Up @@ -84,6 +88,8 @@ The receiver emits the following metrics:
container.cpu.percent
container.cpu.usage.percpu

See [./documentation.md](./documentation.md) for full detail.

## Building

This receiver uses the official libpod Go bindings for Podman. In order to include
Expand Down
5 changes: 5 additions & 0 deletions receiver/podmanreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver/internal/metadata"
)

var _ component.Config = (*Config)(nil)
Expand All @@ -22,6 +24,9 @@ type Config struct {
APIVersion string `mapstructure:"api_version"`
SSHKey string `mapstructure:"ssh_key"`
SSHPassphrase configopaque.String `mapstructure:"ssh_passphrase"`

// MetricsBuilderConfig config. Enable or disable stats by name.
metadata.MetricsBuilderConfig `mapstructure:",squash"`
}

func (config Config) Validate() error {
Expand Down
10 changes: 6 additions & 4 deletions receiver/podmanreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func TestLoadConfig(t *testing.T) {
InitialDelay: time.Second,
Timeout: 5 * time.Second,
},
APIVersion: defaultAPIVersion,
Endpoint: "unix:///run/podman/podman.sock",
APIVersion: defaultAPIVersion,
Endpoint: "unix:///run/podman/podman.sock",
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
},
{
Expand All @@ -48,8 +49,9 @@ func TestLoadConfig(t *testing.T) {
InitialDelay: time.Second,
Timeout: 20 * time.Second,
},
APIVersion: defaultAPIVersion,
Endpoint: "http://example.com/",
APIVersion: defaultAPIVersion,
Endpoint: "http://example.com/",
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
},
}
Expand Down
120 changes: 120 additions & 0 deletions receiver/podmanreceiver/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# podman_stats

## Default Metrics

The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:

```yaml
metrics:
<metric_name>:
enabled: false
```
### container.blockio.io_service_bytes_recursive.read
Number of bytes transferred from the disk by the container
[More docs](https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt).
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {operations} | Sum | Int | Cumulative | true |
### container.blockio.io_service_bytes_recursive.write
Number of bytes transferred to the disk by the container
[More docs](https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt).
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {operations} | Sum | Int | Cumulative | true |
### container.cpu.percent
Percent of CPU used by the container.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |
### container.cpu.usage.percpu
Total CPU time consumed per CPU-core.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| core | The CPU core number when utilising per-CPU metrics. | Any Str |
### container.cpu.usage.system
System CPU usage.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
### container.cpu.usage.total
Total CPU time consumed.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
### container.memory.percent
Percentage of memory used.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |
### container.memory.usage.limit
Memory limit of the container.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | false |
### container.memory.usage.total
Memory usage of the container.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | false |
### container.network.io.usage.rx_bytes
Bytes received by the container.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | true |
### container.network.io.usage.tx_bytes
Bytes sent by the container.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | true |
## Resource Attributes
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| container.id | The ID of the container. | Any Str | true |
| container.image.name | The name of the image in use by the container. | Any Str | true |
| container.name | The name of the container. | Any Str | true |
| container.runtime | The runtime of the container. For this receiver, it will always be 'podman'. | Any Str | true |
7 changes: 4 additions & 3 deletions receiver/podmanreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ func createDefaultConfig() *Config {
cfg.Timeout = 5 * time.Second

return &Config{
ControllerConfig: cfg,
Endpoint: "unix:///run/podman/podman.sock",
APIVersion: defaultAPIVersion,
ControllerConfig: cfg,
Endpoint: "unix:///run/podman/podman.sock",
APIVersion: defaultAPIVersion,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/podmanreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podman
go 1.21

require (
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.97.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/collector/config/configopaque v1.4.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/collector/confmap v0.97.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/collector/consumer v0.97.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/collector/pdata v1.4.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/collector/receiver v0.97.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/collector/semconv v0.97.1-0.20240404121116-4f1a8936d26b
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/goleak v1.3.0
Expand Down
2 changes: 0 additions & 2 deletions receiver/podmanreceiver/go.sum

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

134 changes: 134 additions & 0 deletions receiver/podmanreceiver/internal/metadata/generated_config.go

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

Loading

0 comments on commit fe59abb

Please sign in to comment.