Skip to content

Commit

Permalink
[receiver/dockerstats] Add inspect metrics (open-telemetry#21803)
Browse files Browse the repository at this point in the history
**Description:**

Adds 3 new metrics from the docker inspect api
* container.cpu.limit
* container.cpu.shares
* container.restart.count

Since all these metrics are collected from the inspect api, a new method
was created (`recordInspectMetrics`) where only the containerJSON
structure is passed as an argument.

**Link to tracking Issue:** open-telemetry#21087

**Testing:**

New metrics were added to the receiver test and expected_metrics.yaml
files.
The receiver and config tests were also adjusted to reflect the minimum
api version of 1.25

```
❯ go clean -testcache
❯ make test
go test -race -timeout 300s -parallel 4 --tags="" ./...
ok  	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver	0.508s
ok  	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver/internal/metadata	0.381s
❯ go test --tags integration ./...
ok  	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver	14.060s
ok  	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver/internal/metadata	0.241s
```

**Documentation:**
New metrics documentation was generated using `mdatagen`

---------

Signed-off-by: Paschalis Tsilias <paschalis.tsilias@gmail.com>
Signed-off-by: Christian Kruse <ctkruse99@gmail.com>
Signed-off-by: Dani Louca <dlouca@splunk.com>
Signed-off-by: Jared Tan <jian.tan@daocloud.io>
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
Signed-off-by: Raphael Silva <rapphil@gmail.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
Signed-off-by: Sean Porter <portertech@gmail.com>
Co-authored-by: Christian Felipe Álvarez <calvarez@newrelic.com>
Co-authored-by: Christian <sigilioso@gmail.com>
Co-authored-by: Ryan Fitzpatrick <10867373+rmfitzpatrick@users.noreply.github.com>
Co-authored-by: Martin Majlis <122797378+martin-majlis-s1@users.noreply.github.com>
Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com>
Co-authored-by: hovavza <147598197+hovavza@users.noreply.github.com>
Co-authored-by: Povilas Versockas <povilas.versockas@coralogix.com>
Co-authored-by: Dmitrii Anoshin <anoshindx@gmail.com>
Co-authored-by: sakulali <sakulali@126.com>
Co-authored-by: OpenTelemetry Bot <107717825+opentelemetrybot@users.noreply.github.com>
Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Juraci Paixão Kröhling <juraci@kroehling.de>
Co-authored-by: Andrzej Stencel <astencel@sumologic.com>
Co-authored-by: Brandon Johnson <brandon.johnson@bluemedora.com>
Co-authored-by: Miel Donkers <miel.donkers@gmail.com>
Co-authored-by: bryan-aguilar <46550959+bryan-aguilar@users.noreply.github.com>
Co-authored-by: Christian Kruse <ctkruse99@gmail.com>
Co-authored-by: gord02 <53834349+gord02@users.noreply.github.com>
Co-authored-by: bagmeg <joonsoo181005@gmail.com>
Co-authored-by: Yang Song <songy23@users.noreply.github.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
Co-authored-by: Curtis Robert <crobert@splunk.com>
Co-authored-by: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com>
Co-authored-by: Antoine Toulme <antoine@lunar-ocean.com>
Co-authored-by: Dani Louca <59848726+dloucasfx@users.noreply.github.com>
Co-authored-by: xu0o0 <hq.xu0o0@gmail.com>
Co-authored-by: David Ashpole <dashpole@google.com>
Co-authored-by: Jared Tan <jian.tan@daocloud.io>
Co-authored-by: Raj Nishtala <113392743+rnishtala-sumo@users.noreply.github.com>
Co-authored-by: Dominik Rosiek <58699848+sumo-drosiek@users.noreply.github.com>
Co-authored-by: Priyanshu Raj <55045459+rpriyanshu9@users.noreply.github.com>
Co-authored-by: Raphael Philipe Mendes da Silva <rapphil@gmail.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
Co-authored-by: Yotam loewenbach <48534558+yotamloe@users.noreply.github.com>
Co-authored-by: Alex Boten <aboten@lightstep.com>
Co-authored-by: Jina Jain <jjain@splunk.com>
Co-authored-by: Curtis Robert <92119472+crobert-1@users.noreply.github.com>
Co-authored-by: Abhishek Saharn <102726227+asaharn@users.noreply.github.com>
Co-authored-by: Ramachandran A G <ramacg@microsoft.com>
Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Co-authored-by: Ramachandran A G <106139410+ag-ramachandran@users.noreply.github.com>
Co-authored-by: Faith Chikwekwe <faithchikwekwe01@gmail.com>
Co-authored-by: Daniel Kuiper <44123852+kuiperda@users.noreply.github.com>
Co-authored-by: ArchangelSDY <Archangel.SDY@gmail.com>
Co-authored-by: Pavol Loffay <p.loffay@gmail.com>
Co-authored-by: Paulo Janotti <pjanotti@splunk.com>
Co-authored-by: Nathan Burke <n.burke@natbur.com>
Co-authored-by: shalper2 <99686388+shalper2@users.noreply.github.com>
Co-authored-by: 道君 <daojun@apache.org>
Co-authored-by: Colin Desmond <codesmon@microsoft.com>
Co-authored-by: Mario <mariorvinas@gmail.com>
Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
Co-authored-by: Steven Swartz <stevenswartz@live.ca>
Co-authored-by: Chris Parkins <cjparkins@yahoo.com>
Co-authored-by: Frederic Branczyk <fbranczyk@gmail.com>
Co-authored-by: Jiekun <zhujiekun@52tt.com>
Co-authored-by: Joel <joelperez91@gmail.com>
Co-authored-by: Sean Porter <portertech@gmail.com>
Co-authored-by: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com>
Co-authored-by: nzbart <nzbart@users.noreply.github.com>
Co-authored-by: Pavan Krishna <pavankri@cisco.com>
Co-authored-by: pszkamruk-splunk <75434853+pszkamruk-splunk@users.noreply.github.com>
  • Loading branch information
Show file tree
Hide file tree
Showing 24 changed files with 1,534 additions and 37 deletions.
16 changes: 16 additions & 0 deletions .chloggen/add_inspect_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: dockerstatsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add [container.cpu.limit], [container.cpu.shares] and [container.restarts] metrics from docker container api"

# One or more tracking issues related to the change
issues: [21087]

# (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: It requires API version 1.25 or greater.
4 changes: 2 additions & 2 deletions receiver/dockerstatsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestLoadConfig(t *testing.T) {
},

Endpoint: "http://example.com/",
DockerAPIVersion: 1.24,
DockerAPIVersion: 1.25,

ExcludedImages: []string{
"undesired-container",
Expand Down Expand Up @@ -95,5 +95,5 @@ func TestValidateErrors(t *testing.T) {
assert.Equal(t, "endpoint must be specified", component.ValidateConfig(cfg).Error())

cfg = &Config{ScraperControllerSettings: scraperhelper.ScraperControllerSettings{CollectionInterval: 1 * time.Second}, Endpoint: "someEndpoint", DockerAPIVersion: 1.21}
assert.Equal(t, "api_version must be at least 1.22", component.ValidateConfig(cfg).Error())
assert.Equal(t, "api_version must be at least 1.25", component.ValidateConfig(cfg).Error())
}
26 changes: 26 additions & 0 deletions receiver/dockerstatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ Number of sectors transferred to/from disk by the group and descendant groups (O
| device_minor | Device minor number for block IO operations. | Any Str |
| operation | Type of BlockIO operation. | Any Str |
### container.cpu.limit
CPU limit set for the container.
This metric is only reported if the container has limits set with -cpus, -cpuset-cpus or -cpu-quota.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpus} | Gauge | Double |
### container.cpu.shares
CPU shares set for the container.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Int |
### container.cpu.throttling_data.periods
Number of periods with throttling active.
Expand Down Expand Up @@ -698,6 +716,14 @@ It requires docker API 1.23 or higher and kernel version >= 4.3 with pids cgroup
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {pids} | Sum | Int | Cumulative | false |
### container.restarts
Number of restarts for the container.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {restarts} | Sum | Int | Cumulative | true |
### container.uptime
Time elapsed since container start time.
Expand Down
12 changes: 12 additions & 0 deletions receiver/dockerstatsreceiver/internal/metadata/generated_config.go

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.

173 changes: 173 additions & 0 deletions receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go

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

Loading

0 comments on commit 9f300b7

Please sign in to comment.