Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
go.opentelemetry.io/collector/connector/connectortest v0.143.0
go.opentelemetry.io/collector/consumer v1.49.0
go.opentelemetry.io/collector/consumer/consumertest v0.143.0
go.opentelemetry.io/collector/featuregate v1.49.0
go.opentelemetry.io/collector/filter v0.143.0
go.opentelemetry.io/collector/pdata v1.49.0
go.opentelemetry.io/collector/pdata/xpdata v0.143.0
Expand Down Expand Up @@ -60,7 +61,6 @@ require (
go.opentelemetry.io/collector/connector/xconnector v0.143.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.143.0 // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.143.0 // indirect
go.opentelemetry.io/collector/featuregate v1.49.0 // indirect
go.opentelemetry.io/collector/internal/componentalias v0.0.0-00010101000000-000000000000 // indirect
go.opentelemetry.io/collector/internal/fanoutconsumer v0.143.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.143.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions cmd/mdatagen/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ func run(ymlPath string) error {
toGenerate[filepath.Join(tmplDir, "logs_test.go.tmpl")] = filepath.Join(codeDir, "generated_logs_test.go")
}

if len(md.FeatureGates) > 0 { // only generate feature gates if feature gates are present
toGenerate[filepath.Join(tmplDir, "feature_gates.go.tmpl")] = filepath.Join(codeDir, "generated_feature_gates.go")
}

// If at least one file to generate, will need the codeDir
if len(toGenerate) > 0 {
if err = os.MkdirAll(codeDir, 0o700); err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/mdatagen/internal/embedded_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestEnsureTemplatesLoaded(t *testing.T) {
path.Join(rootDir, "telemetrytest_test.go.tmpl"): {},
path.Join(rootDir, "helper.tmpl"): {},
path.Join(rootDir, "feature_gates.md.tmpl"): {},
path.Join(rootDir, "feature_gates.go.tmpl"): {},
}
count = 0
)
Expand Down
9 changes: 9 additions & 0 deletions cmd/mdatagen/internal/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@ func TestLoadMetadata(t *testing.T) {
ScopeName: "go.opentelemetry.io/collector/internal/receiver/samplereceiver",
ShortFolderName: "sample",
Tests: Tests{Host: "newMdatagenNopHost()"},
FeatureGates: []FeatureGate{
{
ID: "receiver.sample.featuregate.example",
Description: "This is an example feature gate for testing mdatagen code generation.",
Stage: "alpha",
FromVersion: "v0.100.0",
ReferenceURL: "https://github.com/open-telemetry/opentelemetry-collector/issues/12345",
},
},
},
},
{
Expand Down
10 changes: 10 additions & 0 deletions cmd/mdatagen/internal/samplereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,13 @@ Duration of request [Alpha]
| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| s | Histogram | Double | Alpha |

## Feature Gates

This component has the following feature gates:

| Feature Gate | Stage | Description | From Version | To Version | Reference |
| ------------ | ----- | ----------- | ------------ | ---------- | --------- |
| `receiver.sample.featuregate.example` | alpha | This is an example feature gate for testing mdatagen code generation. | v0.100.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector/issues/12345) |

For more information about feature gates, see the [Feature Gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md) documentation.

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

7 changes: 7 additions & 0 deletions cmd/mdatagen/internal/samplereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ github_project: open-telemetry/opentelemetry-collector

sem_conv_version: 1.38.0

feature_gates:
- id: receiver.sample.featuregate.example
description: This is an example feature gate for testing mdatagen code generation.
stage: alpha
from_version: v0.100.0
reference_url: https://github.com/open-telemetry/opentelemetry-collector/issues/12345

status:
disable_codecov_badge: true
class: receiver
Expand Down
21 changes: 21 additions & 0 deletions cmd/mdatagen/internal/templates/feature_gates.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Code generated by mdatagen. DO NOT EDIT.

package {{ .Package }}

import (
"go.opentelemetry.io/collector/featuregate"
)

{{- range $idx, $gate := .FeatureGates }}

var {{ printf "%s" $gate.ID | publicVar }}FeatureGate = featuregate.GlobalRegistry().MustRegister(
"{{ $gate.ID }}",
featuregate.Stage{{ printf "%s" $gate.Stage | casesTitle }},
featuregate.WithRegisterDescription("{{ $gate.Description }}"),
featuregate.WithRegisterReferenceURL("{{ $gate.ReferenceURL }}"),
featuregate.WithRegisterFromVersion("{{ $gate.FromVersion }}"),
{{- if $gate.ToVersion }}
featuregate.WithRegisterToVersion("{{ $gate.ToVersion }}"),
{{- end }}
)
{{- end }}
Loading