Skip to content

Commit 60b22d1

Browse files
authored
Add scraper component type support to mdatagen (#12092)
Updates #11238 Signed-off-by: Bogdan Drutu <[email protected]>
1 parent c56efd3 commit 60b22d1

24 files changed

+1970
-11
lines changed

.chloggen/add-scraper-support.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: mdatagen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add scraper component type support to mdatagen
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12092]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

cmd/mdatagen/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ require (
1919
go.opentelemetry.io/collector/processor/processortest v0.117.0
2020
go.opentelemetry.io/collector/receiver v0.117.0
2121
go.opentelemetry.io/collector/receiver/receivertest v0.117.0
22+
go.opentelemetry.io/collector/scraper v0.117.0
23+
go.opentelemetry.io/collector/scraper/scrapertest v0.117.0
2224
go.opentelemetry.io/collector/semconv v0.117.0
2325
go.opentelemetry.io/otel/metric v1.32.0
2426
go.opentelemetry.io/otel/sdk/metric v1.32.0
@@ -114,3 +116,7 @@ replace go.opentelemetry.io/collector/component/componentstatus => ../../compone
114116
replace go.opentelemetry.io/collector/processor => ../../processor
115117

116118
replace go.opentelemetry.io/collector/consumer/consumererror => ../../consumer/consumererror
119+
120+
replace go.opentelemetry.io/collector/scraper => ../../scraper
121+
122+
replace go.opentelemetry.io/collector/scraper/scrapertest => ../../scraper/scrapertest

cmd/mdatagen/internal/command.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ func templatize(tmplFile string, md Metadata) *template.Template {
234234
"isConnector": func() bool {
235235
return md.Status.Class == "connector"
236236
},
237+
"isScraper": func() bool {
238+
return md.Status.Class == "scraper"
239+
},
237240
"isCommand": func() bool {
238241
return md.Status.Class == "cmd"
239242
},

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Sample Scraper
2+
This scraper is used for testing purposes to check the output of mdatagen.
3+
<!-- status autogenerated section -->
4+
| Status | |
5+
| ------------- |-----------|
6+
| Stability | [stable]: metrics |
7+
| Unsupported Platforms | freebsd, illumos |
8+
| Distributions | [] |
9+
| Warnings | [Any additional information that should be brought to the consumer's attention](#warnings) |
10+
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector?query=is%3Aissue%20is%3Aopen%20label%3Ascraper%2Fsample%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aopen+is%3Aissue+label%3Ascraper%2Fsample) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector?query=is%3Aissue%20is%3Aclosed%20label%3Ascraper%2Fsample%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aclosed+is%3Aissue+label%3Ascraper%2Fsample) |
11+
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@dmitryax](https://www.github.com/dmitryax) |
12+
13+
[stable]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stable
14+
<!-- end autogenerated section -->
15+
16+
## Warnings
17+
18+
This is where warnings are described.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Generate a test metrics builder from a sample metrics set covering all configuration options.
5+
//go:generate mdatagen metadata.yaml
6+
7+
package samplescraper // import "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplescraper"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)
2+
3+
# sample
4+
5+
## Default Metrics
6+
7+
The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:
8+
9+
```yaml
10+
metrics:
11+
<metric_name>:
12+
enabled: false
13+
```
14+
15+
### default.metric
16+
17+
Monotonic cumulative sum int metric enabled by default.
18+
19+
The metric will be become optional soon.
20+
21+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
22+
| ---- | ----------- | ---------- | ----------------------- | --------- |
23+
| s | Sum | Int | Cumulative | true |
24+
25+
#### Attributes
26+
27+
| Name | Description | Values |
28+
| ---- | ----------- | ------ |
29+
| string_attr | Attribute with any string value. | Any Str |
30+
| state | Integer attribute with overridden name. | Any Int |
31+
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` |
32+
| slice_attr | Attribute with a slice value. | Any Slice |
33+
| map_attr | Attribute with a map value. | Any Map |
34+
35+
### default.metric.to_be_removed
36+
37+
[DEPRECATED] Non-monotonic delta sum double metric enabled by default.
38+
39+
The metric will be will be removed soon.
40+
41+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
42+
| ---- | ----------- | ---------- | ----------------------- | --------- |
43+
| s | Sum | Double | Delta | false |
44+
45+
### metric.input_type
46+
47+
Monotonic cumulative sum int metric with string input_type enabled by default.
48+
49+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
50+
| ---- | ----------- | ---------- | ----------------------- | --------- |
51+
| s | Sum | Int | Cumulative | true |
52+
53+
#### Attributes
54+
55+
| Name | Description | Values |
56+
| ---- | ----------- | ------ |
57+
| string_attr | Attribute with any string value. | Any Str |
58+
| state | Integer attribute with overridden name. | Any Int |
59+
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` |
60+
| slice_attr | Attribute with a slice value. | Any Slice |
61+
| map_attr | Attribute with a map value. | Any Map |
62+
63+
## Optional Metrics
64+
65+
The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration:
66+
67+
```yaml
68+
metrics:
69+
<metric_name>:
70+
enabled: true
71+
```
72+
73+
### optional.metric
74+
75+
[DEPRECATED] Gauge double metric disabled by default.
76+
77+
| Unit | Metric Type | Value Type |
78+
| ---- | ----------- | ---------- |
79+
| 1 | Gauge | Double |
80+
81+
#### Attributes
82+
83+
| Name | Description | Values |
84+
| ---- | ----------- | ------ |
85+
| string_attr | Attribute with any string value. | Any Str |
86+
| boolean_attr | Attribute with a boolean value. | Any Bool |
87+
| boolean_attr2 | Another attribute with a boolean value. | Any Bool |
88+
89+
### optional.metric.empty_unit
90+
91+
[DEPRECATED] Gauge double metric disabled by default.
92+
93+
| Unit | Metric Type | Value Type |
94+
| ---- | ----------- | ---------- |
95+
| | Gauge | Double |
96+
97+
#### Attributes
98+
99+
| Name | Description | Values |
100+
| ---- | ----------- | ------ |
101+
| string_attr | Attribute with any string value. | Any Str |
102+
| boolean_attr | Attribute with a boolean value. | Any Bool |
103+
104+
## Resource Attributes
105+
106+
| Name | Description | Values | Enabled |
107+
| ---- | ----------- | ------ | ------- |
108+
| map.resource.attr | Resource attribute with a map value. | Any Map | true |
109+
| optional.resource.attr | Explicitly disabled ResourceAttribute. | Any Str | false |
110+
| slice.resource.attr | Resource attribute with a slice value. | Any Slice | true |
111+
| string.enum.resource.attr | Resource attribute with a known set of string values. | Str: ``one``, ``two`` | true |
112+
| string.resource.attr | Resource attribute with any string value. | Any Str | true |
113+
| string.resource.attr_disable_warning | Resource attribute with any string value. | Any Str | true |
114+
| string.resource.attr_remove_warning | Resource attribute with any string value. | Any Str | false |
115+
| string.resource.attr_to_be_removed | Resource attribute with any string value. | Any Str | true |
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package samplescraper // import "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplescraper"
5+
6+
import (
7+
"context"
8+
9+
"go.opentelemetry.io/collector/cmd/mdatagen/internal/samplescraper/internal/metadata"
10+
"go.opentelemetry.io/collector/component"
11+
"go.opentelemetry.io/collector/pdata/pmetric"
12+
"go.opentelemetry.io/collector/scraper"
13+
)
14+
15+
// NewFactory returns a receiver.Factory for sample receiver.
16+
func NewFactory() scraper.Factory {
17+
return scraper.NewFactory(
18+
metadata.Type,
19+
func() component.Config { return &struct{}{} },
20+
scraper.WithMetrics(createMetrics, metadata.MetricsStability))
21+
}
22+
23+
func createMetrics(context.Context, scraper.Settings, component.Config) (scraper.Metrics, error) {
24+
return scraper.NewMetrics(func(context.Context) (pmetric.Metrics, error) {
25+
return pmetric.NewMetrics(), nil
26+
})
27+
}

cmd/mdatagen/internal/samplescraper/generated_component_test.go

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/internal/samplescraper/generated_package_test.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)