-
Notifications
You must be signed in to change notification settings - Fork 291
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
WIP: Autogenerate Telegraf docs from influxdata/telegraf repo. #5656
Draft
jstirnaman
wants to merge
2
commits into
master
Choose a base branch
from
automate-telegraf-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 @@ | ||
Build Telegraf documentation from https://github.com/influxdata/telegraf |
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,180 @@ | ||
#!/bin/bash | ||
|
||
# Determine the root project directory | ||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
|
||
# If the Telegraf repo isn't already cloned in ./external, clone it | ||
|
||
if [ ! -d "$ROOT_DIR/external/telegraf" ]; then | ||
git clone https://github.com/influxdata/telegraf.git "$ROOT_DIR/external/telegraf" | ||
fi | ||
# Update the external repository | ||
cd "$ROOT_DIR/external/telegraf" | ||
git pull origin master | ||
|
||
# Function to create a Hugo page | ||
create_page() { | ||
local dest_dir=$1 | ||
local dest_file="$dest_dir/_index.md" | ||
local content=$2 | ||
|
||
mkdir -p "$dest_dir" | ||
echo "$content" > "$dest_file" | ||
} | ||
|
||
# Function to copy README.md content to _index.md | ||
copy_readme() { | ||
local plugin_dir=$1 | ||
local src_readme="$plugin_dir/README.md" | ||
local dest_dir=$2 | ||
local dest_file="$dest_dir/_index.md" | ||
|
||
# If src_readme doesn't exist, then return an error | ||
if [ ! -f "$src_readme" ]; then | ||
echo "README.md not found in $plugin_dir" | ||
return 1 | ||
fi | ||
# If $dest_file doesn't exist, then return an error | ||
if [ ! -f "$dest_file" ]; then | ||
echo "$dest_file not found" | ||
return 1 | ||
fi | ||
|
||
# Copy the README.md content to _index.md | ||
cat "$src_readme" >> "$dest_file" | ||
echo "Copied $src_readme to $dest_file" | ||
} | ||
|
||
# Semaphore function to limit concurrent processes | ||
semaphore() { | ||
local max_concurrent=$1 | ||
while [ "$(jobs -r | wc -l)" -ge "$max_concurrent" ]; do | ||
sleep 0.1 | ||
done | ||
} | ||
|
||
# Limit the number of concurrent processes | ||
MAX_CONCURRENT=5 | ||
|
||
# Function to generate frontmatter for input plugins | ||
input_plugin_frontmatter() { | ||
local plugin_name=$1 | ||
|
||
cat <<EOF | ||
--- | ||
description: "Telegraf plugin for collecting metrics from $plugin_name" | ||
menu: | ||
telegraf_v1_ref: | ||
parent: input_plugins_reference | ||
name: $plugin_name | ||
identifier: "$plugin_name-input-plugin" | ||
tags: [$plugin_name, "input-plugins", "configuration"] | ||
related: | ||
- /telegraf/v1/configure_plugins/ | ||
--- | ||
|
||
EOF | ||
} | ||
|
||
# Function to generate frontmatter for output plugins | ||
output_plugin_frontmatter() { | ||
local plugin_name=$1 | ||
|
||
cat <<EOF | ||
--- | ||
description: "Telegraf plugin for sending metrics to $plugin_name" | ||
menu: | ||
telegraf_v1_ref: | ||
parent: output_plugins_reference | ||
name: $plugin_name | ||
identifier: "$plugin_name-output-plugin" | ||
tags: [$plugin_name, "output-plugins", "configuration"] | ||
related: | ||
- /telegraf/v1/configure_plugins/ | ||
--- | ||
|
||
EOF | ||
} | ||
|
||
# Build function to create pages and copy README.md files | ||
build() { | ||
local src_dir=$1 | ||
local dest_dir=$2 | ||
local frontmatter_func=$3 | ||
local main_frontmatter=$4 | ||
|
||
# Create the main index file for plugins | ||
echo "$main_frontmatter" > "$dest_dir/_index.md" | ||
|
||
for plugin_dir in "$src_dir"/*; do | ||
# If the directory name is "all", then skip it | ||
if [ "$(basename "$plugin_dir")" == "all" ]; then | ||
continue | ||
fi | ||
local plugin_name=$(basename "$plugin_dir") | ||
local plugin_dest_dir=$dest_dir/$plugin_name | ||
if [ -d "$plugin_dir" ]; then | ||
semaphore "$MAX_CONCURRENT" | ||
( | ||
local frontmatter=$($frontmatter_func "$plugin_name") | ||
create_page "$plugin_dest_dir" "$frontmatter" | ||
copy_readme "$plugin_dir" "$plugin_dest_dir" | ||
) & | ||
fi | ||
done | ||
|
||
# Wait for all background jobs to finish | ||
wait | ||
} | ||
|
||
# Configuration for input plugins | ||
SRC_DIR_INPUT="$ROOT_DIR/external/telegraf/plugins/inputs" | ||
DEST_DIR_INPUT="$ROOT_DIR/content/telegraf/v1/input-plugins" | ||
FRONTMATTER_FUNC_INPUT="input_plugin_frontmatter" | ||
MAIN_FRONTMATTER_INPUT=$(cat <<EOF | ||
--- | ||
title: "Telegraf Input Plugins" | ||
description: "Telegraf input plugins collect metrics from the system, services, and third-party APIs." | ||
menu: | ||
telegraf_v1_ref: | ||
name: Input plugins | ||
identifier: input_plugins_reference | ||
weight: 10 | ||
tags: [input-plugins] | ||
--- | ||
|
||
Telegraf input plugins collect metrics from the system, services, and third-party APIs. | ||
|
||
{{< children >}} | ||
|
||
EOF | ||
) | ||
|
||
# Run the build function for input plugins | ||
build "$SRC_DIR_INPUT" "$DEST_DIR_INPUT" "$FRONTMATTER_FUNC_INPUT" "$MAIN_FRONTMATTER_INPUT" | ||
|
||
# Configuration for output plugins | ||
SRC_DIR_OUTPUT="$ROOT_DIR/external/telegraf/plugins/outputs" | ||
DEST_DIR_OUTPUT="$ROOT_DIR/content/telegraf/v1/output-plugins" | ||
FRONTMATTER_FUNC_OUTPUT="output_plugin_frontmatter" | ||
MAIN_FRONTMATTER_OUTPUT=$(cat <<EOF | ||
--- | ||
title: "Telegraf Output Plugins" | ||
description: "Telegraf output plugins send metrics to various destinations." | ||
menu: | ||
telegraf_v1_ref: | ||
name: Output plugins | ||
identifier: output_plugins_reference | ||
weight: 20 | ||
tags: [output-plugins] | ||
--- | ||
|
||
Telegraf output plugins send metrics to various destinations. | ||
|
||
{{< children >}} | ||
|
||
EOF | ||
) | ||
|
||
# Run the build function for output plugins | ||
build "$SRC_DIR_OUTPUT" "$DEST_DIR_OUTPUT" "$FRONTMATTER_FUNC_OUTPUT" "$MAIN_FRONTMATTER_OUTPUT" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you'll iterate over the page data to do something here?