Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add cloud provider info to the gateways #1778

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
92bb30e
add cloud provider attributes to the gateways, initial commit
hisarbalik Jan 21, 2025
32651c0
add get gardener shoot-info getter
hisarbalik Jan 22, 2025
1f4476d
Merge branch 'main' into add-metricpipeline-cloud-provider-attributes
hisarbalik Jan 22, 2025
50d6ae3
update unit tests with cluster info attributes
hisarbalik Jan 22, 2025
25f8e83
update RBAC rules
hisarbalik Jan 22, 2025
9c274dd
fix wrong pipeline service configuation
hisarbalik Jan 22, 2025
7983e62
fix wrong pipeline service configuation tests
hisarbalik Jan 22, 2025
849d134
add configmap shhot-info from namespace kube-system to the cache
hisarbalik Jan 22, 2025
62da594
re-generate sec-scan-config.yaml
hisarbalik Jan 22, 2025
66f9394
adjust cluster roles for OTel based gateways
hisarbalik Jan 22, 2025
2863e47
fix otel gateway unit tests
hisarbalik Jan 22, 2025
469115e
revert doc changes
hisarbalik Jan 22, 2025
84d7847
update cache config
hisarbalik Jan 22, 2025
4148ecb
update cache settings
hisarbalik Jan 22, 2025
f7f1ed7
update rbac rules
hisarbalik Jan 22, 2025
6bb0968
add unit test for cluster info getter
hisarbalik Jan 23, 2025
edeb602
refactor the cluster info getter
hisarbalik Jan 23, 2025
3792f30
fix linter issues
hisarbalik Jan 23, 2025
30b5e40
Merge branch 'main' into add-metricpipeline-cloud-provider-attributes
hisarbalik Jan 23, 2025
8e7ae43
add host.arch and host.type attrbiutes to the k8sattribute processor
hisarbalik Jan 24, 2025
6b28648
Merge branch 'add-metricpipeline-cloud-provider-attributes' of github…
hisarbalik Jan 24, 2025
e8fcc03
Merge branch 'main' into add-metricpipeline-cloud-provider-attributes
hisarbalik Jan 24, 2025
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
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rules:
- ""
resources:
- secrets
- configmaps
verbs:
- get
- list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data:
- filter/drop-if-input-source-runtime
- filter/drop-if-input-source-prometheus
- filter/drop-if-input-source-istio
- resource/insert-cluster-name
- resource/insert-cluster-attributes
- batch
exporters:
- otlp/load-test-1
Expand All @@ -58,7 +58,7 @@ data:
- filter/drop-if-input-source-runtime
- filter/drop-if-input-source-prometheus
- filter/drop-if-input-source-istio
- resource/insert-cluster-name
- resource/insert-cluster-attributes
- batch
exporters:
- otlp/load-test-2
Expand All @@ -85,7 +85,7 @@ data:
- filter/drop-if-input-source-runtime
- filter/drop-if-input-source-prometheus
- filter/drop-if-input-source-istio
- resource/insert-cluster-name
- resource/insert-cluster-attributes
- batch
exporters:
- otlp/load-test-3
Expand Down Expand Up @@ -165,7 +165,7 @@ data:
name: k8s.pod.uid
- sources:
- from: connection
resource/insert-cluster-name:
resource/insert-cluster-attributes:
attributes:
- action: insert
key: k8s.cluster.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data:
- filter/drop-if-input-source-runtime
- filter/drop-if-input-source-prometheus
- filter/drop-if-input-source-istio
- resource/insert-cluster-name
- resource/insert-cluster-attributes
- batch
exporters:
- otlp/load-test-1
Expand Down Expand Up @@ -97,7 +97,7 @@ data:
name: k8s.pod.uid
- sources:
- from: connection
resource/insert-cluster-name:
resource/insert-cluster-attributes:
attributes:
- action: insert
key: k8s.cluster.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,25 @@ func extractLabels() []config.ExtractLabel {
Key: "app",
TagName: "kyma.app_name",
},
{
From: "node",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know in case of k3d how this works ? will it be left empty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for k3d and any cluster that doesn't use the labels on nodes, the attributes will not be present on the telemetry data being processed

Key: "topology.kubernetes.io/region",
TagName: "cloud.region",
},
{
From: "node",
Key: "topology.kubernetes.io/zone",
TagName: "cloud.availability_zone",
},
{
From: "node",
Key: "node.kubernetes.io/instance-type",
TagName: "host.type",
},
{
From: "node",
Key: "kubernetes.io/arch",
TagName: "host.arch",
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ func TestK8sAttributesProcessorConfig(t *testing.T) {
Key: "app",
TagName: "kyma.app_name",
},
{
From: "node",
Key: "topology.kubernetes.io/region",
TagName: "cloud.region",
},
{
From: "node",
Key: "topology.kubernetes.io/zone",
TagName: "cloud.availability_zone",
},
{
From: "node",
Key: "node.kubernetes.io/instance-type",
TagName: "host.type",
},
{
From: "node",
Key: "kubernetes.io/arch",
TagName: "host.arch",
},
}

