@cryptotaxi247 / netdata-1 / commits / 66b8a7a4b

chore: add `-c` option to gen docs for a single collector (#20981)

Ilya Mashchenko committed Sep 15, 2025 at 08:25 UTC 66b8a7a4be90059e20d6260777f758ff9d063672
1 file changed +52 -2
integrations/gen_docs_integrations.py
+52 -2
@@ -1,16 +1,26 @@
1 +import argparse
2 import json
3 import re
4 import shutil
5 +import sys
6 from pathlib import Path
7
8 # Dictionary responsible for making the symbolic links at the end of the script's run.
9 symlink_dict = {}
10
11
10 -def cleanup():
12 +def cleanup(only_base_paths=None):
13 """
14 clean directories that are either data collection or exporting integrations
15 + If only_base_paths is provided (list of base dirs), clean ONLY those.
16 """
17 + if only_base_paths:
18 + for base in only_base_paths:
19 + p = Path(base) / "integrations"
20 + if p.exists():
21 + shutil.rmtree(p)
22 + return
23 +
24 for element in Path("src/go/plugin/go.d/collector").glob('**/*/'):
25 if "integrations" in str(element):
26 shutil.rmtree(element)
@@ -523,12 +533,52 @@ def make_symlinks(symlink_dict):
533 f'{element}/{symlink_dict[element]}', f'{element}/README.md'))
534
535
526 -cleanup()
536 +parser = argparse.ArgumentParser(description="Generate integration docs from metadata.yaml files.")
537 +parser.add_argument("-c", "--collector",
538 + help="Only generate docs for this collector (plugin/module), e.g. 'go.d/snmp' or 'apps.plugin/groups'",
539 + default=None)
540 +args = parser.parse_args()
541
542 categories, integrations = read_integrations_js('integrations/integrations.js')
543
544 +
545 +def _base_paths_for_collector(integrations, collector_key):
546 + if not collector_key:
547 + return []
548 + paths = []
549 + for integ in integrations:
550 + if integ.get('integration_type') != 'collector':
551 + continue
552 + meta = integ.get('meta', {})
553 + plugin = meta.get('plugin_name')
554 + module = meta.get('module_name')
555 + if not plugin or not module:
556 + continue
557 + key = plugin + "/" + module
558 + if key == collector_key:
559 + meta_yaml = integ.get('edit_link', '').replace("blob", "edit")
560 + paths.append(build_path(meta_yaml))
561 + return paths
562 +
563 +
564 +only_paths = _base_paths_for_collector(integrations, args.collector)
565 +
566 +if args.collector and not only_paths:
567 + print("No matching collector found for:", args.collector)
568 + sys.exit(1)
569 +
570 +cleanup(only_paths)
571 +
572 # Iterate through every integration
573 for integration in integrations:
574 + if args.collector:
575 + if integration.get('integration_type') != "collector":
576 + continue
577 + meta = integration.get('meta', {})
578 + plugin = meta.get('plugin_name')
579 + module = meta.get('module_name')
580 + if not plugin or not module or (plugin + "/" + module) != args.collector:
581 + continue
582
583 if integration['integration_type'] == "collector":
584