forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for markdown generation (#3100)
This change contains a CLI tool, called 'docsgen', that generates markdown files for collector components. The markdown files present the configuration metadata extracted by the `configschema` API in a human readable form that can be used to manually configure the collector. This change also makes some modifications to the package formerly knows as `schemagen`, renaming it to `configschema` and exporting some things, because it no longer generates a schema yaml file, but rather provides an equivalent API used by docsgen. Also, this PR includes one sample, generated .md document: `receiver/otlpreceiver/config.md`
- Loading branch information
Showing
24 changed files
with
1,182 additions
and
354 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ConfigSchema API | ||
|
||
This package contains an API that can be used to introspect the configuration | ||
struct of a collector component. It can be used to generate documentation or | ||
tools to help users configure the collector. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// 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 configschema | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config" | ||
) | ||
|
||
const ( | ||
receiver = "receiver" | ||
extension = "extension" | ||
processor = "processor" | ||
exporter = "exporter" | ||
) | ||
|
||
// CfgInfo contains a component config instance, as well as its group name and | ||
// type. | ||
type CfgInfo struct { | ||
// the name of the component group, e.g. "receiver" | ||
Group string | ||
// the component type, e.g. "otlpreceiver.Config" | ||
Type config.Type | ||
// an instance of the component's configuration struct | ||
CfgInstance interface{} | ||
} | ||
|
||
// GetAllCfgInfos accepts a Factories struct, then creates and returns a CfgInfo | ||
// for each of its components. | ||
func GetAllCfgInfos(components component.Factories) []CfgInfo { | ||
var out []CfgInfo | ||
for _, f := range components.Receivers { | ||
out = append(out, CfgInfo{ | ||
Type: f.Type(), | ||
Group: receiver, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}) | ||
} | ||
for _, f := range components.Extensions { | ||
out = append(out, CfgInfo{ | ||
Type: f.Type(), | ||
Group: extension, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}) | ||
} | ||
for _, f := range components.Processors { | ||
out = append(out, CfgInfo{ | ||
Type: f.Type(), | ||
Group: processor, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}) | ||
} | ||
for _, f := range components.Exporters { | ||
out = append(out, CfgInfo{ | ||
Type: f.Type(), | ||
Group: exporter, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}) | ||
} | ||
return out | ||
} | ||
|
||
// GetCfgInfo accepts a Factories struct, then creates and returns the default | ||
// config for the component specified by the passed-in componentType and | ||
// componentName. | ||
func GetCfgInfo(components component.Factories, componentType, componentName string) (CfgInfo, error) { | ||
t := config.Type(componentName) | ||
switch componentType { | ||
case receiver: | ||
f := components.Receivers[t] | ||
if f == nil { | ||
return CfgInfo{}, fmt.Errorf("unknown %s name %q", componentType, componentName) | ||
} | ||
return CfgInfo{ | ||
Type: f.Type(), | ||
Group: componentType, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}, nil | ||
case processor: | ||
f := components.Processors[t] | ||
if f == nil { | ||
return CfgInfo{}, fmt.Errorf("unknown %s name %q", componentType, componentName) | ||
} | ||
return CfgInfo{ | ||
Type: f.Type(), | ||
Group: componentType, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}, nil | ||
case exporter: | ||
f := components.Exporters[t] | ||
if f == nil { | ||
return CfgInfo{}, fmt.Errorf("unknown %s name %q", componentType, componentName) | ||
} | ||
return CfgInfo{ | ||
Type: f.Type(), | ||
Group: componentType, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}, nil | ||
case extension: | ||
f := components.Extensions[t] | ||
if f == nil { | ||
return CfgInfo{}, fmt.Errorf("unknown %s name %q", componentType, componentName) | ||
} | ||
return CfgInfo{ | ||
Type: f.Type(), | ||
Group: componentType, | ||
CfgInstance: f.CreateDefaultConfig(), | ||
}, nil | ||
} | ||
return CfgInfo{}, fmt.Errorf("unknown component type %q", componentType) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.