docs: fix COLLECTORS.md generation (#21228)
Ilya Mashchenko committed
Oct 28, 2025 at 15:03 UTC
aa9a2cc5efde0176e8cc64028124b3791b3f4d36
1 file changed
+8
-14
integrations/gen_doc_collector_page.py
+8
-14
@@ -388,20 +388,14 @@ def main() -> None:
388
md = header + "## Available Data Collection Integrations\n\n" + tables
389
390
outfile = pathlib.Path("./src/collectors/COLLECTORS.md")
391
- txt = outfile.read_text(encoding='utf-8')
392
-
393
- # Find the start of the content to replace
394
- if "## Available Data Collection Integrations" in txt:
395
- pre = txt.split("## Available Data Collection Integrations")[0]
396
- elif "# Monitor anything with Netdata" in txt:
397
- # If the header exists, keep only what's before it
398
- pre = txt.split("# Monitor anything with Netdata")[0]
399
- else:
400
- # Otherwise keep everything before the marker
401
- pre = txt.split("## Add your application to Netdata")[0] if "## Add your application to Netdata" in txt else ""
402
-
403
- new_txt = pre.rstrip() + "\n\n" + md
404
- outfile.write_text(new_txt.rstrip('\n') + "\n", encoding='utf-8')
391
+
392
+ outfile.parent.mkdir(parents=True, exist_ok=True)
393
+
394
+ # Always overwrite the file with freshly generated content (no partial preserves)
395
+ # Write atomically to avoid partial writes
396
+ tmp = outfile.with_suffix(outfile.suffix + ".tmp")
397
+ tmp.write_text(md.rstrip('\n') + "\n", encoding='utf-8')
398
+ tmp.replace(outfile)
399
400
401
if __name__ == '__main__':