Skip to content

Commit

Permalink
[chore][mdatagen] Use MustNewType for metadata.Type
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Feb 5, 2024
1 parent ae77a82 commit 83dfce8
Show file tree
Hide file tree
Showing 271 changed files with 954 additions and 333 deletions.
5 changes: 4 additions & 1 deletion cmd/mdatagen/internal/metadata/generated_status.go

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

10 changes: 8 additions & 2 deletions cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,11 @@ import (
"go.opentelemetry.io/otel/trace"
)
var (
Type = component.MustNewType("foo")
)
const (
Type = "foo"
MetricsStability = component.StabilityLevelBeta
)
Expand Down Expand Up @@ -362,8 +365,11 @@ import (
"go.opentelemetry.io/otel/trace"
)
var (
Type = component.MustNewType("foo")
)
const (
Type = "foo"
MetricsStability = component.StabilityLevelAlpha
)
Expand Down
9 changes: 7 additions & 2 deletions cmd/mdatagen/templates/status.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import (
"go.opentelemetry.io/otel/trace"
)

{{ if eq .Parent "" }}
var (
Type = component.MustNewType("{{ .Type }}")
)
{{- end }}

const (
Type = "{{ .Type }}"
{{- range $stability, $signals := .Status.Stability }}
{{- range $signal := $signals }}
{{ toCamelCase $signal }}Stability = component.StabilityLevel{{ casesTitle $stability }}
Expand All @@ -23,4 +28,4 @@ func Meter(settings component.TelemetrySettings) metric.Meter {

func Tracer(settings component.TelemetrySettings) trace.Tracer {
return settings.TracerProvider.Tracer("{{ .ScopeName }}")
}
}
17 changes: 17 additions & 0 deletions cmd/mdatagen/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"errors"
"fmt"
"regexp"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.uber.org/multierr"
Expand All @@ -28,10 +29,26 @@ func (md *metadata) Validate() error {
return errs
}

// typeRegexp is used to validate the type of a component.
// A type must start with an ASCII alphabetic character and
// can only contain ASCII alphanumeric characters and '_'.
// We allow '/' for subcomponents.
// This must be kept in sync with the regex in component/config.go.
var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]*$`)

func (md *metadata) validateType() error {
if md.Type == "" {
return errors.New("missing type")
}

if md.Parent != "" {
// subcomponents are allowed to have a '/' in their type.
return nil
}

if !typeRegexp.MatchString(md.Type) {
return fmt.Errorf("invalid character(s) in type %q", md.Type)
}
return nil
}

Expand Down

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.

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.

6 changes: 3 additions & 3 deletions connector/servicegraphconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ func newConnector(set component.TelemetrySettings, config component.Config) *ser
meter := metadata.Meter(set)

droppedSpan, _ := meter.Int64Counter(
processorhelper.BuildCustomMetricName(metadata.Type, "dropped_spans"),
processorhelper.BuildCustomMetricName(metadata.Type.String(), "dropped_spans"),
metric.WithDescription("Number of spans dropped when trying to add edges"),
metric.WithUnit("1"),
)
totalEdges, _ := meter.Int64Counter(
processorhelper.BuildCustomMetricName(metadata.Type, "total_edges"),
processorhelper.BuildCustomMetricName(metadata.Type.String(), "total_edges"),
metric.WithDescription("Total number of unique edges"),
metric.WithUnit("1"),
)
expiredEdges, _ := meter.Int64Counter(
processorhelper.BuildCustomMetricName(metadata.Type, "expired_edges"),
processorhelper.BuildCustomMetricName(metadata.Type.String(), "expired_edges"),
metric.WithDescription("Number of edges that expired before finding its matching span"),
metric.WithUnit("1"),
)
Expand Down

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.

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

2 changes: 1 addition & 1 deletion exporter/awscloudwatchlogsexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newCwLogsPusher(expConfig *Config, params exp.CreateSettings) (*cwlExporter
}

// create CWLogs client with aws session config
svcStructuredLog := cwlogs.NewClient(params.Logger, awsConfig, params.BuildInfo, expConfig.LogGroupName, expConfig.LogRetention, expConfig.Tags, session, metadata.Type)
svcStructuredLog := cwlogs.NewClient(params.Logger, awsConfig, params.BuildInfo, expConfig.LogGroupName, expConfig.LogRetention, expConfig.Tags, session, metadata.Type.String())
collectorIdentifier, err := uuid.NewRandom()

if err != nil {
Expand Down

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

2 changes: 1 addition & 1 deletion exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newEmfExporter(config *Config, set exporter.CreateSettings) (*emfExporter,
}

// create CWLogs client with aws session config
svcStructuredLog := cwlogs.NewClient(set.Logger, awsConfig, set.BuildInfo, config.LogGroupName, config.LogRetention, config.Tags, session, metadata.Type)
svcStructuredLog := cwlogs.NewClient(set.Logger, awsConfig, set.BuildInfo, config.LogGroupName, config.LogRetention, config.Tags, session, metadata.Type.String())
collectorIdentifier, err := uuid.NewRandom()

if err != nil {
Expand Down

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.

5 changes: 4 additions & 1 deletion exporter/awss3exporter/internal/metadata/generated_status.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.

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.

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

0 comments on commit 83dfce8

Please sign in to comment.