Skip to content

Add time_slice SLO type support#2701

Open
cedi wants to merge 3 commits intoDataDog:mainfrom
cedi:cedi/add-time-slice-slo-support
Open

Add time_slice SLO type support#2701
cedi wants to merge 3 commits intoDataDog:mainfrom
cedi:cedi/add-time-slice-slo-support

Conversation

@cedi
Copy link
Copy Markdown

@cedi cedi commented Mar 4, 2026

What does this PR do?

Adds support for Datadog Time Slice SLOs alongside the existing metric and monitor SLO types.

Time Slice SLOs use an SLI specification with a metric query, a comparator, and a threshold to determine what counts as good uptime in each time window. This is modeled as a new timeSlice field on DatadogSLOSpec, following the existing pattern where each SLO type has its own dedicated payload field (query for metric, monitorIDs for monitor, timeSlice for time_slice).

The API is designed for simplicity: the user provides a single metric query string, and the operator auto-generates the named query (query1) and formula (query1) when building the Datadog API request — matching the ergonomics of metric SLOs where users provide one query and the operator handles the rest.

Example CR:

spec:
  type: time_slice
  name: my-service-availability
  timeSlice:
    query: "trace.servlet.request{env:prod}"
    comparator: ">"
    threshold: "5"
  timeframe: 7d
  targetThreshold: "97"

Motivation

The Datadog API supports three SLO types: metric, monitor, and time_slice. The operator previously only supported metric and monitor. Time Slice SLOs are useful for monitoring uptime based on SLI thresholds evaluated per time window, which is a common pattern for service availability targets.

Additional Notes

  • The DataSource is intentionally omitted from the CRD and hardcoded to "metrics" in the API mapping, since Datadog only supports metric data sources for time_slice SLOs.
  • The Comparator field is a kubebuilder-validated enum (>, >=, <, <=), rejected at admission time if invalid.
  • Cross-field validation ensures users cannot combine incompatible fields (e.g., timeSlice with type: metric, or query with type: time_slice).
  • All existing metric and monitor SLO behavior is unchanged — new types and code paths are purely additive.

Minimum Agent Versions

No minimum agent version required. This change only affects the operator's interaction with the Datadog API.

  • Agent: N/A
  • Cluster Agent: N/A

Describe your test plan

  • Unit tests for validation (datadogslo_validation_test.go): 7 test cases covering valid time_slice spec, missing TimeSlice field, empty query, and all cross-field rejection combinations.
  • Unit tests for API mapping (slo_test.go): buildSLO test cases covering metric, monitor, and time_slice — verifying the full SDK object construction including hardcoded data source and auto-generated query/formula names.
  • All existing tests continue to pass unchanged.

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed (see: signing commits)

@cedi cedi requested a review from a team March 4, 2026 11:33
@cedi cedi requested review from a team as code owners March 4, 2026 11:33
Add support for Datadog Time Slice SLOs alongside the existing metric
and monitor SLO types. Time Slice SLOs use an SLI specification with
metric queries, formulas, a comparator, and a threshold to determine
what counts as good uptime in each time slice.

- Add DatadogSLOTypeTimeSlice and related CRD types (DatadogSLOTimeSlice,
  DatadogSLOFormula, DatadogSLODataSourceQuery, DatadogSLOTimeSliceComparator)
- Add TimeSlice field to DatadogSLOSpec following the existing pattern
  where each SLO type has its own dedicated payload field
- Add validation for time_slice specs including cross-field rejection
  to prevent invalid type/field combinations
- Add buildSliSpecification() mapping to the datadogV1 SDK types with
  hardcoded metrics data source
- Add comprehensive unit tests for validation and API mapping
- Regenerate CRDs and deepcopy/openapi code
@cedi cedi force-pushed the cedi/add-time-slice-slo-support branch from 6ce7bb9 to 7fcdc8e Compare March 4, 2026 11:49
@gabedos gabedos added the enhancement New feature or request label Mar 11, 2026
@gabedos gabedos added this to the v1.26.0 milestone Mar 11, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.90%. Comparing base (7fae85c) to head (0f8996a).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2701      +/-   ##
==========================================
+ Coverage   38.80%   38.90%   +0.10%     
==========================================
  Files         309      309              
  Lines       26750    26775      +25     
==========================================
+ Hits        10379    10416      +37     
+ Misses      15592    15586       -6     
+ Partials      779      773       -6     
Flag Coverage Δ
unittests 38.90% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/controller/datadogslo/slo.go 80.58% <100.00%> (+21.60%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fae85c...0f8996a. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants