Skip to content

Conversation

matt-metivier
Copy link
Contributor

@matt-metivier matt-metivier commented Sep 5, 2025

This PR introduces a new Terraform resource for managing Asserts custom model rules, enabling users to define custom entity types and their detection rules using YAML configuration.

Changes

New Resource: grafana_asserts_custom_model_rules

  • Manages custom entity definitions through the Asserts CustomModelRulesControllerAPI
  • Supports flexible entity type configuration with Prometheus query-based detection
  • Implements full CRUD operations with proper retry logic for eventual consistency
  • Uses name-based resource identification for individual rule set management

Key Features

  • Entity type definition with custom names and types (Service, Pod, Namespace, etc.)
  • Prometheus query-based entity detection rules
  • Nested schema structure supporting multiple entities per rule set
  • Error handling and retry mechanisms

Technical Details

The resource implements proper retry logic using shared utilities to handle eventual consistency issues common with distributed systems. The implementation includes conversion functions between Terraform schema and API DTOs, ensuring proper data transformation and validation.

Testing

  • Unit tests validate all CRUD operations and data conversion
  • Acceptance tests verify resource lifecycle and state management
  • Stress tests confirm retry logic handles concurrent operations
  • Import functionality verified with proper state handling

Breaking Changes

None. This is a new resource addition with no impact on existing functionality.

@matt-metivier matt-metivier requested a review from a team as a code owner September 5, 2025 21:35
Copy link
Contributor

github-actions bot commented Sep 5, 2025

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch from 2355088 to a339fc4 Compare September 5, 2025 21:54
@CLAassistant
Copy link

CLAassistant commented Sep 5, 2025

CLA assistant check
All committers have signed the CLA.

@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch from 8137144 to dc9331d Compare September 5, 2025 22:02
Base automatically changed from asserts-update-dependencies to asserts-refactor-common-utilities September 5, 2025 22:23
@matt-metivier matt-metivier force-pushed the asserts-refactor-common-utilities branch from 9668de8 to e742667 Compare September 5, 2025 22:41
@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch from e1d0bb4 to 2fe501d Compare September 5, 2025 22:42
@matt-metivier matt-metivier force-pushed the asserts-refactor-common-utilities branch from e742667 to 4ea55ad Compare September 5, 2025 22:48
@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch from 2fe501d to f9c1ffc Compare September 5, 2025 22:49
Base automatically changed from asserts-refactor-common-utilities to main September 8, 2025 23:41
@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch 2 times, most recently from 6acbf8e to 7a37321 Compare September 11, 2025 18:38
feat(asserts): make custom model rules resource more Terraform native

- Replace YAML string with structured blocks for better UX
- Add conversion functions between Terraform blocks and API DTOs
- Update schema to use nested blocks (rules -> entity -> defined_by)
- Provide better IDE support, validation, and type safety
- Update tests, documentation, and examples to use new format
- Follow Terraform conventions similar to Kubernetes provider

This addresses the PR feedback from Alex3k to make the resource
more idiomatic and user-friendly while maintaining API compatibility.

test: add stress test flag to control eventual consistency tests

- Add CheckStressTestsEnabled function to testutils package
- Update all stress tests to require TF_ACC_STRESS environment variable
- Stress tests will now be skipped unless explicitly enabled
- This prevents flaky stress test failures in CI while still allowing
  developers to run them when needed for testing eventual consistency

feat(asserts): add custom model rules resource

- Add grafana_asserts_custom_model_rules resource for managing Asserts custom model rules
- Implement full CRUD operations with proper retry logic using shared utilities
- Add comprehensive tests including stress tests for eventual consistency
- Add documentation and usage examples
- Update catalog configuration for the new resource
- Register the new resource in the asserts resources list

This resource allows users to define custom entity types and their detection rules
using YAML configuration, enabling flexible monitoring model customization.
@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch from abb0ca5 to afcecc7 Compare September 11, 2025 20:36
@matt-metivier matt-metivier changed the title feat(asserts): add custom model rules resource 4658 add custom model rules resource Sep 11, 2025
@matt-metivier matt-metivier changed the title 4658 add custom model rules resource 4658:add custom model rules resource Sep 11, 2025
@matt-metivier matt-metivier force-pushed the asserts-custom-model-rules branch from 9531ad4 to e262306 Compare September 16, 2025 18:28
@matt-metivier matt-metivier enabled auto-merge (squash) September 24, 2025 13:16
@matt-metivier matt-metivier merged commit 0a50ebd into main Sep 24, 2025
31 checks passed
@matt-metivier matt-metivier deleted the asserts-custom-model-rules branch September 24, 2025 14:28
Copy link

@jgehrett jgehrett left a comment

Choose a reason for hiding this comment

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

Looking good! Sorry I'm late to the party. Just a small comment on enriched_by doc

Optional:

- `disabled` (Boolean) Whether this entity is disabled.
- `enriched_by` (List of String) List of enrichment sources for the entity.

Choose a reason for hiding this comment

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

enriched_by has the same schema as defined_by.
It's a PropertyRule

"enriched_by": {
Type: schema.TypeList,
Optional: true,
Description: "List of enrichment sources for the entity.",

Choose a reason for hiding this comment

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

I think this should be similar to defined_by.
Something like:
List of queries that enrich entities of this type.

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.

5 participants