Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Support connector in metrics.go.tmpl NewMetricsBuilder #12403

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/fix_cmd_mdata-gen-metrics.yml
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: bug_fix

# 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: Fix mdatagen generated_metrics for connectors

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

# (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]
2 changes: 1 addition & 1 deletion cmd/mdatagen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Examples of this metadata about a component are:
* its stability level
* the distributions containing it
* the types of pipelines it supports
* metrics emitted in the case of a scraping receiver
* metrics emitted in the case of a scraping receiver, a scrapper, or a connector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* metrics emitted in the case of a scraping receiver, a scrapper, or a connector
* metrics emitted in the case of a scraping receiver, a scraper, or a connector


The metadata generator defines a schema for specifying this information to ensure it is complete and well-formed.
The metadata generator is then able to ingest the metadata, validate it against the schema and produce documentation in a standardized format.
Expand Down
15 changes: 15 additions & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require (
go.opentelemetry.io/collector/component/componenttest v0.120.0
go.opentelemetry.io/collector/confmap v1.26.0
go.opentelemetry.io/collector/confmap/provider/fileprovider v1.26.0
go.opentelemetry.io/collector/connector v0.120.0
go.opentelemetry.io/collector/connector/connectortest v0.120.0
go.opentelemetry.io/collector/consumer v1.26.0
go.opentelemetry.io/collector/consumer/consumertest v0.120.0
go.opentelemetry.io/collector/filter v0.120.0
Expand Down Expand Up @@ -49,11 +51,14 @@ require (
github.com/spf13/pflag v1.0.6 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/collector/component/componentstatus v0.120.0 // indirect
go.opentelemetry.io/collector/connector/xconnector v0.120.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.120.0 // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.120.0 // indirect
go.opentelemetry.io/collector/internal/fanoutconsumer v0.120.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.120.0 // indirect
go.opentelemetry.io/collector/pdata/testdata v0.120.0 // indirect
go.opentelemetry.io/collector/pipeline v0.120.0 // indirect
go.opentelemetry.io/collector/pipeline/xpipeline v0.120.0 // indirect
go.opentelemetry.io/collector/processor/xprocessor v0.120.0 // indirect
go.opentelemetry.io/collector/receiver/xreceiver v0.120.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
Expand Down Expand Up @@ -118,3 +123,13 @@ replace go.opentelemetry.io/collector/consumer/consumererror => ../../consumer/c
replace go.opentelemetry.io/collector/scraper => ../../scraper

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

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

replace go.opentelemetry.io/collector/connector/connectortest => ../../connector/connectortest

replace go.opentelemetry.io/collector/pipeline/xpipeline => ../../pipeline/xpipeline

replace go.opentelemetry.io/collector/internal/fanoutconsumer => ../../internal/fanoutconsumer

replace go.opentelemetry.io/collector/connector/xconnector => ../../connector/xconnector
7 changes: 7 additions & 0 deletions cmd/mdatagen/internal/sampleconnector/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 sampleconnector // import "go.opentelemetry.io/collector/cmd/mdatagen/internal/sampleconnector"
16 changes: 16 additions & 0 deletions cmd/mdatagen/internal/sampleconnector/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# sample

## 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 |
41 changes: 41 additions & 0 deletions cmd/mdatagen/internal/sampleconnector/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"context"

"go.opentelemetry.io/collector/cmd/mdatagen/internal/sampleconnector/internal/metadata"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/pmetric"
)

// NewFactory returns a receiver.Factory for sample receiver.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NewFactory returns a receiver.Factory for sample receiver.
// NewFactory returns a connector.Factory for sample connector.

func NewFactory() connector.Factory {
return connector.NewFactory(
metadata.Type,
func() component.Config { return &struct{}{} },
connector.WithMetricsToMetrics(createMetricsToMetricsConnector, metadata.MetricsStability))
}

func createMetricsToMetricsConnector(context.Context, connector.Settings, component.Config, consumer.Metrics) (connector.Metrics, error) {
return nopInstance, nil

Check warning on line 25 in cmd/mdatagen/internal/sampleconnector/factory.go

View check run for this annotation

Codecov / codecov/patch

cmd/mdatagen/internal/sampleconnector/factory.go#L24-L25

Added lines #L24 - L25 were not covered by tests
}

var nopInstance = &nopConnector{}

type nopConnector struct {
component.StartFunc
component.ShutdownFunc
}

func (n nopConnector) Capabilities() consumer.Capabilities {
return consumer.Capabilities{MutatesData: false}

Check warning on line 36 in cmd/mdatagen/internal/sampleconnector/factory.go

View check run for this annotation

Codecov / codecov/patch

cmd/mdatagen/internal/sampleconnector/factory.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}

func (n nopConnector) ConsumeMetrics(context.Context, pmetric.Metrics) error {
return nil

Check warning on line 40 in cmd/mdatagen/internal/sampleconnector/factory.go

View check run for this annotation

Codecov / codecov/patch

cmd/mdatagen/internal/sampleconnector/factory.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

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/sampleconnector/generated_package_test.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.

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

Loading
Loading