Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11902,10 +11902,10 @@ components:
type: object
SLOCountDefinition:
description: 'A count-based (metric) SLI specification, composed of three parts:
the good events formula, the total events formula,

and the underlying queries.'
the good events formula, the bad or total events formula, and the underlying
queries.'
example:
bad_events_formula: query2
good_events_formula: query1 - query2
queries:
- data_source: metrics
Expand All @@ -11914,8 +11914,11 @@ components:
- data_source: metrics
name: query2
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
total_events_formula: query1
properties:
bad_events_formula:
$ref: '#/components/schemas/SLOFormula'
description: The bad events formula (recommended). Alternatively, total
events can be defined by the `total_events_formula` field instead.
good_events_formula:
$ref: '#/components/schemas/SLOFormula'
queries:
Expand All @@ -11929,16 +11932,18 @@ components:
type: array
total_events_formula:
$ref: '#/components/schemas/SLOFormula'
description: '"The total events formula. Alternatively, bad events can be
defined by the `bad_events_formula` field instead.'
required:
- good_events_formula
- total_events_formula
- queries
type: object
SLOCountSpec:
additionalProperties: false
description: A metric SLI specification.
example:
count:
bad_events_formula: query2
good_events_formula: query1 - query2
queries:
- data_source: metrics
Expand All @@ -11947,7 +11952,6 @@ components:
- data_source: metrics
name: query2
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
total_events_formula: query1
properties:
count:
$ref: '#/components/schemas/SLOCountDefinition'
Expand Down
76 changes: 76 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_707861409.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Create a new metric SLO object using bad events formula returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.ServiceLevelObjectivesApi;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricDataSource;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricQueryDefinition;
import com.datadog.api.client.v1.model.SLOCountDefinition;
import com.datadog.api.client.v1.model.SLOCountSpec;
import com.datadog.api.client.v1.model.SLODataSourceQueryDefinition;
import com.datadog.api.client.v1.model.SLOFormula;
import com.datadog.api.client.v1.model.SLOListResponse;
import com.datadog.api.client.v1.model.SLOSliSpec;
import com.datadog.api.client.v1.model.SLOThreshold;
import com.datadog.api.client.v1.model.SLOTimeframe;
import com.datadog.api.client.v1.model.SLOType;
import com.datadog.api.client.v1.model.ServiceLevelObjectiveRequest;
import java.util.Arrays;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
ServiceLevelObjectivesApi apiInstance = new ServiceLevelObjectivesApi(defaultClient);

ServiceLevelObjectiveRequest body =
new ServiceLevelObjectiveRequest()
.type(SLOType.METRIC)
.description("Metric SLO using sli_specification")
.name("Example-Service-Level-Objective")
.sliSpecification(
new SLOSliSpec(
new SLOCountSpec()
.count(
new SLOCountDefinition()
.goodEventsFormula(new SLOFormula().formula("query1 - query2"))
.badEventsFormula(new SLOFormula().formula("query2"))
.queries(
Arrays.asList(
new SLODataSourceQueryDefinition(
new FormulaAndFunctionMetricQueryDefinition()
.dataSource(
FormulaAndFunctionMetricDataSource.METRICS)
.name("query1")
.query("sum:httpservice.hits{*}.as_count()")),
new SLODataSourceQueryDefinition(
new FormulaAndFunctionMetricQueryDefinition()
.dataSource(
FormulaAndFunctionMetricDataSource.METRICS)
.name("query2")
.query("sum:httpservice.errors{*}.as_count()")))))))
.tags(Arrays.asList("env:prod", "type:count"))
.thresholds(
Collections.singletonList(
new SLOThreshold()
.target(99.0)
.targetDisplay("99.0")
.timeframe(SLOTimeframe.SEVEN_DAYS)
.warning(99.5)
.warningDisplay("99.5")))
.timeframe(SLOTimeframe.SEVEN_DAYS)
.targetThreshold(99.0)
.warningThreshold(99.5);

