query field.
+ */
+@JsonPropertyOrder({
+ SLOCountDefinition.JSON_PROPERTY_GOOD_EVENTS_FORMULA,
+ SLOCountDefinition.JSON_PROPERTY_QUERIES,
+ SLOCountDefinition.JSON_PROPERTY_TOTAL_EVENTS_FORMULA
+})
+@jakarta.annotation.Generated(
+ 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_GOOD_EVENTS_FORMULA = "good_events_formula";
+ private SLOFormula goodEventsFormula;
+
+ public static final String JSON_PROPERTY_QUERIES = "queries";
+ private Listquery field.
+ *
+ * @return count
+ */
+ @JsonProperty(JSON_PROPERTY_COUNT)
+ @JsonInclude(value = JsonInclude.Include.ALWAYS)
+ public SLOCountDefinition getCount() {
+ return count;
+ }
+
+ public void setCount(SLOCountDefinition count) {
+ this.count = count;
+ }
+
+ /** Return true if this SLOCountSpec object is equal to o. */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ SLOCountSpec sloCountSpec = (SLOCountSpec) o;
+ return Objects.equals(this.count, sloCountSpec.count);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(count);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("class SLOCountSpec {\n");
+ sb.append(" count: ").append(toIndentedString(count)).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 ");
+ }
+}
diff --git a/src/main/java/com/datadog/api/client/v1/model/SLOResponseData.java b/src/main/java/com/datadog/api/client/v1/model/SLOResponseData.java
index e55f6a99d45..35a36ceb956 100644
--- a/src/main/java/com/datadog/api/client/v1/model/SLOResponseData.java
+++ b/src/main/java/com/datadog/api/client/v1/model/SLOResponseData.java
@@ -343,9 +343,11 @@ public SLOResponseData query(ServiceLevelObjectiveQuery query) {
}
/**
- * A metric-based SLO. Required if type is metric. 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 min of all of those requests.
+ * A count-based (metric) SLO query. This field has been superseded by sli_specification
+ * but is retained for backwards compatibility. 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 min of all of those requests. Usage is not permitted when request payload
+ * contains sli_specification field.
*
* @return query
*/
@@ -367,7 +369,8 @@ public SLOResponseData sliSpecification(SLOSliSpec sliSpecification) {
}
/**
- * A generic SLI specification. This is currently used for time-slice SLOs only.
+ * A generic SLI specification. This is currently used for time-slice and count-based (metric)
+ * SLOs only.
*
* @return sliSpecification
*/
diff --git a/src/main/java/com/datadog/api/client/v1/model/SLOSliSpec.java b/src/main/java/com/datadog/api/client/v1/model/SLOSliSpec.java
index 36a3066f9f6..c45083515b6 100644
--- a/src/main/java/com/datadog/api/client/v1/model/SLOSliSpec.java
+++ b/src/main/java/com/datadog/api/client/v1/model/SLOSliSpec.java
@@ -121,6 +121,48 @@ public SLOSliSpec deserialize(JsonParser jp, DeserializationContext ctxt)
log.log(Level.FINER, "Input data does not match schema 'SLOTimeSliceSpec'", e);
}
+ // deserialize SLOCountSpec
+ try {
+ boolean attemptParsing = true;
+ // ensure that we respect type coercion as set on the client ObjectMapper
+ if (SLOCountSpec.class.equals(Integer.class)
+ || SLOCountSpec.class.equals(Long.class)
+ || SLOCountSpec.class.equals(Float.class)
+ || SLOCountSpec.class.equals(Double.class)
+ || SLOCountSpec.class.equals(Boolean.class)
+ || SLOCountSpec.class.equals(String.class)) {
+ attemptParsing = typeCoercion;
+ if (!attemptParsing) {
+ attemptParsing |=
+ ((SLOCountSpec.class.equals(Integer.class) || SLOCountSpec.class.equals(Long.class))
+ && token == JsonToken.VALUE_NUMBER_INT);
+ attemptParsing |=
+ ((SLOCountSpec.class.equals(Float.class) || SLOCountSpec.class.equals(Double.class))
+ && (token == JsonToken.VALUE_NUMBER_FLOAT
+ || token == JsonToken.VALUE_NUMBER_INT));
+ attemptParsing |=
+ (SLOCountSpec.class.equals(Boolean.class)
+ && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
+ attemptParsing |=
+ (SLOCountSpec.class.equals(String.class) && token == JsonToken.VALUE_STRING);
+ }
+ }
+ if (attemptParsing) {
+ tmp = tree.traverse(jp.getCodec()).readValueAs(SLOCountSpec.class);
+ // TODO: there is no validation against JSON schema constraints
+ // (min, max, enum, pattern...), this does not perform a strict JSON
+ // validation, which means the 'match' count may be higher than it should be.
+ if (!((SLOCountSpec) tmp).unparsed) {
+ deserialized = tmp;
+ match++;
+ }
+ log.log(Level.FINER, "Input data matches schema 'SLOCountSpec'");
+ }
+ } catch (Exception e) {
+ // deserialization failed, continue
+ log.log(Level.FINER, "Input data does not match schema 'SLOCountSpec'", e);
+ }
+
SLOSliSpec ret = new SLOSliSpec();
if (match == 1) {
ret.setActualInstance(deserialized);
@@ -154,8 +196,14 @@ public SLOSliSpec(SLOTimeSliceSpec o) {
setActualInstance(o);
}
+ public SLOSliSpec(SLOCountSpec o) {
+ super("oneOf", Boolean.FALSE);
+ setActualInstance(o);
+ }
+
static {
schemas.put("SLOTimeSliceSpec", new GenericTypeIt could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
* composed schema (allOf, anyOf, oneOf).
@@ -177,18 +225,22 @@ public void setActualInstance(Object instance) {
super.setActualInstance(instance);
return;
}
+ if (JSON.isInstanceOf(SLOCountSpec.class, instance, new HashSetmetric. 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 min of all of those requests.
+ * A count-based (metric) SLO query. This field has been superseded by sli_specification
+ * but is retained for backwards compatibility. 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 min of all of those requests. Usage is not permitted when request payload
+ * contains sli_specification field.
*
* @return query
*/
@@ -348,7 +350,8 @@ public ServiceLevelObjective sliSpecification(SLOSliSpec sliSpecification) {
}
/**
- * A generic SLI specification. This is currently used for time-slice SLOs only.
+ * A generic SLI specification. This is currently used for time-slice and count-based (metric)
+ * SLOs only.
*
* @return sliSpecification
*/
diff --git a/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveQuery.java b/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveQuery.java
index aee83319b41..6c0ee196a22 100644
--- a/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveQuery.java
+++ b/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveQuery.java
@@ -18,9 +18,11 @@
import java.util.Objects;
/**
- * A metric-based SLO. Required if type is metric. 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 min of all of those requests.
+ * A count-based (metric) SLO query. This field has been superseded by sli_specification
+ * but is retained for backwards compatibility. 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 min of all of those requests. Usage is not permitted when request payload
+ * contains sli_specification field.
*/
@JsonPropertyOrder({
ServiceLevelObjectiveQuery.JSON_PROPERTY_DENOMINATOR,
diff --git a/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveRequest.java b/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveRequest.java
index dfb2e482c73..ab07fa6b861 100644
--- a/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveRequest.java
+++ b/src/main/java/com/datadog/api/client/v1/model/ServiceLevelObjectiveRequest.java
@@ -217,9 +217,11 @@ public ServiceLevelObjectiveRequest query(ServiceLevelObjectiveQuery query) {
}
/**
- * A metric-based SLO. Required if type is metric. 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 min of all of those requests.
+ * A count-based (metric) SLO query. This field has been superseded by sli_specification
+ * but is retained for backwards compatibility. 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 min of all of those requests. Usage is not permitted when request payload
+ * contains sli_specification field.
*
* @return query
*/
@@ -241,7 +243,8 @@ public ServiceLevelObjectiveRequest sliSpecification(SLOSliSpec sliSpecification
}
/**
- * A generic SLI specification. This is currently used for time-slice SLOs only.
+ * A generic SLI specification. This is currently used for time-slice and count-based (metric)
+ * SLOs only.
*
* @return sliSpecification
*/
diff --git a/src/test/resources/com/datadog/api/client/v1/api/service_level_objectives.feature b/src/test/resources/com/datadog/api/client/v1/api/service_level_objectives.feature
index c5534618a73..22c9d6cd3f9 100644
--- a/src/test/resources/com/datadog/api/client/v1/api/service_level_objectives.feature
+++ b/src/test/resources/com/datadog/api/client/v1/api/service_level_objectives.feature
@@ -48,6 +48,23 @@ Feature: Service Level Objectives
When the request is sent
Then the response status is 200 OK
+ @team:DataDog/slo-app
+ Scenario: Create a new metric SLO object using sli_specification returns "OK" response
+ Given new "CreateSLO" request
+ And body with value {"type":"metric","description":"Metric SLO using sli_specification","name":"{{ unique }}","sli_specification":{"count":{"good_events_formula":{"formula":"query1 - query2"},"total_events_formula":{"formula":"query1"},"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"],"thresholds":[{"target":99.0,"target_display":"99.0","timeframe":"7d","warning":99.5,"warning_display":"99.5"}],"timeframe":"7d","target_threshold":99.0,"warning_threshold":99.5}
+ When the request is sent
+ Then the response status is 200 OK
+ And the response "data[0].timeframe" is equal to "7d"
+ And the response "data[0].target_threshold" is equal to 99.0
+ And the response "data[0].warning_threshold" is equal to 99.5
+ And the response "data[0]" has field "sli_specification"
+ And the response "data[0].sli_specification" has field "count"
+ And the response "data[0].sli_specification.count" has field "good_events_formula"
+ And the response "data[0].sli_specification.count" has field "total_events_formula"
+ And the response "data[0].sli_specification.count" has field "queries"
+ And the response "data[0].sli_specification.count.queries" has length 2
+ And the response "data[0]" has field "query"
+
@team:DataDog/slo-app
Scenario: Create a time-slice SLO object returns "OK" response
Given new "CreateSLO" request