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
62 changes: 57 additions & 5 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11409,6 +11409,60 @@ components:
example: UTC
type: string
type: object
SLOCountCondition:
description: 'A count-based SLI specification, composed of three parts: the
good events formula, the total events formula,

and the involved queries.'
example:
good_events_formula: query1 - query2
queries:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.success{*} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
total_events_formula: query2
properties:
good_events_formula:
$ref: '#/components/schemas/SLOFormula'
queries:
example:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
items:
$ref: '#/components/schemas/SLODataSourceQueryDefinition'
minItems: 1
type: array
total_events_formula:
$ref: '#/components/schemas/SLOFormula'
required:
- good_events_formula
- total_events_formula
- queries
type: object
SLOCountSpec:
additionalProperties: false
description: A count-based SLI specification.
example:
count:
good_events_formula: query1 - query2
queries:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.success{*} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
total_events_formula: query2
properties:
count:
$ref: '#/components/schemas/SLOCountCondition'
required:
- count
type: object
SLOCreator:
description: The creator of the SLO
nullable: true
Expand Down Expand Up @@ -12295,8 +12349,6 @@ components:
type: array
timeframe:
$ref: '#/components/schemas/SLOTimeframe'
type:
$ref: '#/components/schemas/SLOType'
warning_threshold:
description: 'The optional warning threshold such that when the service
level indicator is
Expand All @@ -12314,9 +12366,10 @@ components:
type: object
SLOSliSpec:
description: A generic SLI specification. This is currently used for time-slice
SLOs only.
and count-based SLOs only.
oneOf:
- $ref: '#/components/schemas/SLOTimeSliceSpec'
- $ref: '#/components/schemas/SLOCountSpec'
SLOState:
description: State of the SLO.
enum:
Expand Down Expand Up @@ -13468,8 +13521,7 @@ components:
- type
type: object
ServiceLevelObjectiveQuery:
description: 'A metric-based SLO. **Required if type is `metric`**. Note that
Datadog only allows the sum by aggregator
description: 'A metric-based SLO. Note that Datadog only allows the sum by aggregator

to be used because this will sum up all request counts instead of averaging
them, or taking the max or
Expand Down
76 changes: 76 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_512760759.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Create a new metric SLO object using sli_specification 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.SLOCountCondition;
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 SLOCountCondition()
.goodEventsFormula(new SLOFormula().formula("query1"))
.totalEventsFormula(new SLOFormula().formula("query2"))
.queries(
Arrays.asList(
new SLODataSourceQueryDefinition(
new FormulaAndFunctionMetricQueryDefinition()
.dataSource(
FormulaAndFunctionMetricDataSource.METRICS)
.name("query1")
.query("sum:httpservice.success{*}.as_count()")),
new SLODataSourceQueryDefinition(
new FormulaAndFunctionMetricQueryDefinition()
.dataSource(
FormulaAndFunctionMetricDataSource.METRICS)
.name("query2")
.query("sum:httpservice.hits{*}.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(98.0)
.warningDisplay("98.0")))
.timeframe(SLOTimeframe.SEVEN_DAYS)
.targetThreshold(99.0)
.warningThreshold(98.0);

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();
}
}
}
222 changes: 222 additions & 0 deletions src/main/java/com/datadog/api/client/v1/model/SLOCountCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/

