Skip to content

Commit

Permalink
use metadata to generate status table
Browse files Browse the repository at this point in the history
This is a proposed first step to remove needing to generate a table for each component separately. As part of this change I propose we also use the metadata to auto-generate the code to return the component status.

Link issue: open-telemetry#19175

Signed-off-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
Alex Boten committed Mar 17, 2023
1 parent 9d21c09 commit 0b74d4c
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 12 deletions.
16 changes: 16 additions & 0 deletions .chloggen/codeboten_doc-status.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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. filelogreceiver)
component: mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: use metadata to generate status table

# One or more tracking issues related to the change
issues: [19175]

# (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:
2 changes: 2 additions & 0 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ func (attr *attribute) Unmarshal(parser *confmap.Conf) error {
type metadata struct {
// Name of the component.
Name string `mapstructure:"name"`
// Status information for the component.
Status Status `mapstructure:"status"`
// SemConvVersion is a version number of OpenTelemetry semantic conventions applied to the scraped metrics.
SemConvVersion string `mapstructure:"sem_conv_version"`
// ResourceAttributes that can be emitted by the component.
Expand Down
36 changes: 36 additions & 0 deletions cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func run(ymlPath string) error {
filepath.Join(codeDir, "generated_metrics.go"), md); err != nil {
return err
}
if len(md.Status.Stability) > 0 {
if err = generateFile(filepath.Join(tmplDir, "status.go.tmpl"),
filepath.Join(codeDir, "generated_status.go"), md); err != nil {
return err
}
}
if err = generateFile(filepath.Join(tmplDir, "testdata", "config.yaml.tmpl"),
filepath.Join(codeDir, "testdata", "config.yaml"), md); err != nil {
return err
Expand Down Expand Up @@ -99,6 +105,36 @@ func generateFile(tmplFile string, outputFile string, md metadata) error {
},
"stringsJoin": strings.Join,
"inc": func(i int) int { return i + 1 },
"stability": func(in string) string {
switch in {
case "alpha":
return "Alpha"
case "beta":
return "Beta"
case "unmaintained":
return "Unmaintained"
case "deprecated":
return "Deprecated"
case "development":
return "Development"
case "stable":
return "Stable"
}
return "Undefined"
},
"distroJoin": func(d []Distribution, sep string) string {
if len(d) == 1 {
return d[0].Name
}
output := ""
for idx, distro := range d {
if idx > 0 {
output += sep
}
output += distro.Name
}
return output
},
// ParseFS delegates the parsing of the files to `Glob`
// which uses the `\` as a special character.
// Meaning on windows based machines, the `\` needs to be replaced
Expand Down
27 changes: 27 additions & 0 deletions cmd/mdatagen/statusdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

type Distribution struct {
Name string `mapstructure:"name"`
URL string `mapstructure:"url"`
}

type Status struct {
Stability string `mapstructure:"stability"`
Pipelines []string `mapstructure:"pipelines"`
Distributions []Distribution `mapstructure:"distributions"`
Type string `mapstructure:"type"`
}
14 changes: 13 additions & 1 deletion cmd/mdatagen/templates/documentation.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# {{ .Name }}

{{if ne .Status.Stability "" }}
| Status | |
| ------------------------ |-----------|
| Stability | [{{ .Status.Stability }}] |
| Supported pipeline types | {{range .Status.Pipelines }}{{.}},{{end}} |
| Distributions | [{{ distroJoin .Status.Distributions "], [" }}] |
{{ end }}
## Default Metrics

The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:
Expand Down Expand Up @@ -91,3 +97,9 @@ metrics:
{{- end }}

{{- end }}
{{if ne .Status.Stability "" }}
[{{ .Status.Stability }}]: https://github.com/open-telemetry/opentelemetry-collector#{{ .Status.Stability }}
{{range .Status.Distributions }}
[{{.Name}}]: {{.URL}}
{{end}}
{{- end -}}
9 changes: 9 additions & 0 deletions cmd/mdatagen/templates/status.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by mdatagen. DO NOT EDIT.

package {{ .Package }}

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

const Stability = component.StabilityLevel{{ stability .Status.Stability }}
9 changes: 1 addition & 8 deletions receiver/haproxyreceiver/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# HAProxy Receiver

| Status | |
| ------------------------ |-----------|
| Stability | [alpha] |
| Supported pipeline types | metrics |
| Distributions | [contrib] |
Component [status](./documentation.md#haproxyreceiver).

The HAProxy receiver generates metrics by polling periodically the HAProxy process through a dedicated socket or HTTP URL.

Expand Down Expand Up @@ -50,6 +46,3 @@ receivers:
haproxy.requests:
enabled: true
```
[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
10 changes: 10 additions & 0 deletions receiver/haproxyreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# haproxyreceiver

| Status | |
| ------------------------ |-----------|
| Stability | [alpha] |
| Supported pipeline types | metrics, |
| Distributions | [contrib] |

## Default Metrics

The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:
Expand Down Expand Up @@ -249,3 +255,7 @@ Cumulative number of sessions. Corresponds to HAProxy's `stot` metric.
| haproxy.url | The path to the HAProxy socket or HTTP URL. | Any Str | true |
| proxy_name | Proxy name | Any Str | false |
| service_name | Service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener) | Any Str | false |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha

[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
5 changes: 2 additions & 3 deletions receiver/haproxyreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ import (
)

const (
typeStr = "haproxy"
stability = component.StabilityLevelAlpha
typeStr = "haproxy"
)

// NewFactory creates a new HAProxy receiver factory.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
typeStr,
newDefaultConfig,
receiver.WithMetrics(newReceiver, stability))
receiver.WithMetrics(newReceiver, metadata.Stability))
}

func newDefaultConfig() component.Config {
Expand Down

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

8 changes: 8 additions & 0 deletions receiver/haproxyreceiver/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: haproxyreceiver

status:
type: receiver
stability: alpha
pipelines: [metrics]
distributions:
- name: contrib
url: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib

resource_attributes:
haproxy.url:
description: The path to the HAProxy socket or HTTP URL.
Expand Down

0 comments on commit 0b74d4c

Please sign in to comment.