Skip to content

Commit

Permalink
fix issue with telemetry type and route id not persisting
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirianni committed Feb 8, 2025
1 parent 38b8e83 commit 9aa5416
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 72 deletions.
1 change: 1 addition & 0 deletions docs/resources/bindplane_configuration_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Configuration V2 builds upon [Configuration V1](./bindplane_configuration.md) by
| ------------------- | ------------ | -------- | ---------------------------- |
| `name` | string | required | The source name. |
| `processors` | list(string) | optional | One or more processor names to attach to the destination. |
| `route_id` | string | required | An arbitrary string that can be used to configure routes to this destination. |

### Rollout Options Block

Expand Down
95 changes: 95 additions & 0 deletions provider/resource_configuration_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,95 @@ func resourceConfigurationV2Read(d *schema.ResourceData, meta any) error {
processors = append(processors, strings.Split(p.Name, ":")[0])
}
source["processors"] = processors

logRoutes := s.Routes.Logs
if len(logRoutes) > 0 {
routes := []map[string]any{}
for _, r := range logRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "logs",
"components": r.Components,
})
}
source["route"] = routes
}
metricRoutes := s.Routes.Metrics
if len(metricRoutes) > 0 {
routes := []map[string]any{}
for _, r := range metricRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "metrics",
"components": r.Components,
})
}
source["route"] = routes
}
traceRoutes := s.Routes.Traces
if len(traceRoutes) > 0 {
routes := []map[string]any{}
for _, r := range traceRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "traces",
"components": r.Components,
})
}
source["route"] = routes
}
logMetricRoutes := s.Routes.LogsMetrics
if len(logMetricRoutes) > 0 {
routes := []map[string]any{}
for _, r := range logMetricRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "logs+metrics",
"components": r.Components,
})
}
source["route"] = routes
}
logTraceRoutes := s.Routes.LogsTraces
if len(logTraceRoutes) > 0 {
routes := []map[string]any{}
for _, r := range logTraceRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "logs+traces",
"components": r.Components,
})
}
source["route"] = routes
}
metricTraceRoutes := s.Routes.MetricsTraces
if len(metricTraceRoutes) > 0 {
routes := []map[string]any{}
for _, r := range metricTraceRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "metrics+traces",
"components": r.Components,
})
}
source["route"] = routes
}
logMetricTraceRoutes := s.Routes.LogsMetricsTraces
if len(logMetricTraceRoutes) > 0 {
routes := []map[string]any{}
for _, r := range logMetricTraceRoutes {
routes = append(routes, map[string]any{
"telemetry_type": "logs+metrics+traces",
"components": r.Components,
})
}
source["route"] = routes
}

sourceBlocks = append(sourceBlocks, source)
}
if err := d.Set("source", sourceBlocks); err != nil {
return err
}

// Save the current state here so we can retrieve the saved
// route ID
stateDestinationBlocks := d.Get("destination").([]any)

destinationBlocks := []map[string]any{}
for _, d := range config.Spec.Destinations {
destination := map[string]any{}
Expand All @@ -497,8 +580,20 @@ func resourceConfigurationV2Read(d *schema.ResourceData, meta any) error {
processors = append(processors, strings.Split(p.Name, ":")[0])
}
destination["processors"] = processors

// Retrieve the saved route IDs from state and copy them
// to the new destination blocks before calling d.Set.
for _, stateDestination := range stateDestinationBlocks {
stateDestination := stateDestination.(map[string]any)
if stateDestination["name"] == destination["name"] {
destination["route_id"] = stateDestination["route_id"]
continue
}
}

destinationBlocks = append(destinationBlocks, destination)
}

if err := d.Set("destination", destinationBlocks); err != nil {
return err
}
Expand Down
177 changes: 105 additions & 72 deletions test/local/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,110 @@ resource "bindplane_connector" "routing" {
)
}

# resource "bindplane_configuration_v2" "configuration" {
# lifecycle {
# create_before_destroy = true
# }

# rollout = true

# name = "my-config-v2"
# platform = "linux"

# source {
# name = bindplane_source.otlp.name