try {
SLOListResponse result = apiInstance.createSLO(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ServiceLevelObjectivesApi#createSLO");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

/**
* A count-based (metric) SLI specification, composed of three parts: the good events formula, the
* total events formula, and the underlying queries.
* bad or total events formula, and the underlying queries.
*/
@JsonPropertyOrder({
SLOCountDefinition.JSON_PROPERTY_BAD_EVENTS_FORMULA,
SLOCountDefinition.JSON_PROPERTY_GOOD_EVENTS_FORMULA,
SLOCountDefinition.JSON_PROPERTY_QUERIES,
SLOCountDefinition.JSON_PROPERTY_TOTAL_EVENTS_FORMULA
Expand All @@ -32,6 +33,9 @@
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
public class SLOCountDefinition {
@JsonIgnore public boolean unparsed = false;
public static final String JSON_PROPERTY_BAD_EVENTS_FORMULA = "bad_events_formula";
private SLOFormula badEventsFormula;

public static final String JSON_PROPERTY_GOOD_EVENTS_FORMULA = "good_events_formula";
private SLOFormula goodEventsFormula;

Expand All @@ -48,14 +52,32 @@ public SLOCountDefinition(
@JsonProperty(required = true, value = JSON_PROPERTY_GOOD_EVENTS_FORMULA)
SLOFormula goodEventsFormula,
@JsonProperty(required = true, value = JSON_PROPERTY_QUERIES)
List<SLODataSourceQueryDefinition> queries,
@JsonProperty(required = true, value = JSON_PROPERTY_TOTAL_EVENTS_FORMULA)
SLOFormula totalEventsFormula) {
List<SLODataSourceQueryDefinition> queries) {
this.goodEventsFormula = goodEventsFormula;
this.unparsed |= goodEventsFormula.unparsed;
this.queries = queries;
this.totalEventsFormula = totalEventsFormula;
this.unparsed |= totalEventsFormula.unparsed;
}

public SLOCountDefinition badEventsFormula(SLOFormula badEventsFormula) {
this.badEventsFormula = badEventsFormula;
this.unparsed |= badEventsFormula.unparsed;
return this;
}

/**
* A formula that specifies how to combine the results of multiple queries.
*
* @return badEventsFormula
*/
@jakarta.annotation.Nullable
@JsonProperty(JSON_PROPERTY_BAD_EVENTS_FORMULA)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public SLOFormula getBadEventsFormula() {
return badEventsFormula;
}

public void setBadEventsFormula(SLOFormula badEventsFormula) {
this.badEventsFormula = badEventsFormula;
}

public SLOCountDefinition goodEventsFormula(SLOFormula goodEventsFormula) {
Expand Down Expand Up @@ -119,8 +141,9 @@ public SLOCountDefinition totalEventsFormula(SLOFormula totalEventsFormula) {
*
* @return totalEventsFormula
*/
@jakarta.annotation.Nullable
@JsonProperty(JSON_PROPERTY_TOTAL_EVENTS_FORMULA)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public SLOFormula getTotalEventsFormula() {
return totalEventsFormula;
}
Expand Down Expand Up @@ -185,21 +208,24 @@ public boolean equals(Object o) {
return false;
}
SLOCountDefinition sloCountDefinition = (SLOCountDefinition) o;
return Objects.equals(this.goodEventsFormula, sloCountDefinition.goodEventsFormula)
return Objects.equals(this.badEventsFormula, sloCountDefinition.badEventsFormula)
&& Objects.equals(this.goodEventsFormula, sloCountDefinition.goodEventsFormula)
&& Objects.equals(this.queries, sloCountDefinition.queries)
&& Objects.equals(this.totalEventsFormula, sloCountDefinition.totalEventsFormula)
&& Objects.equals(this.additionalProperties, sloCountDefinition.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(goodEventsFormula, queries, totalEventsFormula, additionalProperties);
return Objects.hash(
badEventsFormula, goodEventsFormula, queries, totalEventsFormula, additionalProperties);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class SLOCountDefinition {\n");
sb.append(" badEventsFormula: ").append(toIndentedString(badEventsFormula)).append("\n");
sb.append(" goodEventsFormula: ").append(toIndentedString(goodEventsFormula)).append("\n");
sb.append(" queries: ").append(toIndentedString(queries)).append("\n");
sb.append(" totalEventsFormula: ").append(toIndentedString(totalEventsFormula)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SLOCountSpec count(SLOCountDefinition count) {

/**
* A count-based (metric) SLI specification, composed of three parts: the good events formula, the
* total events formula, and the underlying queries.
* bad or total events formula, and the underlying queries.
*
* @return count
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2026-02-25T17:45:38.518Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"httpRequest": {
"body": {
"type": "JSON",
"json": "{\"description\": \"Metric SLO using sli_specification\", \"name\": \"Test-Create_a_new_metric_SLO_object_using_bad_events_formula_returns_OK_response-1772041538\", \"sli_specification\": {\"count\": {\"bad_events_formula\": {\"formula\": \"query2\"}, \"good_events_formula\": {\"formula\": \"query1 - query2\"}, \"queries\": [{\"data_source\": \"metrics\", \"name\": \"query1\", \"query\": \"sum:httpservice.hits{*}.as_count()\"}, {\"data_source\": \"metrics\", \"name\": \"query2\", \"query\": \"sum:httpservice.errors{*}.as_count()\"}]}}, \"tags\": [\"env:prod\", \"type:count\"], \"target_threshold\": 99, \"thresholds\": [{\"target\": 99.0, \"target_display\": \"99.0\", \"timeframe\": \"7d\", \"warning\": 99.5, \"warning_display\": \"99.5\"}], \"timeframe\": \"7d\", \"type\": \"metric\", \"warning_threshold\": 99.5}"
},
"headers": {},
"method": "POST",
"path": "/api/v1/slo",
"keepAlive": false,
"secure": true
},
"httpResponse": {
"body": "{\"data\":[{\"id\":\"7309ff3752fd519f80f65a2ed3247dbb\",\"name\":\"Test-Create_a_new_metric_SLO_object_using_bad_events_formula_returns_OK_response-1772041538\",\"tags\":[\"env:prod\",\"type:count\"],\"monitor_tags\":[],\"thresholds\":[{\"timeframe\":\"7d\",\"target\":99.0,\"target_display\":\"99.\",\"warning\":99.5,\"warning_display\":\"99.5\"}],\"type\":\"metric\",\"type_id\":1,\"description\":\"Metric SLO using sli_specification\",\"timeframe\":\"7d\",\"warning_threshold\":99.5,\"target_threshold\":99,\"query\":{\"numerator\":\"sum:httpservice.hits{*}.as_count() - sum:httpservice.errors{*}.as_count()\",\"denominator\":\"(sum:httpservice.hits{*}.as_count() - sum:httpservice.errors{*}.as_count()) + (sum:httpservice.errors{*}.as_count())\"},\"creator\":{\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"email\":\"team-intg-tools-libs-spam@datadoghq.com\"},\"created_at\":1772041538,\"modified_at\":1772041538,\"sli_specification\":{\"count\":{\"bad_events_formula\":{\"formula\":\"query2\"},\"good_events_formula\":{\"formula\":\"query1 - query2\"},\"queries\":[{\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"sum:httpservice.hits{*}.as_count()\"},{\"data_source\":\"metrics\",\"name\":\"query2\",\"query\":\"sum:httpservice.errors{*}.as_count()\"}]}}}],\"error\":null}\n",
"headers": {
"Content-Type": [
"application/json"
]
},
"statusCode": 200,
"reasonPhrase": "OK"
},
"times": {
"remainingTimes": 1
},
"timeToLive": {
"unlimited": true
},
"id": "d5693d5e-ee1e-afa7-88d0-69277375e5d9"
},
{
"httpRequest": {
"headers": {},
"method": "DELETE",
"path": "/api/v1/slo/7309ff3752fd519f80f65a2ed3247dbb",
"keepAlive": false,
"secure": true
},
"httpResponse": {
"body": "{\"data\":[\"7309ff3752fd519f80f65a2ed3247dbb\"],\"error\":null}\n",
"headers": {
"Content-Type": [
"application/json"
]
},
"statusCode": 200,
"reasonPhrase": "OK"
},
"times": {
"remainingTimes": 1
},
"timeToLive": {
"unlimited": true
},
"id": "c0933b3f-30b7-b24a-0ddb-dcdf3c1ea62d"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"timeToLive": {
"unlimited": true
},
"id": "d5bade64-6ebb-4f4d-903d-8069b52bb31e"
"id": "d5bade64-6ebb-4f4d-903d-8069b52bb31d"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"timeToLive": {
"unlimited": true
},
"id": "d5bade64-6ebb-4f4d-903d-8069b52bb31d"
"id": "d5bade64-6ebb-4f4d-903d-8069b52bb31e"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"timeToLive": {
"unlimited": true
},
"id": "3f83caea-c405-97df-c554-ee2d9f9e4f01"
"id": "3f83caea-c405-97df-c554-ee2d9f9e4f02"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"timeToLive": {
"unlimited": true
},
"id": "3f83caea-c405-97df-c554-ee2d9f9e4f02"
"id": "3f83caea-c405-97df-c554-ee2d9f9e4f01"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"timeToLive": {
"unlimited": true
},
"id": "c206b9cd-771e-14f0-5d18-42a3a48556cf"
"id": "c206b9cd-771e-14f0-5d18-42a3a48556ce"
},
{
"httpRequest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"timeToLive": {
"unlimited": true
},
"id": "194b15fb-fcae-9b9a-e1a7-0daa19dc9eec"
"id": "194b15fb-fcae-9b9a-e1a7-0daa19dc9eed"
},
{
"httpRequest": {
Expand Down Expand Up @@ -57,7 +57,7 @@
"timeToLive": {
"unlimited": true
},
"id": "c206b9cd-771e-14f0-5d18-42a3a48556ce"
"id": "c206b9cd-771e-14f0-5d18-42a3a48556cf"
},
{
"httpRequest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"timeToLive": {
"unlimited": true
},
"id": "73fd406e-d686-10bd-50ee-83f2c499e8a9"
"id": "73fd406e-d686-10bd-50ee-83f2c499e8a8"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"timeToLive": {
"unlimited": true
},
"id": "194b15fb-fcae-9b9a-e1a7-0daa19dc9ee9"
"id": "194b15fb-fcae-9b9a-e1a7-0daa19dc9eea"
},
{
"httpRequest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"timeToLive": {
"unlimited": true
},
"id": "194b15fb-fcae-9b9a-e1a7-0daa19dc9eed"
"id": "194b15fb-fcae-9b9a-e1a7-0daa19dc9ee9"
},
{
"httpRequest": {
Expand Down
Loading
Loading