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
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package observability_pipeline

import (
datadogV2 "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type AddMetricTagsProcessorModel struct {
Tags []AddMetricTagsProcessorTagModel `tfsdk:"tag"`
}

type AddMetricTagsProcessorTagModel struct {
Name types.String `tfsdk:"name"`
Value types.String `tfsdk:"value"`
}

func AddMetricTagsProcessorSchema() schema.ListNestedBlock {
return schema.ListNestedBlock{
Description: "The `add_metric_tags` processor adds static tags to metrics.",
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{},
Blocks: map[string]schema.Block{
"tag": schema.ListNestedBlock{
Description: "A list of static tags to add to each metric. Up to 15 tags may be defined.",
Validators: []validator.List{
listvalidator.IsRequired(),
listvalidator.SizeAtMost(15),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Required: true,
Description: "The tag name.",
},
"value": schema.StringAttribute{
Required: true,
Description: "The tag value.",
},
},
},
},
},
},
}
}

func ExpandAddMetricTagsProcessor(common BaseProcessorFields, src *AddMetricTagsProcessorModel) datadogV2.ObservabilityPipelineConfigProcessorItem {
proc := datadogV2.NewObservabilityPipelineAddMetricTagsProcessorWithDefaults()
common.ApplyTo(proc)

tags := make([]datadogV2.ObservabilityPipelineFieldValue, 0, len(src.Tags))
for _, t := range src.Tags {
tags = append(tags, datadogV2.ObservabilityPipelineFieldValue{
Name: t.Name.ValueString(),
Value: t.Value.ValueString(),
})
}
proc.SetTags(tags)

return datadogV2.ObservabilityPipelineAddMetricTagsProcessorAsObservabilityPipelineConfigProcessorItem(proc)
}

func FlattenAddMetricTagsProcessor(src *datadogV2.ObservabilityPipelineAddMetricTagsProcessor) *AddMetricTagsProcessorModel {
if src == nil {
return nil
}
var tags []AddMetricTagsProcessorTagModel
for _, t := range src.GetTags() {
tags = append(tags, AddMetricTagsProcessorTagModel{
Name: types.StringValue(t.GetName()),
Value: types.StringValue(t.GetValue()),
})
}
return &AddMetricTagsProcessorModel{Tags: tags}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package observability_pipeline

import (
datadogV2 "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type AggregateProcessorModel struct {
IntervalSecs types.Int64 `tfsdk:"interval_secs"`
Mode types.String `tfsdk:"mode"`
}

func AggregateProcessorSchema() schema.ListNestedBlock {
return schema.ListNestedBlock{
Description: "The `aggregate` processor combines metrics that share the same name and tags into a single metric over a configurable interval.",
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"interval_secs": schema.Int64Attribute{
Required: true,
Description: "The interval, in seconds, over which metrics are aggregated. Must be between 1 and 60.",
Validators: []validator.Int64{
int64validator.Between(1, 60),
},
},
"mode": schema.StringAttribute{
Required: true,
Description: "The aggregation mode. One of `auto`, `sum`, `latest`, `count`, `max`, `min`, `mean`.",
Validators: []validator.String{
stringvalidator.OneOf("auto", "sum", "latest", "count", "max", "min", "mean"),
},
},
},
},
}
}

func ExpandAggregateProcessor(common BaseProcessorFields, src *AggregateProcessorModel) datadogV2.ObservabilityPipelineConfigProcessorItem {
proc := datadogV2.NewObservabilityPipelineAggregateProcessorWithDefaults()
common.ApplyTo(proc)
proc.SetIntervalSecs(src.IntervalSecs.ValueInt64())
proc.SetMode(datadogV2.ObservabilityPipelineAggregateProcessorMode(src.Mode.ValueString()))
return datadogV2.ObservabilityPipelineAggregateProcessorAsObservabilityPipelineConfigProcessorItem(proc)
}

func FlattenAggregateProcessor(src *datadogV2.ObservabilityPipelineAggregateProcessor) *AggregateProcessorModel {
if src == nil {
return nil
}
return &AggregateProcessorModel{
IntervalSecs: types.Int64Value(src.GetIntervalSecs()),
Mode: types.StringValue(string(src.GetMode())),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package observability_pipeline

import (
datadogV2 "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type RenameMetricTagsProcessorModel struct {
Tags []RenameMetricTagsProcessorTagModel `tfsdk:"tag"`
}

type RenameMetricTagsProcessorTagModel struct {
Tag types.String `tfsdk:"tag"`
RenameTo types.String `tfsdk:"rename_to"`
}

func RenameMetricTagsProcessorSchema() schema.ListNestedBlock {
return schema.ListNestedBlock{
Description: "The `rename_metric_tags` processor changes the keys of tags on metrics.",
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{},
Blocks: map[string]schema.Block{
"tag": schema.ListNestedBlock{
Description: "A list of rename rules. Up to 15 tags may be defined.",
Validators: []validator.List{
listvalidator.IsRequired(),
listvalidator.SizeAtMost(15),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"tag": schema.StringAttribute{
Required: true,
Description: "The original tag key on the metric event.",
},
"rename_to": schema.StringAttribute{
Required: true,
Description: "The new tag key to assign in place of the original.",
},
},
},
},
},
},
}
}

func ExpandRenameMetricTagsProcessor(common BaseProcessorFields, src *RenameMetricTagsProcessorModel) datadogV2.ObservabilityPipelineConfigProcessorItem {
proc := datadogV2.NewObservabilityPipelineRenameMetricTagsProcessorWithDefaults()
common.ApplyTo(proc)

tags := make([]datadogV2.ObservabilityPipelineRenameMetricTagsProcessorTag, 0, len(src.Tags))
for _, t := range src.Tags {
tags = append(tags, datadogV2.ObservabilityPipelineRenameMetricTagsProcessorTag{
Tag: t.Tag.ValueString(),
RenameTo: t.RenameTo.ValueString(),
})
}
proc.SetTags(tags)

return datadogV2.ObservabilityPipelineRenameMetricTagsProcessorAsObservabilityPipelineConfigProcessorItem(proc)
}

func FlattenRenameMetricTagsProcessor(src *datadogV2.ObservabilityPipelineRenameMetricTagsProcessor) *RenameMetricTagsProcessorModel {
if src == nil {
return nil
}
var tags []RenameMetricTagsProcessorTagModel
for _, t := range src.GetTags() {
tags = append(tags, RenameMetricTagsProcessorTagModel{
Tag: types.StringValue(t.GetTag()),
RenameTo: types.StringValue(t.GetRenameTo()),
})
}
return &RenameMetricTagsProcessorModel{Tags: tags}
}
Loading
Loading