config := K8sAttributesProcessorConfig()
Expand Down
21 changes: 19 additions & 2 deletions internal/otelcollector/config/gatewayprocs/resource_procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ import (
"github.com/kyma-project/telemetry-manager/internal/otelcollector/config"
)

func InsertClusterNameProcessorConfig() *config.ResourceProcessor {
func InsertClusterAttributesProcessorConfig(clusterName, cloudProvider string) *config.ResourceProcessor {
if cloudProvider != "" {
return &config.ResourceProcessor{
Attributes: []config.AttributeAction{
{
Action: "insert",
Key: "k8s.cluster.name",
Value: clusterName,
},
{
Action: "insert",
Key: "cloud.provider",
Value: cloudProvider,
},
},
}
}

return &config.ResourceProcessor{
Attributes: []config.AttributeAction{
{
Action: "insert",
Key: "k8s.cluster.name",
Value: "${KUBERNETES_SERVICE_HOST}",
Value: clusterName,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ func TestInsertClusterNameProcessorConfig(t *testing.T) {
{
Action: "insert",
Key: "k8s.cluster.name",
Value: "${KUBERNETES_SERVICE_HOST}",
Value: "test-cluster",
},
{
Action: "insert",
Key: "cloud.provider",
Value: "test-cloud-provider",
},
}

config := InsertClusterNameProcessorConfig()
config := InsertClusterAttributesProcessorConfig("test-cluster", "test-cloud-provider")

require.ElementsMatch(expectedAttributeActions, config.Attributes, "Attributes should match")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/otelcollector/config/log/gateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type Receivers struct {
type Processors struct {
config.BaseProcessors `yaml:",inline"`

K8sAttributes *config.K8sAttributesProcessor `yaml:"k8sattributes,omitempty"`
InsertClusterName *config.ResourceProcessor `yaml:"resource/insert-cluster-name,omitempty"`
DropKymaAttributes *config.ResourceProcessor `yaml:"resource/drop-kyma-attributes,omitempty"`
K8sAttributes *config.K8sAttributesProcessor `yaml:"k8sattributes,omitempty"`
InsertClusterAttributes *config.ResourceProcessor `yaml:"resource/insert-cluster-attributes,omitempty"`
DropKymaAttributes *config.ResourceProcessor `yaml:"resource/drop-kyma-attributes,omitempty"`
}

type Exporters map[string]Exporter
Expand Down
11 changes: 8 additions & 3 deletions internal/otelcollector/config/log/gateway/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ type Builder struct {
Reader client.Reader
}

func (b *Builder) Build(ctx context.Context, pipelines []telemetryv1alpha1.LogPipeline) (*Config, otlpexporter.EnvVars, error) {
type BuildOptions struct {
ClusterName string
CloudProvider string
}

func (b *Builder) Build(ctx context.Context, pipelines []telemetryv1alpha1.LogPipeline, opts BuildOptions) (*Config, otlpexporter.EnvVars, error) {
cfg := &Config{
Base: config.Base{
Service: config.DefaultService(make(config.Pipelines)),
Extensions: config.DefaultExtensions(),
},
Receivers: makeReceiversConfig(),
Processors: makeProcessorsConfig(),
Processors: makeProcessorsConfig(opts),
Exporters: make(Exporters),
}

Expand Down Expand Up @@ -99,7 +104,7 @@ func makePipelineConfig(exporterIDs ...string) config.Pipeline {
Processors: []string{
"memory_limiter",
"k8sattributes",
"resource/insert-cluster-name",
"resource/insert-cluster-attributes",
"batch",
},
Exporters: exporterIDs,
Expand Down
68 changes: 56 additions & 12 deletions internal/otelcollector/config/log/gateway/config_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ func TestBuildConfig(t *testing.T) {
t.Run("otlp exporter endpoint", func(t *testing.T) {
collectorConfig, envVars, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput(testutils.OTLPEndpoint("http://localhost")).Build(),
})
},
BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
},
)
require.NoError(t, err)

const endpointEnvVar = "OTLP_ENDPOINT_TEST"
Expand All @@ -42,7 +47,10 @@ func TestBuildConfig(t *testing.T) {
})

t.Run("secure", func(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build()})
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)
require.Contains(t, collectorConfig.Exporters, "otlp/test")

Expand All @@ -52,7 +60,10 @@ func TestBuildConfig(t *testing.T) {

t.Run("insecure", func(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-insecure").WithOTLPOutput(testutils.OTLPEndpoint("http://localhost")).Build()})
testutils.NewLogPipelineBuilder().WithName("test-insecure").WithOTLPOutput(testutils.OTLPEndpoint("http://localhost")).Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)
require.Contains(t, collectorConfig.Exporters, "otlp/test-insecure")

Expand All @@ -63,6 +74,9 @@ func TestBuildConfig(t *testing.T) {
t.Run("basic auth", func(t *testing.T) {
collectorConfig, envVars, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-basic-auth").WithOTLPOutput(testutils.OTLPBasicAuth("user", "password")).Build(),
}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)
require.Contains(t, collectorConfig.Exporters, "otlp/test-basic-auth")
Expand All @@ -82,6 +96,9 @@ func TestBuildConfig(t *testing.T) {
t.Run("custom header", func(t *testing.T) {
collectorConfig, envVars, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-custom-header").WithOTLPOutput(testutils.OTLPCustomHeader("Authorization", "TOKEN_VALUE", "Api-Token")).Build(),
}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)
require.Contains(t, collectorConfig.Exporters, "otlp/test-custom-header")
Expand All @@ -99,6 +116,9 @@ func TestBuildConfig(t *testing.T) {
t.Run("mtls", func(t *testing.T) {
collectorConfig, envVars, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-mtls").WithOTLPOutput(testutils.OTLPClientTLSFromString("ca", "cert", "key")).Build(),
}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)
require.Contains(t, collectorConfig.Exporters, "otlp/test-mtls")
Expand All @@ -115,7 +135,10 @@ func TestBuildConfig(t *testing.T) {
})

t.Run("extensions", func(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithOTLPOutput().Build()})
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)

require.NotEmpty(t, collectorConfig.Extensions.HealthCheck.Endpoint)
Expand All @@ -125,7 +148,10 @@ func TestBuildConfig(t *testing.T) {
})

t.Run("telemetry", func(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithOTLPOutput().Build()})
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)

metricreaders := []config.MetricReader{
Expand All @@ -147,7 +173,10 @@ func TestBuildConfig(t *testing.T) {
})

t.Run("single pipeline queue size", func(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build()})
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)
require.Equal(t, maxQueueSize, collectorConfig.Exporters["otlp/test"].OTLP.SendingQueue.QueueSize, "Pipeline should have the full queue size")
})
Expand All @@ -156,7 +185,10 @@ func TestBuildConfig(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-1").WithOTLPOutput().Build(),
testutils.NewLogPipelineBuilder().WithName("test-2").WithOTLPOutput().Build(),
testutils.NewLogPipelineBuilder().WithName("test-3").WithOTLPOutput().Build()})
testutils.NewLogPipelineBuilder().WithName("test-3").WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})