# // Route all telemetry types to datadog
# route {
# components = [
# "destinations/${bindplane_destination.datadog.id}"
# ]
# }

# // route logs to loki
# route {
# telemetry_type = "logs"
# components = [
# "destinations/${bindplane_destination.loki.id}"
# ]
# }

# // route traces to google
# route {
# telemetry_type = "traces"
# components = [
# "destinations/${bindplane_destination.google.id}"
# ]
# }
# }

# source {
# name = bindplane_source.journald.name
# processors = [
# bindplane_processor_bundle.bundle.name,
# ]

# route {
# components = [
# "destinations/${bindplane_destination.custom.id}"
# ]
# }

# route {
# components = [
# "destinations/${bindplane_destination.google.id}"
# ]
# }

# route {
# components = [
# "destinations/${bindplane_destination.loki.id}"
# ]
# }
# }

# source {
# name = bindplane_source.host.name
# route {
# telemetry_type = "metrics"
# components = [
# "destinations/${bindplane_destination.google.id}"
# ]
# }
# }

# destination {
# route_id = bindplane_destination.custom.id
# name = bindplane_destination.custom.name
# processors = [
# bindplane_processor.batch.name,

# // order matters here
# bindplane_processor.time-parse-http-datatime.name
# ]
# }

# destination {
# route_id = bindplane_destination.google.id
# name = bindplane_destination.google.name
# }

# destination {
# route_id = bindplane_destination.loki.id
# name = bindplane_destination.loki.name
# }

# destination {
# route_id = bindplane_destination.datadog.id
# name = bindplane_destination.datadog.name
# }

# extensions = [
# bindplane_extension.pprof.name
# ]
# }


resource "bindplane_configuration_v2" "configuration" {
lifecycle {
create_before_destroy = true
Expand All @@ -295,85 +399,14 @@ resource "bindplane_configuration_v2" "configuration" {
name = bindplane_source.otlp.name

// Route all telemetry types to datadog
route {
components = [
"destinations/${bindplane_destination.datadog.id}"
]
}

// route logs to loki
route {
telemetry_type = "logs"
components = [
"destinations/${bindplane_destination.loki.id}"
]
}

// route traces to google
route {
telemetry_type = "traces"
components = [
"destinations/${bindplane_destination.google.id}"
]
}
}

source {
name = bindplane_source.journald.name
processors = [
bindplane_processor_bundle.bundle.name,
]

route {
components = [
"destinations/${bindplane_destination.custom.id}"
]
}

route {
components = [
"destinations/${bindplane_destination.google.id}"
]
}

route {
components = [
"destinations/${bindplane_destination.loki.id}"
]
}
}

source {
name = bindplane_source.host.name
route {
telemetry_type = "metrics"
components = [
"destinations/${bindplane_destination.google.id}"
"destinations/${bindplane_destination.datadog.id}"
]
}
}

destination {
route_id = bindplane_destination.custom.id
name = bindplane_destination.custom.name
processors = [
bindplane_processor.batch.name,

// order matters here
bindplane_processor.time-parse-http-datatime.name
]
}

destination {
route_id = bindplane_destination.google.id
name = bindplane_destination.google.name
}

destination {
route_id = bindplane_destination.loki.id
name = bindplane_destination.loki.name
}

destination {
route_id = bindplane_destination.datadog.id
name = bindplane_destination.datadog.name
Expand Down
24 changes: 24 additions & 0 deletions test/local/out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: bindplane.observiq.com/v2beta
kind: Configuration
metadata:
name: v1-a
labels:
platform: linux
spec:
contentType: ""
measurementInterval: ""
disableLegacyEnvVarNormalization: false
sources:
- id: 01JKKNZZERHCJ01ZDV2M0C68ZX
name: example-otlp-default
routes:
logs+metrics+traces:
- id: "0"
components:
- destinations/01JKKP03XRXRZJ64T1DC23FQRG
destinations:
- id: 01JKKP03XRXRZJ64T1DC23FQRG
name: dev
selector:
matchLabels:
configuration: v1-a

0 comments on commit 9aa5416

Please sign in to comment.