add 'alertRuleTemplates' function to readme generation#3076
add 'alertRuleTemplates' function to readme generation#3076tommyers-elastic merged 16 commits intoelastic:mainfrom
Conversation
There was a problem hiding this comment.
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
alertRuleTemplatestemplate function to the README generation system with optional tech preview flag support - Implemented template scanning and rendering from
kibana/alerting_rule_templatedirectory - 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.
internal/docs/alert_rule_template.go
Outdated
|
|
||
| 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). |
There was a problem hiding this comment.
[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.
| 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). |
There was a problem hiding this comment.
this is the correct url. i don't like hard coding the URL here, but not sure what else to do.
There was a problem hiding this comment.
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.
internal/docs/alert_rule_template.go
Outdated
| templatesDir := filepath.Join(packageRoot, "kibana", "alerting_rule_template") | ||
|
|
||
| var builder strings.Builder | ||
| if techPreview { |
There was a problem hiding this comment.
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.
internal/docs/alert_rule_template.go
Outdated
| 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. |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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.
internal/docs/alert_rule_template.go
Outdated
|
|
||
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
i think this kind of generic information probable belongs on the docs website, not in the package itself.
daniela-elastic
left a comment
There was a problem hiding this comment.
Approved in principle but please consider the content suggestions I've made
… it makes it less likely you render the preamble by mistake
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Nit. Avoid using underscores in Go file or package names.
internal/docs/alert_rule_template.go
Outdated
|
|
||
| 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). |
There was a problem hiding this comment.
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.
alaudazzi
left a comment
There was a problem hiding this comment.
Left a minor suggestion.
Co-authored-by: Arianna Laudazzi <46651782+alaudazzi@users.noreply.github.com>
fixed in 2a461f4 |
mrodm
left a comment
There was a problem hiding this comment.
LGTM
Added some comments and questions.
| setupFunc: func(t *testing.T) string { | ||
| tmpDir := t.TempDir() |
There was a problem hiding this comment.
I'm not sure, should these functions (setupFunc and validateFunc) add t.Helper() ?
Co-authored-by: Mario Rodriguez Molins <marrodmo@gmail.com>
Co-authored-by: Mario Rodriguez Molins <marrodmo@gmail.com>
💚 Build Succeeded
History
|

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