Skip to content

Commit

Permalink
[cmd/mdatagen] Generate more mdatagen attribute documentation (open-t…
Browse files Browse the repository at this point in the history
…elemetry#8985)

* Enhance mdatagen attribute documentation

* ensure example has attribute without value/enums

* Add changelog entry

* Add testing of mdatagen documentation generation

* Commit all updated documentation.md files

* Satisfy linter
  • Loading branch information
dehaansa committed Apr 11, 2022
1 parent c03519a commit 67a8a8d
Show file tree
Hide file tree
Showing 31 changed files with 245 additions and 172 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- `splunkheceporter`: Add an option to disable log or profiling data (#9065)
- `datadogexporter`: Add `host_metadata` configuration section to configure host metadata export (#9100)

- `cmd/mdatagen`: Update documentation generated for attributes to list enumerated values and show the "value" that will be visible on metrics when it is different from the attribute key in metadata.yaml (#8983)

### 🛑 Breaking changes 🛑

- `filelogreceiver`, `journaldreceiver`, `syslogreceiver`, `tcplogreceiver`, `udplogreceiver`:
Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/documentation.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| Name | Description | Values |
| ---- | ----------- | ------ |
{{- range $attributeName, $attributeInfo := .Attributes }}
| {{ $attributeName }} | {{ $attributeInfo.Description }} |
| {{ $attributeName }}{{- if $attributeInfo.Value }} ({{ $attributeInfo.Value }}){{- end}} | {{ $attributeInfo.Description }} | {{ stringsJoin $attributeInfo.Enum ", " }} |
{{- end }}
1 change: 1 addition & 0 deletions cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func generateDocumentation(ymlDir string, thisDir string, md metadata, useExpGen
"publicVar": func(s string) (string, error) {
return formatIdentifier(s, true)
},
"stringsJoin": strings.Join,
}).ParseFiles(path.Join(thisDir, "documentation.tmpl")))

buf := bytes.Buffer{}
Expand Down
47 changes: 35 additions & 12 deletions cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ import (
const (
validMetadata = `
name: metricreceiver
attributes:
cpu_type:
value: type
description: The type of CPU consumption
enum:
- user
- io_wait
- system
host:
description: The type of CPU consumption
metrics:
system.cpu.time:
enabled: true
Expand All @@ -35,7 +45,7 @@ metrics:
sum:
aggregation: cumulative
value_type: double
attributes: []
attributes: [host, cpu_type]
`
)

Expand All @@ -45,20 +55,23 @@ func Test_runContents(t *testing.T) {
useExpGen bool
}
tests := []struct {
name string
args args
want string
wantErr string
name string
args args
expectedDocumentation string
want string
wantErr string
}{
{
name: "valid metadata",
args: args{validMetadata, false},
want: "",
name: "valid metadata",
args: args{validMetadata, false},
expectedDocumentation: "testdata/documentation_v1.md",
want: "",
},
{
name: "valid metadata v2",
args: args{validMetadata, true},
want: "",
name: "valid metadata v2",
args: args{validMetadata, true},
expectedDocumentation: "testdata/documentation_v2.md",
want: "",
},
{
name: "invalid yaml",
Expand Down Expand Up @@ -91,7 +104,17 @@ func Test_runContents(t *testing.T) {
}
require.FileExists(t, genFilePath)

require.FileExists(t, filepath.Join(tmpdir, "documentation.md"))
actualDocumentation := filepath.Join(tmpdir, "documentation.md")
require.FileExists(t, actualDocumentation)
if tt.expectedDocumentation != "" {
expectedFileBytes, err := ioutil.ReadFile(tt.expectedDocumentation)
require.NoError(t, err)

actualFileBytes, err := ioutil.ReadFile(actualDocumentation)
require.NoError(t, err)

require.Equal(t, expectedFileBytes, actualFileBytes)
}
}
})
}
Expand Down
20 changes: 20 additions & 0 deletions cmd/mdatagen/testdata/documentation_v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# metricreceiver

## Metrics

These are the metrics available for this scraper.

| Name | Description | Unit | Type | Attributes |
| ---- | ----------- | ---- | ---- | ---------- |
| **system.cpu.time** | Total CPU seconds broken down by different states. Additional information on CPU Time can be found [here](https://en.wikipedia.org/wiki/CPU_time). | s | Sum(Double) | <ul> <li>host</li> <li>cpu_type</li> </ul> |

**Highlighted metrics** are emitted by default.

## Metric attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| cpu_type (type) | The type of CPU consumption | user, io_wait, system |
| host | The type of CPU consumption | |
27 changes: 27 additions & 0 deletions cmd/mdatagen/testdata/documentation_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# metricreceiver

## Metrics

These are the metrics available for this scraper.

| Name | Description | Unit | Type | Attributes |
| ---- | ----------- | ---- | ---- | ---------- |
| **system.cpu.time** | Total CPU seconds broken down by different states. Additional information on CPU Time can be found [here](https://en.wikipedia.org/wiki/CPU_time). | s | Sum(Double) | <ul> <li>host</li> <li>cpu_type</li> </ul> |

**Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default.
Any metric can be enabled or disabled with the following scraper configuration:

```yaml
metrics:
<metric_name>:
enabled: <true|false>
```

## Metric attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| cpu_type (type) | The type of CPU consumption | user, io_wait, system |
| host | The type of CPU consumption | |
10 changes: 5 additions & 5 deletions receiver/apachereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| scoreboard_state | The state of a connection. |
| server_name | The name of the Apache HTTP server. |
| workers_state | The state of workers. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| scoreboard_state (state) | The state of a connection. | open, waiting, starting, reading, sending, keepalive, dnslookup, closing, logging, finishing, idle_cleanup |
| server_name | The name of the Apache HTTP server. | |
| workers_state (state) | The state of workers. | busy, idle |
4 changes: 2 additions & 2 deletions receiver/couchbasereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| Name | Description | Values |
| ---- | ----------- | ------ |
12 changes: 6 additions & 6 deletions receiver/couchdbreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| http.method | An HTTP request method. |
| http.status_code | An HTTP status code. |
| operation | The operation type. |
| view | The view type. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| http.method | An HTTP request method. | COPY, DELETE, GET, HEAD, OPTIONS, POST, PUT |
| http.status_code | An HTTP status code. | |
| operation | The operation type. | writes, reads |
| view | The view type. | temporary_view_reads, view_reads |
34 changes: 17 additions & 17 deletions receiver/elasticsearchreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| cache_name | The name of cache. |
| collector_name | The name of the garbage collector. |
| direction | The direction of network data. |
| disk_usage_state | The state of a section of space on disk. |
| document_state | The state of the document. |
| elasticsearch.cluster.name | The name of the elasticsearch cluster. |
| elasticsearch.node.name | The name of the elasticsearch node. |
| fs_direction | The direction of filesystem IO. |
| health_status | The health status of the cluster. |
| memory_pool_name | The name of the JVM memory pool. |
| operation | The type of operation. |
| shard_state | The state of the shard. |
| task_state | The state of the task. |
| thread_pool_name | The name of the thread pool. |
| thread_state | The state of the thread. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| cache_name | The name of cache. | fielddata, query |
| collector_name (name) | The name of the garbage collector. | |
| direction | The direction of network data. | received, sent |
| disk_usage_state (state) | The state of a section of space on disk. | used, free |
| document_state (state) | The state of the document. | active, deleted |
| elasticsearch.cluster.name | The name of the elasticsearch cluster. | |
| elasticsearch.node.name | The name of the elasticsearch node. | |
| fs_direction (direction) | The direction of filesystem IO. | read, write |
| health_status (status) | The health status of the cluster. | green, yellow, red |
| memory_pool_name (name) | The name of the JVM memory pool. | |
| operation (operation) | The type of operation. | index, delete, get, query, fetch, scroll, suggest, merge, refresh, flush, warmer |
| shard_state (state) | The state of the shard. | active, relocating, initializing, unassigned |
| task_state (state) | The state of the task. | rejected, completed |
| thread_pool_name | The name of the thread pool. | |
| thread_state (state) | The state of the thread. | active, idle |
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| cpu | CPU number starting at 0. |
| state | Breakdown of CPU usage by type. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| cpu | CPU number starting at 0. | |
| state | Breakdown of CPU usage by type. | idle, interrupt, nice, softirq, steal, system, user, wait |
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| device | Name of the disk. |
| direction | Direction of flow of bytes/operations (read or write). |
| Name | Description | Values |
| ---- | ----------- | ------ |
| device | Name of the disk. | |
| direction | Direction of flow of bytes/operations (read or write). | read, write |
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| device | Identifier of the filesystem. |
| mode | Mountpoint mode such "ro", "rw", etc. |
| mountpoint | Mountpoint path. |
| state | Breakdown of filesystem usage by type. |
| type | Filesystem type, such as, "ext4", "tmpfs", etc. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| device | Identifier of the filesystem. | |
| mode | Mountpoint mode such "ro", "rw", etc. | |
| mountpoint | Mountpoint path. | |
| state | Breakdown of filesystem usage by type. | free, reserved, used |
| type | Filesystem type, such as, "ext4", "tmpfs", etc. | |
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| Name | Description | Values |
| ---- | ----------- | ------ |
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| state | Breakdown of memory usage by type. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| state | Breakdown of memory usage by type. | buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used |
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| device | Name of the network interface. |
| direction | Direction of flow of bytes/operations (receive or transmit). |
| protocol | Network protocol, e.g. TCP or UDP. |
| state | State of the network connection. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| device | Name of the network interface. | |
| direction | Direction of flow of bytes/operations (receive or transmit). | receive, transmit |
| protocol | Network protocol, e.g. TCP or UDP. | tcp |
| state | State of the network connection. | |
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| device | Name of the page file. |
| direction | Page In or Page Out. |
| state | Breakdown of paging usage by type. |
| type | Type of fault. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| device | Name of the page file. | |
| direction | Page In or Page Out. | page_in, page_out |
| state | Breakdown of paging usage by type. | cached, free, used |
| type | Type of fault. | major, minor |
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| status | Breakdown status of the processes. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| status | Breakdown status of the processes. | blocked, daemon, detached, idle, locked, orphan, paging, running, sleeping, stopped, system, unknown, zombies |
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ metrics:

## Metric attributes

| Name | Description |
| ---- | ----------- |
| direction | Direction of flow of bytes (read or write). |
| state | Breakdown of CPU usage by type. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| direction | Direction of flow of bytes (read or write). | read, write |
| state | Breakdown of CPU usage by type. | system, user, wait |
10 changes: 5 additions & 5 deletions receiver/kafkametricsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ These are the metrics available for this scraper.

## Metric attributes

| Name | Description |
| ---- | ----------- |
| group | The ID (string) of a consumer group |
| partition | The number (integer) of the partition |
| topic | The ID (integer) of a topic |
| Name | Description | Values |
| ---- | ----------- | ------ |
| group | The ID (string) of a consumer group | |
| partition | The number (integer) of the partition | |
| topic | The ID (integer) of a topic | |
8 changes: 4 additions & 4 deletions receiver/kubeletstatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ These are the metrics available for this scraper.

## Metric attributes

| Name | Description |
| ---- | ----------- |
| direction | Direction of flow of bytes/operations (receive or transmit). |
| interface | Name of the network interface. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| direction | Direction of flow of bytes/operations (receive or transmit). | receive, transmit |
| interface | Name of the network interface. | |
14 changes: 7 additions & 7 deletions receiver/memcachedreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ These are the metrics available for this scraper.

## Metric attributes

| Name | Description |
| ---- | ----------- |
| command | The type of command. |
| direction | Direction of data flow. |
| operation | The type of operation. |
| state | The type of CPU usage. |
| type | Result of cache request. |
| Name | Description | Values |
| ---- | ----------- | ------ |
| command | The type of command. | get, set, flush, touch |
| direction | Direction of data flow. | sent, received |
| operation | The type of operation. | increment, decrement, get |
| state | The type of CPU usage. | system, user |
| type | Result of cache request. | hit, miss |
Loading

0 comments on commit 67a8a8d

Please sign in to comment.