-
Notifications
You must be signed in to change notification settings - Fork 52
/
QueryTimeseriesData_301142940.go
57 lines (51 loc) · 1.73 KB
/
QueryTimeseriesData_301142940.go
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
// Timeseries cross product query returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.TimeseriesFormulaQueryRequest{
Data: datadogV2.TimeseriesFormulaRequest{
Attributes: datadogV2.TimeseriesFormulaRequestAttributes{
Formulas: []datadogV2.QueryFormula{
{
Formula: "a",
Limit: &datadogV2.FormulaLimit{
Count: datadog.PtrInt32(10),
Order: datadogV2.QUERYSORTORDER_DESC.Ptr(),
},
},
},
From: 1636625471000,
Interval: datadog.PtrInt64(5000),
Queries: []datadogV2.TimeseriesQuery{
datadogV2.TimeseriesQuery{
MetricsTimeseriesQuery: &datadogV2.MetricsTimeseriesQuery{
DataSource: datadogV2.METRICSDATASOURCE_METRICS,
Query: "avg:datadog.estimated_usage.metrics.custom{*}",
Name: datadog.PtrString("a"),
}},
},
To: 1636629071000,
},
Type: datadogV2.TIMESERIESFORMULAREQUESTTYPE_TIMESERIES_REQUEST,
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
configuration.SetUnstableOperationEnabled("v2.QueryTimeseriesData", true)
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewMetricsApi(apiClient)
resp, r, err := api.QueryTimeseriesData(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `MetricsApi.QueryTimeseriesData`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `MetricsApi.QueryTimeseriesData`:\n%s\n", responseContent)
}