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

feat(tools/readme_linter): Check for global configuration section #12426

Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/tools/package_lxd_test/package_lxd_test
/tools/license_checker/license_checker*
/tools/readme_config_includer/generator*
/tools/readme_linter/readme_linter*
/tools/custom_builder/custom_builder*
/vendor
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion docs/includes/plugin_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.

[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
Hipska marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions plugins/inputs/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.

[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins

## Configuration

Expand Down Expand Up @@ -75,13 +75,13 @@ SELECT max(field1), mean(field1), min(field1) FROM measurement1 WHERE tag1=bar A
This optional section can provide basic troubleshooting steps that a user can
perform.

## Example
## Example Output

This section shows example output in Line Protocol format. You can often use
`telegraf --input-filter <plugin-name> --test` or use the `file` output to get
this information.

```shell
```text
measurement1,tag1=foo,tag2=bar field1=1i,field2=2.1 1453831884664956455
measurement2,tag1=foo,tag2=bar,tag3=baz field3=1i 1453831884664956455
```
9 changes: 9 additions & 0 deletions plugins/inputs/netflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Definitions for IPFIX are according to [IANA assignement document][IPFIX doc].
[ASA extensions]: https://www.cisco.com/c/en/us/td/docs/security/asa/special/netflow/asa_netflow.html
[IPFIX doc]: https://www.iana.org/assignments/ipfix/ipfix.xhtml#ipfix-nat-type

## Global configuration options <!-- @/docs/includes/plugin_config.md -->

In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.

[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins

## Configuration

```toml @sample.conf
Expand Down
30 changes: 26 additions & 4 deletions tools/readme_linter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var rules rulesMap
func init() {
rules = make(rulesMap)

//rules for all plugin types
// Rules for all plugin types
all := []ruleFunc{
firstSection,
noLongLinesInParagraphs(80),
Expand All @@ -54,13 +54,35 @@ func init() {
rules[i] = all
}

inputRules := []ruleFunc{
// Rules for input plugins
rules[pluginInput] = append(rules[pluginInput], []ruleFunc{
requiredSectionsClose([]string{
"Example Output",
"Metrics",
"Global configuration options",
}),
}
rules[pluginInput] = append(rules[pluginInput], inputRules...)
}...)

// Rules for output plugins
rules[pluginOutput] = append(rules[pluginOutput], []ruleFunc{
requiredSectionsClose([]string{
"Global configuration options",
}),
}...)

// Rules for processor pluings
rules[pluginProcessor] = append(rules[pluginProcessor], []ruleFunc{
requiredSectionsClose([]string{
"Global configuration options",
}),
}...)

// Rules for aggregator pluings
rules[pluginAggregator] = append(rules[pluginAggregator], []ruleFunc{
requiredSectionsClose([]string{
"Global configuration options",
}),
}...)
}

func checkFile(filename string, pluginType plugin, sourceFlag bool) (bool, error) {
Expand Down
8 changes: 4 additions & 4 deletions tools/readme_linter/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func requiredSections(t *T, root ast.Node, headings []string) error {
if child == nil {
continue
}
title := string(child.Text(t.markdown))
title := strings.TrimSpace(string(child.Text(t.markdown)))
if headingsSet.has(title) && h.Level != expectedLevel {
t.assertNodef(n, "has required section '%s' but wrong heading level. Expected level %d, found %d",
t.assertNodef(n, "has required section %q but wrong heading level. Expected level %d, found %d",
title, expectedLevel, h.Level)
}

Expand All @@ -63,7 +63,7 @@ func requiredSections(t *T, root ast.Node, headings []string) error {

headingsSet.forEach(func(title string) {
if _, exists := titleCounts[title]; !exists {
t.assertf("missing required section '%s'", title)
t.assertf("missing required section %q", title)
}
})

Expand Down Expand Up @@ -157,7 +157,7 @@ func configSection(t *T, root ast.Node) error {
}

if config == nil {
t.assertf("missing section '%s'", expectedTitle)
t.assertf("missing required section %q", expectedTitle)
return nil
}

Expand Down