Skip to content

Commit fa099a8

Browse files
authored
Merge pull request #135 from kube-logging/feat/bytesconnector-confgen
feat: add bytes connector
2 parents 186d409 + 98c1370 commit fa099a8

File tree

6 files changed

+88
-4
lines changed

6 files changed

+88
-4
lines changed

Diff for: internal/controller/telemetry/collector_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import (
5050
const (
5151
otelCollectorKind = "OpenTelemetryCollector"
5252
requeueDelayOnFailedTenant = 20 * time.Second
53-
axoflowOtelCollectorImageRef = "ghcr.io/axoflow/axoflow-otel-collector/axoflow-otel-collector:0.112.0-dev10"
53+
axoflowOtelCollectorImageRef = "ghcr.io/axoflow/axoflow-otel-collector/axoflow-otel-collector:0.112.0-dev12"
5454
)
5555

5656
var (

Diff for: internal/controller/telemetry/otel_conf_gen/otel_col_conf_test_fixtures/complex.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
connectors:
2+
bytes/exporter:
3+
logs:
4+
otelcol_exporter_sent_log_records_bytes:
5+
description:
6+
Bytes of log records successfully sent to destination
7+
attributes:
8+
- key: exporter
29
count/output_metrics:
310
logs:
411
telemetry_controller_output_log_count:
@@ -371,6 +378,7 @@ service:
371378
exporters:
372379
- otlphttp/collector_loki-test-output
373380
- count/output_metrics
381+
- bytes/exporter
374382
processors:
375383
- memory_limiter
376384
- attributes/exporter_name_loki-test-output
@@ -380,6 +388,7 @@ service:
380388
exporters:
381389
- otlp/collector_otlp-test-output
382390
- count/output_metrics
391+
- bytes/exporter
383392
processors:
384393
- memory_limiter
385394
- attributes/exporter_name_otlp-test-output
@@ -390,6 +399,7 @@ service:
390399
exporters:
391400
- otlp/collector_otlp-test-output-2
392401
- count/output_metrics
402+
- bytes/exporter
393403
processors:
394404
- memory_limiter
395405
- attributes/exporter_name_otlp-test-output-2
@@ -399,6 +409,7 @@ service:
399409
exporters:
400410
- fluentforwardexporter/collector_fluentforward-test-output
401411
- count/output_metrics
412+
- bytes/exporter
402413
processors:
403414
- memory_limiter
404415
- attributes/exporter_name_fluentforward-test-output
@@ -408,6 +419,7 @@ service:
408419
exporters:
409420
- otlp/collector_otlp-test-output-3
410421
- count/output_metrics
422+
- bytes/exporter
411423
processors:
412424
- memory_limiter
413425
- attributes/exporter_name_otlp-test-output-3
@@ -468,6 +480,15 @@ service:
468480
- attributes/metricattributes
469481
receivers:
470482
- count/output_metrics
483+
metrics/output_bytes:
484+
exporters:
485+
- prometheus/message_metrics_exporter
486+
processors:
487+
- memory_limiter
488+
- deltatocumulative
489+
- attributes/metricattributes
490+
receivers:
491+
- bytes/exporter
471492
metrics/tenant:
472493
exporters:
473494
- prometheus/message_metrics_exporter

Diff for: internal/controller/telemetry/otel_conf_gen/otel_conf_gen.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func (cfgInput *OtelColConfigInput) generateReceivers() map[string]any {
162162
func (cfgInput *OtelColConfigInput) generateConnectors() map[string]any {
163163
connectors := make(map[string]any)
164164
maps.Copy(connectors, connector.GenerateCountConnectors())
165+
maps.Copy(connectors, connector.GenerateBytesConnectors())
165166

166167
for _, tenant := range cfgInput.Tenants {
167168
// Generate routing connector for the tenant's subscription if it has any
@@ -189,6 +190,7 @@ func (cfgInput *OtelColConfigInput) generateConnectors() map[string]any {
189190

190191
func (cfgInput *OtelColConfigInput) generateNamedPipelines() map[string]*otelv1beta1.Pipeline {
191192
const outputCountConnectorName = "count/output_metrics"
193+
const outputBytesConnectorName = "bytes/exporter"
192194

193195
var namedPipelines = make(map[string]*otelv1beta1.Pipeline)
194196
tenants := []string{}
@@ -235,15 +237,15 @@ func (cfgInput *OtelColConfigInput) generateNamedPipelines() map[string]*otelv1b
235237
var exporters []string
236238

237239
if output.Output.Spec.OTLPGRPC != nil {
238-
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName}
240+
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName, outputBytesConnectorName}
239241
}
240242

241243
if output.Output.Spec.OTLPHTTP != nil {
242-
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName}
244+
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName, outputBytesConnectorName}
243245
}
244246

245247
if output.Output.Spec.Fluentforward != nil {
246-
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName}
248+
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName, outputBytesConnectorName}
247249
}
248250
if cfgInput.Debug {
249251
exporters = append(exporters, "debug")

Diff for: internal/controller/telemetry/otel_conf_gen/otel_conf_gen_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ func TestOtelColConfigInput_generateNamedPipelines(t *testing.T) {
497497
[]string{"deltatocumulative", "attributes/metricattributes"},
498498
[]string{"prometheus/message_metrics_exporter"},
499499
),
500+
"metrics/output_bytes": pipeline.GeneratePipeline(
501+
[]string{"bytes/exporter"},
502+
[]string{"deltatocumulative", "attributes/metricattributes"},
503+
[]string{"prometheus/message_metrics_exporter"},
504+
),
500505
"metrics/tenant": pipeline.GeneratePipeline(
501506
[]string{"count/tenant_metrics"},
502507
[]string{"deltatocumulative", "attributes/metricattributes"},
@@ -708,6 +713,11 @@ func TestOtelColConfigInput_generateNamedPipelines(t *testing.T) {
708713
Processors: []string{"deltatocumulative", "attributes/metricattributes"},
709714
Exporters: []string{"prometheus/message_metrics_exporter"},
710715
},
716+
"metrics/output_bytes": {
717+
Receivers: []string{"bytes/exporter"},
718+
Processors: []string{"deltatocumulative", "attributes/metricattributes"},
719+
Exporters: []string{"prometheus/message_metrics_exporter"},
720+
},
711721
"metrics/tenant": {
712722
Receivers: []string{"count/tenant_metrics"},
713723
Processors: []string{"deltatocumulative", "attributes/metricattributes"},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright © 2024 Kube logging authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package connector
16+
17+
import "github.com/kube-logging/telemetry-controller/internal/controller/telemetry/utils"
18+
19+
type BytesConnectorAttributes struct {
20+
Key *string `json:"key,omitempty"`
21+
DefaultValue *string `json:"default_value,omitempty"`
22+
}
23+
24+
type BytesConnector struct {
25+
Description string `json:"description,omitempty"`
26+
Attributes []BytesConnectorAttributes `json:"attributes,omitempty"`
27+
}
28+
29+
func GenerateBytesConnectors() map[string]any {
30+
bytesConnectors := make(map[string]any)
31+
32+
bytesConnectors["bytes/exporter"] = map[string]any{
33+
"logs": map[string]BytesConnector{
34+
"otelcol_exporter_sent_log_records_bytes": {
35+
Description: "Bytes of log records successfully sent to destination",
36+
Attributes: []BytesConnectorAttributes{{
37+
Key: utils.ToPtr("exporter"),
38+
}},
39+
},
40+
},
41+
}
42+
43+
return bytesConnectors
44+
45+
}

Diff for: internal/controller/telemetry/pipeline/pipeline.go

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ func GenerateMetricsPipelines() map[string]*otelv1beta1.Pipeline {
6363
Exporters: []string{"prometheus/message_metrics_exporter"},
6464
}
6565

66+
metricsPipelines["metrics/output_bytes"] = &otelv1beta1.Pipeline{
67+
Receivers: []string{"bytes/exporter"},
68+
Processors: []string{"deltatocumulative", "attributes/metricattributes"},
69+
Exporters: []string{"prometheus/message_metrics_exporter"},
70+
}
71+
6672
return metricsPipelines
6773
}
6874

0 commit comments

Comments
 (0)