Skip to content

Commit 9aa5416

Browse files
committed
fix issue with telemetry type and route id not persisting
1 parent 38b8e83 commit 9aa5416

File tree

4 files changed

+225
-72
lines changed

4 files changed

+225
-72
lines changed

docs/resources/bindplane_configuration_v2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Configuration V2 builds upon [Configuration V1](./bindplane_configuration.md) by
5252
| ------------------- | ------------ | -------- | ---------------------------- |
5353
| `name` | string | required | The source name. |
5454
| `processors` | list(string) | optional | One or more processor names to attach to the destination. |
55+
| `route_id` | string | required | An arbitrary string that can be used to configure routes to this destination. |
5556

5657
### Rollout Options Block
5758

provider/resource_configuration_v2.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,95 @@ func resourceConfigurationV2Read(d *schema.ResourceData, meta any) error {
482482
processors = append(processors, strings.Split(p.Name, ":")[0])
483483
}
484484
source["processors"] = processors
485+
486+
logRoutes := s.Routes.Logs
487+
if len(logRoutes) > 0 {
488+
routes := []map[string]any{}
489+
for _, r := range logRoutes {
490+
routes = append(routes, map[string]any{
491+
"telemetry_type": "logs",
492+
"components": r.Components,
493+
})
494+
}
495+
source["route"] = routes
496+
}
497+
metricRoutes := s.Routes.Metrics
498+
if len(metricRoutes) > 0 {
499+
routes := []map[string]any{}
500+
for _, r := range metricRoutes {
501+
routes = append(routes, map[string]any{
502+
"telemetry_type": "metrics",
503+
"components": r.Components,
504+
})
505+
}
506+
source["route"] = routes
507+
}
508+
traceRoutes := s.Routes.Traces
509+
if len(traceRoutes) > 0 {
510+
routes := []map[string]any{}
511+
for _, r := range traceRoutes {
512+
routes = append(routes, map[string]any{
513+
"telemetry_type": "traces",
514+
"components": r.Components,
515+
})
516+
}
517+
source["route"] = routes
518+
}
519+
logMetricRoutes := s.Routes.LogsMetrics
520+
if len(logMetricRoutes) > 0 {
521+
routes := []map[string]any{}
522+
for _, r := range logMetricRoutes {
523+
routes = append(routes, map[string]any{
524+
"telemetry_type": "logs+metrics",
525+
"components": r.Components,
526+
})
527+
}
528+
source["route"] = routes
529+
}
530+
logTraceRoutes := s.Routes.LogsTraces
531+
if len(logTraceRoutes) > 0 {
532+
routes := []map[string]any{}
533+
for _, r := range logTraceRoutes {
534+
routes = append(routes, map[string]any{
535+
"telemetry_type": "logs+traces",
536+
"components": r.Components,
537+
})
538+
}
539+
source["route"] = routes
540+
}
541+
metricTraceRoutes := s.Routes.MetricsTraces
542+
if len(metricTraceRoutes) > 0 {
543+
routes := []map[string]any{}
544+
for _, r := range metricTraceRoutes {
545+
routes = append(routes, map[string]any{
546+
"telemetry_type": "metrics+traces",
547+
"components": r.Components,
548+
})
549+
}
550+
source["route"] = routes
551+
}
552+
logMetricTraceRoutes := s.Routes.LogsMetricsTraces
553+
if len(logMetricTraceRoutes) > 0 {
554+
routes := []map[string]any{}
555+
for _, r := range logMetricTraceRoutes {
556+
routes = append(routes, map[string]any{
557+
"telemetry_type": "logs+metrics+traces",
558+
"components": r.Components,
559+
})
560+
}
561+
source["route"] = routes
562+
}
563+
485564
sourceBlocks = append(sourceBlocks, source)
486565
}
487566
if err := d.Set("source", sourceBlocks); err != nil {
488567
return err
489568
}
490569

570+
// Save the current state here so we can retrieve the saved
571+
// route ID
572+
stateDestinationBlocks := d.Get("destination").([]any)
573+
491574
destinationBlocks := []map[string]any{}
492575
for _, d := range config.Spec.Destinations {
493576
destination := map[string]any{}
@@ -497,8 +580,20 @@ func resourceConfigurationV2Read(d *schema.ResourceData, meta any) error {
497580
processors = append(processors, strings.Split(p.Name, ":")[0])
498581
}
499582
destination["processors"] = processors
583+
584+
// Retrieve the saved route IDs from state and copy them
585+
// to the new destination blocks before calling d.Set.
586+
for _, stateDestination := range stateDestinationBlocks {
587+
stateDestination := stateDestination.(map[string]any)
588+
if stateDestination["name"] == destination["name"] {
589+
destination["route_id"] = stateDestination["route_id"]
590+
continue
591+
}
592+
}
593+
500594
destinationBlocks = append(destinationBlocks, destination)
501595
}
596+
502597
if err := d.Set("destination", destinationBlocks); err != nil {
503598
return err
504599
}

test/local/main.tf

Lines changed: 105 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,110 @@ resource "bindplane_connector" "routing" {
281281
)
282282
}
283283

284+
# resource "bindplane_configuration_v2" "configuration" {
285+
# lifecycle {
286+
# create_before_destroy = true
287+
# }
288+
289+
# rollout = true
290+
291+
# name = "my-config-v2"
292+
# platform = "linux"
293+
294+
# source {
295+
# name = bindplane_source.otlp.name
296+
297+
# // Route all telemetry types to datadog
298+
# route {
299+
# components = [
300+
# "destinations/${bindplane_destination.datadog.id}"
301+
# ]
302+
# }
303+
304+
# // route logs to loki
305+
# route {
306+
# telemetry_type = "logs"
307+
# components = [
308+
# "destinations/${bindplane_destination.loki.id}"
309+
# ]
310+
# }
311+
312+
# // route traces to google
313+
# route {
314+
# telemetry_type = "traces"
315+
# components = [
316+
# "destinations/${bindplane_destination.google.id}"
317+
# ]
318+
# }
319+
# }
320+
321+
# source {
322+
# name = bindplane_source.journald.name
323+
# processors = [
324+
# bindplane_processor_bundle.bundle.name,
325+
# ]
326+
327+
# route {
328+
# components = [
329+
# "destinations/${bindplane_destination.custom.id}"
330+
# ]
331+
# }
332+
333+
# route {
334+
# components = [
335+
# "destinations/${bindplane_destination.google.id}"
336+
# ]
337+
# }
338+
339+
# route {
340+
# components = [
341+
# "destinations/${bindplane_destination.loki.id}"
342+
# ]
343+
# }
344+
# }
345+
346+
# source {
347+
# name = bindplane_source.host.name
348+
# route {
349+
# telemetry_type = "metrics"
350+
# components = [
351+
# "destinations/${bindplane_destination.google.id}"
352+
# ]
353+
# }
354+
# }
355+
356+
# destination {
357+
# route_id = bindplane_destination.custom.id
358+
# name = bindplane_destination.custom.name
359+
# processors = [
360+
# bindplane_processor.batch.name,
361+
362+
# // order matters here
363+
# bindplane_processor.time-parse-http-datatime.name
364+
# ]
365+
# }
366+
367+
# destination {
368+
# route_id = bindplane_destination.google.id
369+
# name = bindplane_destination.google.name
370+
# }
371+
372+
# destination {
373+
# route_id = bindplane_destination.loki.id
374+
# name = bindplane_destination.loki.name
375+
# }
376+
377+
# destination {
378+
# route_id = bindplane_destination.datadog.id
379+
# name = bindplane_destination.datadog.name
380+
# }
381+
382+
# extensions = [
383+
# bindplane_extension.pprof.name
384+
# ]
385+
# }
386+
387+
284388
resource "bindplane_configuration_v2" "configuration" {
285389
lifecycle {
286390
create_before_destroy = true
@@ -295,85 +399,14 @@ resource "bindplane_configuration_v2" "configuration" {
295399
name = bindplane_source.otlp.name
296400

297401
// Route all telemetry types to datadog
298-
route {
299-
components = [
300-
"destinations/${bindplane_destination.datadog.id}"
301-
]
302-
}
303-
304-
// route logs to loki
305402
route {
306403
telemetry_type = "logs"
307404
components = [
308-
"destinations/${bindplane_destination.loki.id}"
309-
]
310-
}
311-
312-
// route traces to google
313-
route {
314-
telemetry_type = "traces"
315-
components = [
316-
"destinations/${bindplane_destination.google.id}"
317-
]
318-
}
319-
}
320-
321-
source {
322-
name = bindplane_source.journald.name
323-
processors = [
324-
bindplane_processor_bundle.bundle.name,
325-
]
326-
327-
route {
328-
components = [
329-
"destinations/${bindplane_destination.custom.id}"
330-
]
331-
}
332-
333-
route {
334-
components = [
335-
"destinations/${bindplane_destination.google.id}"
336-
]
337-
}
338-
339-
route {
340-
components = [
341-
"destinations/${bindplane_destination.loki.id}"
342-
]
343-
}
344-
}
345-
346-
source {
347-
name = bindplane_source.host.name
348-
route {
349-
telemetry_type = "metrics"
350-
components = [
351-
"destinations/${bindplane_destination.google.id}"
405+
"destinations/${bindplane_destination.datadog.id}"
352406
]
353407
}
354408
}
355409

356-
destination {
357-
route_id = bindplane_destination.custom.id
358-
name = bindplane_destination.custom.name
359-
processors = [
360-
bindplane_processor.batch.name,
361-
362-
// order matters here
363-
bindplane_processor.time-parse-http-datatime.name
364-
]
365-
}
366-
367-
destination {
368-
route_id = bindplane_destination.google.id
369-
name = bindplane_destination.google.name
370-
}
371-
372-
destination {
373-
route_id = bindplane_destination.loki.id
374-
name = bindplane_destination.loki.name
375-
}
376-
377410
destination {
378411
route_id = bindplane_destination.datadog.id
379412
name = bindplane_destination.datadog.name

test/local/out.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: bindplane.observiq.com/v2beta
2+
kind: Configuration
3+
metadata:
4+
name: v1-a
5+
labels:
6+
platform: linux
7+
spec:
8+
contentType: ""
9+
measurementInterval: ""
10+
disableLegacyEnvVarNormalization: false
11+
sources:
12+
- id: 01JKKNZZERHCJ01ZDV2M0C68ZX
13+
name: example-otlp-default
14+
routes:
15+
logs+metrics+traces:
16+
- id: "0"
17+
components:
18+
- destinations/01JKKP03XRXRZJ64T1DC23FQRG
19+
destinations:
20+
- id: 01JKKP03XRXRZJ64T1DC23FQRG
21+
name: dev
22+
selector:
23+
matchLabels:
24+
configuration: v1-a

0 commit comments

Comments
 (0)