Skip to content

Commit 103a6bf

Browse files
authored
feat(datadog)!: Add SLO tables, housekeeping (#11166)
Adds `datadog_slos` and `datadog_slo_corrections` tables for SLO info. Housekeeping: - Updates the Datadog SDK used from 2.9.0 to 2.13.0 - Updates all PKs to include `account_name` and `id`, plus parent id if exists - Updates plugin-sdk version to 3.9.0 - Removes all manually added fields, now using `transformers` exclusively - Datadog NullableTypes mapped to proper types Closes #[10780](#10780)
1 parent 0a1764f commit 103a6bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+646
-432
lines changed

plugins/source/datadog/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Bar() *schema.Table {
3737
// the resolver function is responsible for fetching data from the API
3838
Resolver: fetchBar,
3939
// columns will be automatically created from the given struct
40-
Transform: transformers.TransformWithStruct(&datadogV2.Bar{}),
40+
Transform: client.TransformWithStruct(&datadogV2.Bar{}),
4141
// define additional columns here, or override the default columns
4242
Columns: []schema.Column{},
4343
}

plugins/source/datadog/client/mocks/incidents_api.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/datadog/client/mocks/service_level_objective_corrections_api.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/datadog/client/mocks/service_level_objectives_api.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/datadog/client/resolvers.go

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,20 @@ package client
22

33
import (
44
"context"
5-
"fmt"
6-
7-
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
85

6+
"github.com/apache/arrow/go/v13/arrow"
97
"github.com/cloudquery/plugin-sdk/v3/schema"
10-
"github.com/thoas/go-funk"
118
)
129

13-
func ResolveParentColumn(field string) schema.ColumnResolver {
14-
return func(_ context.Context, _ schema.ClientMeta, r *schema.Resource, c schema.Column) error {
15-
return r.Set(c.Name, funk.Get(r.Parent.Item, field))
16-
}
17-
}
18-
1910
func ResolveAccountName(_ context.Context, meta schema.ClientMeta, r *schema.Resource, col schema.Column) error {
2011
client := meta.(*Client)
2112
return r.Set(col.Name, client.multiplexedAccount.Name)
2213
}
2314

24-
type Nullable interface {
25-
Get() any
26-
IsSet() bool
27-
}
28-
29-
func GetNullable(i any) (any, error) {
30-
switch v := i.(type) {
31-
case datadog.NullableTime:
32-
return v.Get(), nil
33-
case datadog.NullableInt64:
34-
return v.Get(), nil
35-
}
36-
return nil, fmt.Errorf("unsupported datadog nullable type %T", i)
37-
}
38-
39-
func NullableResolver(path string) schema.ColumnResolver {
40-
return func(_ context.Context, meta schema.ClientMeta, r *schema.Resource, c schema.Column) error {
41-
data, err := GetNullable(funk.Get(r.Item, path, funk.WithAllowZero()))
42-
if err != nil {
43-
return err
44-
}
45-
return r.Set(c.Name, data)
46-
}
15+
var AccountNameColumn = schema.Column{
16+
Name: "account_name",
17+
Type: arrow.BinaryTypes.String,
18+
Resolver: ResolveAccountName,
19+
PrimaryKey: true,
20+
NotNull: true,
4721
}

plugins/source/datadog/client/services.go

Lines changed: 24 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/datadog/client/services/incidents_api.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/datadog/client/services/service_level_objective_corrections_api.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/datadog/client/services/service_level_objectives_api.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"reflect"
6+
7+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
8+
"github.com/apache/arrow/go/v13/arrow"
9+
"github.com/cloudquery/plugin-sdk/v3/schema"
10+
"github.com/cloudquery/plugin-sdk/v3/transformers"
11+
"github.com/thoas/go-funk"
12+
)
13+
14+
func typeTransformer(field reflect.StructField) (arrow.DataType, error) {
15+
switch reflect.New(field.Type).Elem().Interface().(type) {
16+
case datadog.NullableInt, datadog.NullableInt64:
17+
return arrow.PrimitiveTypes.Int64, nil
18+
case datadog.NullableInt32:
19+
return arrow.PrimitiveTypes.Int32, nil
20+
case datadog.NullableBool:
21+
return arrow.FixedWidthTypes.Boolean, nil
22+
case datadog.NullableFloat32:
23+
return arrow.PrimitiveTypes.Float32, nil
24+
case datadog.NullableFloat64:
25+
return arrow.PrimitiveTypes.Float64, nil
26+
case datadog.NullableString:
27+
return arrow.BinaryTypes.String, nil
28+
case datadog.NullableTime:
29+
return arrow.FixedWidthTypes.Timestamp_us, nil
30+
default:
31+
return nil, nil
32+
}
33+
}
34+
35+
type nullable interface {
36+
IsSet() bool
37+
}
38+
39+
func resolverTransformer(field reflect.StructField, path string) schema.ColumnResolver {
40+
switch reflect.New(field.Type).Elem().Interface().(type) {
41+
case
42+
datadog.NullableBool,
43+
datadog.NullableFloat32,
44+
datadog.NullableFloat64,
45+
datadog.NullableInt32,
46+
datadog.NullableInt64,
47+
datadog.NullableInt,
48+
datadog.NullableString,
49+
datadog.NullableTime:
50+
51+
return func(_ context.Context, meta schema.ClientMeta, r *schema.Resource, c schema.Column) error {
52+
val := funk.Get(r.Item, path, funk.WithAllowZero())
53+
if !val.(nullable).IsSet() {
54+
return r.Set(c.Name, nil)
55+
}
56+
getFunc, ok := reflect.TypeOf(val).MethodByName("Get")
57+
if !ok {
58+
panic("no Get() on nullable type " + field.Type.String())
59+
}
60+
61+
ret := getFunc.Func.Call([]reflect.Value{reflect.ValueOf(val)})
62+
if len(ret) != 1 {
63+
panic("expected 1 return value from Get()")
64+
}
65+
66+
return r.Set(c.Name, ret[0].Interface())
67+
}
68+
69+
default:
70+
return nil
71+
}
72+
}
73+
74+
var options = []transformers.StructTransformerOption{
75+
transformers.WithTypeTransformer(typeTransformer),
76+
transformers.WithResolverTransformer(resolverTransformer),
77+
}
78+
79+
func TransformWithStruct(t any, opts ...transformers.StructTransformerOption) schema.Transform {
80+
return transformers.TransformWithStruct(t, append(options, opts...)...)
81+
}

0 commit comments

Comments
 (0)