feat(slo): introduce SLO templates API#246778
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces two new internal API endpoints for SLO templates: GET /api/observability/slo_templates/{templateId} to retrieve a single template and GET /api/observability/slo_templates to search/find templates with filtering and pagination support. The implementation includes a new repository layer for accessing SLO template saved objects, comprehensive validation and filtering logic to handle partial or invalid templates, and extensive test coverage with edge cases.
Key changes:
- New SLO template repository with validation and filtering of stored templates
- Two REST API endpoints with pagination, search, and tag filtering capabilities
- Comprehensive test suites covering valid, partial, invalid, and edge-case scenarios
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
slo_api.ts |
Adds test helper methods getTemplate and findTemplates; relocates existing helper methods |
index.ts |
Registers new test files for template endpoints |
get_slo_template.ts |
Comprehensive tests for GET single template endpoint covering valid, partial, invalid, and error cases |
find_slo_templates.ts |
Extensive tests for find/search endpoint including pagination, search, tag filtering, and validation errors |
slo_template_repository.ts |
Implements repository with field-level validation and filtering logic for stored templates |
slo_template.ts |
Updates saved object type definition with safer type checking for template name |
types.ts |
Adds SLOTemplateRepository to scoped clients interface |
slo_templates.ts |
Implements two route handlers with platinum license check and parameter validation |
route.ts |
Registers new template routes in route repository |
create_slo_server_route.ts |
Adds error handling for SLOTemplateNotFound error type |
plugin.ts |
Instantiates template repository and includes it in scoped clients |
errors.ts |
Defines new SLOTemplateNotFound error class |
slo_template.ts (domain) |
Updates type definitions to use new schema types |
index.ts (domain) |
Updates export to use renamed template type file |
slo_template.ts (schema) |
Defines template schema with all fields optional and stored template as unknown record |
slo.ts (schema) |
Removes old template schema definition |
index.ts (schema) |
Exports new template schema |
slo_templates.ts (rest_specs) |
Defines parameter schemas and response types for both endpoints |
index.ts (rest_specs) |
Exports template route specifications |
| @@ -0,0 +1,83 @@ | |||
| /* | |||
There was a problem hiding this comment.
💬 Decided to not create application services for these route handlers since the orchestration logic is very simple.
| @@ -0,0 +1,350 @@ | |||
| /* | |||
There was a problem hiding this comment.
🤖-generated, 👨🏻-reviewed
| @@ -0,0 +1,362 @@ | |||
| /* | |||
There was a problem hiding this comment.
🤖-generated, 👨🏻-reviewed
|
Pinging @elastic/actionable-obs-team (Team:actionable-obs) |
baileycash-elastic
left a comment
There was a problem hiding this comment.
Looks good, small question:
We have validation here for pagination, will the same checks be applied to the existing SLO find service?
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
cc @kdelemme |
We should already have some validation for the find slo service, if some are missing we can always add them for sure. Would be nice to leverage |
dmlemeshko
left a comment
There was a problem hiding this comment.
x-pack/solutions/observability/test/api_integration_deployment_agnostic/services/slo_api.ts changes LGTM
Resolves #246779
Pre-requisite for #245854
Summary
This PR introduces two new internal routes and a new repository for the new SLOTemplate saved objects.
The routes can be used to fetch a specific SLOTemplate from its id, or search through them (search on name, filter on tags).
Integration tests have been added to make sure we are able to construct a valid SLO Template based on partially stored object.
Note
Expectation from reviewer is a code review. Manual testing can be done, but you will have to follow the instructions from #245903. You can always call the API without having any slo templates.