require.NoError(t, err)

Expand All @@ -167,15 +199,18 @@ func TestBuildConfig(t *testing.T) {
})

t.Run("single pipeline topology", func(t *testing.T) {
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build()})
collectorConfig, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)

require.Contains(t, collectorConfig.Service.Pipelines, "logs/test")
require.Contains(t, collectorConfig.Service.Pipelines["logs/test"].Receivers, "otlp")

require.Equal(t, collectorConfig.Service.Pipelines["logs/test"].Processors[0], "memory_limiter")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test"].Processors[1], "k8sattributes")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test"].Processors[2], "resource/insert-cluster-name")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test"].Processors[2], "resource/insert-cluster-attributes")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test"].Processors[3], "batch")

require.Contains(t, collectorConfig.Service.Pipelines["logs/test"].Exporters, "otlp/test")
Expand All @@ -184,7 +219,10 @@ func TestBuildConfig(t *testing.T) {
t.Run("multi pipeline topology", func(t *testing.T) {
collectorConfig, envVars, err := sut.Build(context.Background(), []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-1").WithOTLPOutput().Build(),
testutils.NewLogPipelineBuilder().WithName("test-2").WithOTLPOutput().Build()})
testutils.NewLogPipelineBuilder().WithName("test-2").WithOTLPOutput().Build()}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)

