Skip to content

add 'alertRuleTemplates' function to readme generation#3076

Merged
tommyers-elastic merged 16 commits intoelastic:mainfrom
tommyers-elastic:alert-rule-template-docs
Nov 25, 2025
Merged

add 'alertRuleTemplates' function to readme generation#3076
tommyers-elastic merged 16 commits intoelastic:mainfrom
tommyers-elastic:alert-rule-template-docs

Conversation

@tommyers-elastic
Copy link
Contributor

This provides the ability to auto-render alert rule templates in integration readmes.

@tommyers-elastic tommyers-elastic changed the title add 'alertRuleTemplate' function to readme generation add 'alertRuleTemplates' function to readme generation Nov 13, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds functionality to auto-render alert rule templates in integration README files. The implementation introduces a new template function alertRuleTemplates that can be used in README templates to automatically generate documentation for Kibana alert rule templates.

Key Changes

  • Added alertRuleTemplates template function to the README generation system with optional tech preview flag support
  • Implemented template scanning and rendering from kibana/alerting_rule_template directory
  • Auto-generates markdown documentation with template names and descriptions

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/docs/alert_rule_template.go New file implementing the alert rule template rendering logic with directory walking and JSON parsing
internal/docs/readme.go Registers the new alertRuleTemplates template function in the README rendering system

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


builder.WriteString(`Alert rule templates provide pre-defined configurations for creating alert rules in Kibana.

For more information, see the [Elastic documentation](https://www.elastic.co/docs/reference/fleet/alert-templates#alert-templates).
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The documentation URL https://www.elastic.co/docs/reference/fleet/alert-templates#alert-templates appears to use an unusual format. Elastic documentation typically uses URLs like https://www.elastic.co/guide/en/fleet/{version}/... rather than /docs/reference/. Please verify this URL is correct and will be accessible to users.

Suggested change
For more information, see the [Elastic documentation](https://www.elastic.co/docs/reference/fleet/alert-templates#alert-templates).
For more information, see the [Elastic documentation](https://www.elastic.co/guide/en/fleet/current/alert-templates.html).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the correct url. i don't like hard coding the URL here, but not sure what else to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use linkMap.RenderLink(), and rely on the links_table.yml file. But this should still need to have a fallback in case the file doesn't exist or it doesn't contain the expected url.

There is a linkMap already initialized in renderReadme, you could pass it to renderAlertRuleTemplates.

templatesDir := filepath.Join(packageRoot, "kibana", "alerting_rule_template")

var builder strings.Builder
if techPreview {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @daniela-elastic, please can you review the preamble content here (lines 26-40).

this is the text that will appear before the list of templates in the readme.

we currently link to the existing docs page, which needs improving, but i think it's the right place long term.

builder.WriteString("**Tech Preview:** Alert rule templates are in tech preview and may be changed or removed in future releases.\n\n")
}

builder.WriteString(`Alert rule templates provide pre-defined configurations for creating alert rules in Kibana.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention that these are templates that you can use to easily create and customize alerts. But are not live alerts in and of themselves.? Something along the lines of "Alert rule templates provide pre-defined best practice configurations that you can use to easily create alert rules in Kibana."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to take your version. i think it says pretty much the same thing.

i think we should avoid putting more detail about how these are used in the package readmes, and leave that for the shared docs page that's linked below.


For more information, see the [Elastic documentation](https://www.elastic.co/docs/reference/fleet/alert-templates#alert-templates).

Alert rule templates require Elastic Stack version 9.2.0 or later.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if it's worth mentioning that you can create an alert based on the recommended configuration in the documentation regardless of the stack version. Ultimately, the main ingredients you need are the threshold. and other rule config - things that exist in all recent versions of the stack. The only thing you cannot do with pre 9.2 is the ability to see the alert rule asset in the asset tab of the integration, click on it and the alert rule is prepopulated with the config. But the hard part, or rather the are where we help the user the most is with the actual content - they don't have to go and do their own research to figure out which metrics to alert on and with what config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this kind of generic information probable belongs on the docs website, not in the package itself.

Copy link

@daniela-elastic daniela-elastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved in principle but please consider the content suggestions I've made

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Avoid using underscores in Go file or package names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i followed the existing convention in the repo on this.

Image


builder.WriteString(`Alert rule templates provide pre-defined configurations for creating alert rules in Kibana.

For more information, see the [Elastic documentation](https://www.elastic.co/docs/reference/fleet/alert-templates#alert-templates).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use linkMap.RenderLink(), and rely on the links_table.yml file. But this should still need to have a fallback in case the file doesn't exist or it doesn't contain the expected url.

There is a linkMap already initialized in renderReadme, you could pass it to renderAlertRuleTemplates.

Copy link
Contributor

@alaudazzi alaudazzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor suggestion.

Co-authored-by: Arianna Laudazzi <46651782+alaudazzi@users.noreply.github.com>
@tommyers-elastic
Copy link
Contributor Author

You could use linkMap.RenderLink(), and rely on the links_table.yml file. But this should still need to have a fallback in case the file doesn't exist or it doesn't contain the expected url.

There is a linkMap already initialized in renderReadme, you could pass it to renderAlertRuleTemplates.

fixed in 2a461f4

Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Added some comments and questions.

Comment on lines +104 to +105
setupFunc: func(t *testing.T) string {
tmpDir := t.TempDir()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, should these functions (setupFunc and validateFunc) add t.Helper() ?

tommyers-elastic and others added 2 commits November 24, 2025 14:49
Co-authored-by: Mario Rodriguez Molins <marrodmo@gmail.com>
Co-authored-by: Mario Rodriguez Molins <marrodmo@gmail.com>
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@tommyers-elastic tommyers-elastic merged commit 99b5b45 into elastic:main Nov 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants