Skip to content

Commit

Permalink
Add scraper component type support to mdatagen (#12092)
Browse files Browse the repository at this point in the history
Updates
#11238

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jan 16, 2025
1 parent c56efd3 commit 60b22d1
Show file tree
Hide file tree
Showing 24 changed files with 1,970 additions and 11 deletions.
25 changes: 25 additions & 0 deletions .chloggen/add-scraper-support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add scraper component type support to mdatagen

# One or more tracking issues or pull requests related to the change
issues: [12092]

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

# 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: [api]
6 changes: 6 additions & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ require (
go.opentelemetry.io/collector/processor/processortest v0.117.0
go.opentelemetry.io/collector/receiver v0.117.0
go.opentelemetry.io/collector/receiver/receivertest v0.117.0
go.opentelemetry.io/collector/scraper v0.117.0
go.opentelemetry.io/collector/scraper/scrapertest v0.117.0
go.opentelemetry.io/collector/semconv v0.117.0
go.opentelemetry.io/otel/metric v1.32.0
go.opentelemetry.io/otel/sdk/metric v1.32.0
Expand Down Expand Up @@ -114,3 +116,7 @@ replace go.opentelemetry.io/collector/component/componentstatus => ../../compone
replace go.opentelemetry.io/collector/processor => ../../processor

replace go.opentelemetry.io/collector/consumer/consumererror => ../../consumer/consumererror

replace go.opentelemetry.io/collector/scraper => ../../scraper

replace go.opentelemetry.io/collector/scraper/scrapertest => ../../scraper/scrapertest
3 changes: 3 additions & 0 deletions cmd/mdatagen/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func templatize(tmplFile string, md Metadata) *template.Template {
"isConnector": func() bool {
return md.Status.Class == "connector"
},
"isScraper": func() bool {
return md.Status.Class == "scraper"
},
"isCommand": func() bool {
return md.Status.Class == "cmd"
},
Expand Down

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

18 changes: 18 additions & 0 deletions cmd/mdatagen/internal/samplescraper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Sample Scraper
This scraper is used for testing purposes to check the output of mdatagen.
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [stable]: metrics |
| Unsupported Platforms | freebsd, illumos |
| Distributions | [] |
| Warnings | [Any additional information that should be brought to the consumer's attention](#warnings) |
| 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) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@dmitryax](https://www.github.com/dmitryax) |

[stable]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stable
<!-- end autogenerated section -->

## Warnings

This is where warnings are described.
7 changes: 7 additions & 0 deletions cmd/mdatagen/internal/samplescraper/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Generate a test metrics builder from a sample metrics set covering all configuration options.
//go:generate mdatagen metadata.yaml

package samplescraper // import "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplescraper"
115 changes: 115 additions & 0 deletions cmd/mdatagen/internal/samplescraper/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# sample

## 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
```
### default.metric
Monotonic cumulative sum int metric enabled by default.
The metric will be become optional soon.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| string_attr | Attribute with any string value. | Any Str |
| state | Integer attribute with overridden name. | Any Int |
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` |
| slice_attr | Attribute with a slice value. | Any Slice |
| map_attr | Attribute with a map value. | Any Map |
### default.metric.to_be_removed
[DEPRECATED] Non-monotonic delta sum double metric enabled by default.
The metric will be will be removed soon.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Double | Delta | false |
### metric.input_type
Monotonic cumulative sum int metric with string input_type enabled by default.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| string_attr | Attribute with any string value. | Any Str |
| state | Integer attribute with overridden name. | Any Int |
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` |
| slice_attr | Attribute with a slice value. | Any Slice |
| map_attr | Attribute with a map value. | Any Map |
## Optional Metrics
The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration:
```yaml
metrics:
<metric_name>:
enabled: true
```
### optional.metric
[DEPRECATED] Gauge double metric disabled by default.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| string_attr | Attribute with any string value. | Any Str |
| boolean_attr | Attribute with a boolean value. | Any Bool |
| boolean_attr2 | Another attribute with a boolean value. | Any Bool |
### optional.metric.empty_unit
[DEPRECATED] Gauge double metric disabled by default.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| | Gauge | Double |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| string_attr | Attribute with any string value. | Any Str |
| boolean_attr | Attribute with a boolean value. | Any Bool |
## Resource Attributes
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| map.resource.attr | Resource attribute with a map value. | Any Map | true |
| optional.resource.attr | Explicitly disabled ResourceAttribute. | Any Str | false |
| slice.resource.attr | Resource attribute with a slice value. | Any Slice | true |
| string.enum.resource.attr | Resource attribute with a known set of string values. | Str: ``one``, ``two`` | true |
| string.resource.attr | Resource attribute with any string value. | Any Str | true |
| string.resource.attr_disable_warning | Resource attribute with any string value. | Any Str | true |
| string.resource.attr_remove_warning | Resource attribute with any string value. | Any Str | false |
| string.resource.attr_to_be_removed | Resource attribute with any string value. | Any Str | true |
27 changes: 27 additions & 0 deletions cmd/mdatagen/internal/samplescraper/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package samplescraper // import "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplescraper"

import (
"context"

"go.opentelemetry.io/collector/cmd/mdatagen/internal/samplescraper/internal/metadata"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/scraper"
)

// NewFactory returns a receiver.Factory for sample receiver.
func NewFactory() scraper.Factory {
return scraper.NewFactory(
metadata.Type,
func() component.Config { return &struct{}{} },
scraper.WithMetrics(createMetrics, metadata.MetricsStability))
}

func createMetrics(context.Context, scraper.Settings, component.Config) (scraper.Metrics, error) {
return scraper.NewMetrics(func(context.Context) (pmetric.Metrics, error) {
return pmetric.NewMetrics(), nil
})
}
70 changes: 70 additions & 0 deletions cmd/mdatagen/internal/samplescraper/generated_component_test.go

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

13 changes: 13 additions & 0 deletions cmd/mdatagen/internal/samplescraper/generated_package_test.go

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

Loading

0 comments on commit 60b22d1

Please sign in to comment.