require.Contains(t, collectorConfig.Exporters, "otlp/test-1")
Expand All @@ -195,15 +233,15 @@ func TestBuildConfig(t *testing.T) {
require.Contains(t, collectorConfig.Service.Pipelines["logs/test-1"].Receivers, "otlp")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-1"].Processors[0], "memory_limiter")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-1"].Processors[1], "k8sattributes")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-1"].Processors[2], "resource/insert-cluster-name")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-1"].Processors[2], "resource/insert-cluster-attributes")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-1"].Processors[3], "batch")

require.Contains(t, collectorConfig.Service.Pipelines, "logs/test-2")
require.Contains(t, collectorConfig.Service.Pipelines["logs/test-2"].Exporters, "otlp/test-2")
require.Contains(t, collectorConfig.Service.Pipelines["logs/test-2"].Receivers, "otlp")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-2"].Processors[0], "memory_limiter")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-2"].Processors[1], "k8sattributes")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-2"].Processors[2], "resource/insert-cluster-name")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-2"].Processors[2], "resource/insert-cluster-attributes")
require.Equal(t, collectorConfig.Service.Pipelines["logs/test-2"].Processors[3], "batch")

require.Contains(t, envVars, "OTLP_ENDPOINT_TEST_1")
Expand All @@ -213,6 +251,9 @@ func TestBuildConfig(t *testing.T) {
t.Run("marshaling", func(t *testing.T) {
config, _, err := sut.Build(context.Background(), []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test").WithOTLPOutput().Build(),
}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.NoError(t, err)

Expand All @@ -230,6 +271,9 @@ func TestBuildConfig(t *testing.T) {
t.Run("failed to make otlp exporter config", func(t *testing.T) {
_, _, err := sut.Build(ctx, []telemetryv1alpha1.LogPipeline{
testutils.NewLogPipelineBuilder().WithName("test-fail").WithOTLPOutput(testutils.OTLPBasicAuthFromSecret("nonexistent-secret", "default", "user", "password")).Build(),
}, BuildOptions{
ClusterName: "test-cluster",
CloudProvider: "test-cloud-provider",
})
require.Error(t, err)
require.ErrorContains(t, err, "failed to make otlp exporter config")
Expand Down
Loading
Loading