-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateSLO_512760759.java
More file actions
79 lines (75 loc) · 4.04 KB
/
CreateSLO_512760759.java
File metadata and controls
79 lines (75 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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.SLOCountDefinition;
import com.datadog.api.client.v1.model.SLOCountDefinitionWithTotalEventsFormula;
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(
new SLOCountDefinitionWithTotalEventsFormula()
.goodEventsFormula(new SLOFormula().formula("query1 - query2"))
.totalEventsFormula(new SLOFormula().formula("query1"))
.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();
}
}
}