package com.datadog.api.client.v1.model;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* A count-based SLI specification, composed of three parts: the good events formula, the total
* events formula, and the involved queries.
*/
@JsonPropertyOrder({
SLOCountCondition.JSON_PROPERTY_GOOD_EVENTS_FORMULA,
SLOCountCondition.JSON_PROPERTY_QUERIES,
SLOCountCondition.JSON_PROPERTY_TOTAL_EVENTS_FORMULA
})
@jakarta.annotation.Generated(
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
public class SLOCountCondition {
@JsonIgnore public boolean unparsed = false;
public static final String JSON_PROPERTY_GOOD_EVENTS_FORMULA = "good_events_formula";
private SLOFormula goodEventsFormula;

public static final String JSON_PROPERTY_QUERIES = "queries";
private List<SLODataSourceQueryDefinition> queries = new ArrayList<>();

public static final String JSON_PROPERTY_TOTAL_EVENTS_FORMULA = "total_events_formula";
private SLOFormula totalEventsFormula;

public SLOCountCondition() {}

@JsonCreator
public SLOCountCondition(
@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) {
this.goodEventsFormula = goodEventsFormula;
this.unparsed |= goodEventsFormula.unparsed;
this.queries = queries;
this.totalEventsFormula = totalEventsFormula;
this.unparsed |= totalEventsFormula.unparsed;
}

public SLOCountCondition goodEventsFormula(SLOFormula goodEventsFormula) {
this.goodEventsFormula = goodEventsFormula;
this.unparsed |= goodEventsFormula.unparsed;
return this;
}

/**
* A formula that specifies how to combine the results of multiple queries.
*
* @return goodEventsFormula
*/
@JsonProperty(JSON_PROPERTY_GOOD_EVENTS_FORMULA)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public SLOFormula getGoodEventsFormula() {
return goodEventsFormula;
}

public void setGoodEventsFormula(SLOFormula goodEventsFormula) {
this.goodEventsFormula = goodEventsFormula;
}

public SLOCountCondition queries(List<SLODataSourceQueryDefinition> queries) {
this.queries = queries;
for (SLODataSourceQueryDefinition item : queries) {
this.unparsed |= item.unparsed;
}
return this;
}

public SLOCountCondition addQueriesItem(SLODataSourceQueryDefinition queriesItem) {
this.queries.add(queriesItem);
this.unparsed |= queriesItem.unparsed;
return this;
}

/**
* Getqueries
*
* @return queries
*/
@JsonProperty(JSON_PROPERTY_QUERIES)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public List<SLODataSourceQueryDefinition> getQueries() {
return queries;
}

public void setQueries(List<SLODataSourceQueryDefinition> queries) {
this.queries = queries;
}

public SLOCountCondition totalEventsFormula(SLOFormula totalEventsFormula) {
this.totalEventsFormula = totalEventsFormula;
this.unparsed |= totalEventsFormula.unparsed;
return this;
}

/**
* A formula that specifies how to combine the results of multiple queries.
*
* @return totalEventsFormula
*/
@JsonProperty(JSON_PROPERTY_TOTAL_EVENTS_FORMULA)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public SLOFormula getTotalEventsFormula() {
return totalEventsFormula;
}

public void setTotalEventsFormula(SLOFormula totalEventsFormula) {
this.totalEventsFormula = totalEventsFormula;
}

/**
* A container for additional, undeclared properties. This is a holder for any undeclared
* properties as specified with the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value. If the property
* does not already exist, create it otherwise replace it.
*
* @param key The arbitrary key to set
* @param value The associated value
* @return SLOCountCondition
*/
@JsonAnySetter
public SLOCountCondition putAdditionalProperty(String key, Object value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<String, Object>();
}
this.additionalProperties.put(key, value);
return this;
}

/**
* Return the additional (undeclared) property.
*
* @return The additional properties
*/
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}

/**
* Return the additional (undeclared) property with the specified name.
*
* @param key The arbitrary key to get
* @return The specific additional property for the given key
*/
public Object getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}

/** Return true if this SLOCountCondition object is equal to o. */
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SLOCountCondition sloCountCondition = (SLOCountCondition) o;
return Objects.equals(this.goodEventsFormula, sloCountCondition.goodEventsFormula)
&& Objects.equals(this.queries, sloCountCondition.queries)
&& Objects.equals(this.totalEventsFormula, sloCountCondition.totalEventsFormula)
&& Objects.equals(this.additionalProperties, sloCountCondition.additionalProperties);
}

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

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class SLOCountCondition {\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");
sb.append(" additionalProperties: ")
.append(toIndentedString(additionalProperties))
.append("\n");
sb.append('}');
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Loading
Loading