Skip to content

Commit

Permalink
chore: Refactor otelcollector and fluentbit config to use default par…
Browse files Browse the repository at this point in the history
…ameters
  • Loading branch information
TeodorSAP committed Nov 27, 2024
1 parent a7892d4 commit eea858c
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ override:
path: ^internal/reconciler/telemetry$
- threshold: 74
path: ^internal/reconciler/tracepipeline$
- threshold: 82
- threshold: 76
path: ^internal/resources/otelcollector$
- threshold: 78
path: ^internal/resources/selfmonitor$
Expand Down
42 changes: 4 additions & 38 deletions controllers/telemetry/logpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -51,32 +50,11 @@ import (
)

const (
// FluentBit
fbBaseName = "telemetry-fluent-bit"

// OTel
otelLogGatewayName = "telemetry-log-gateway"
)

var (
// FluentBit
fbCPULimit = resource.MustParse("1")
fbMemoryLimit = resource.MustParse("1Gi")
fbCPURequest = resource.MustParse("100m")
fbMemoryRequest = resource.MustParse("50Mi")

// OTel
// TODO: Check if these values need to be adjusted
logGatewayBaseCPULimit = resource.MustParse("700m")
logGatewayDynamicCPULimit = resource.MustParse("500m")
logGatewayBaseMemoryLimit = resource.MustParse("500Mi")
logGatewayDynamicMemoryLimit = resource.MustParse("1500Mi")
logGatewayBaseCPURequest = resource.MustParse("100m")
logGatewayDynamicCPURequest = resource.MustParse("100m")
logGatewayBaseMemoryRequest = resource.MustParse("32Mi")
logGatewayDynamicMemoryRequest = resource.MustParse("0")
)

// LogPipelineController reconciles a LogPipeline object
type LogPipelineController struct {
client.Client
Expand Down Expand Up @@ -170,10 +148,6 @@ func configureFluentBitReconciler(client client.Client, config LogPipelineContro
logpipelinefluentbit.WithFluentBitImage(config.FluentBitImage),
logpipelinefluentbit.WithExporterImage(config.ExporterImage),
logpipelinefluentbit.WithPriorityClassName(config.FluentBitPriorityClassName),
logpipelinefluentbit.WithCPULimit(fbCPULimit),
logpipelinefluentbit.WithMemoryLimit(fbMemoryLimit),
logpipelinefluentbit.WithCPURequest(fbCPURequest),
logpipelinefluentbit.WithMemoryRequest(fbMemoryRequest),
)

pipelineValidator := &logpipelinefluentbit.Validator{
Expand Down Expand Up @@ -211,18 +185,10 @@ func configureOtelReconciler(client client.Client, config LogPipelineControllerC
BaseName: otelLogGatewayName,
Namespace: config.TelemetryNamespace,
},
Deployment: otelcollector.DeploymentConfig{
Image: config.OTelCollectorImage,
PriorityClassName: config.LogGatewayPriorityClassName,
BaseCPULimit: logGatewayBaseCPULimit,
DynamicCPULimit: logGatewayDynamicCPULimit,
BaseMemoryLimit: logGatewayBaseMemoryLimit,
DynamicMemoryLimit: logGatewayDynamicMemoryLimit,
BaseCPURequest: logGatewayBaseCPURequest,
DynamicCPURequest: logGatewayDynamicCPURequest,
BaseMemoryRequest: logGatewayBaseMemoryRequest,
DynamicMemoryRequest: logGatewayDynamicMemoryRequest,
},
Deployment: otelcollector.NewDeploymentConfig(
otelcollector.WithImage(config.OTelCollectorImage),
otelcollector.WithPriorityClassName(config.LogGatewayPriorityClassName),
),
OTLPServiceName: config.LogGatewayServiceName,
}

Expand Down
24 changes: 12 additions & 12 deletions controllers/telemetry/metricpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ func newMetricGatewayApplierDeleter(config MetricPipelineControllerConfig) *otel
BaseName: metricGatewayBaseName,
Namespace: config.TelemetryNamespace,
},
Deployment: otelcollector.DeploymentConfig{
Image: config.OTelCollectorImage,
PriorityClassName: config.MetricGatewayPriorityClassName,
BaseCPULimit: metricGatewayBaseCPULimit,
DynamicCPULimit: metricGatewayDynamicCPULimit,
BaseMemoryLimit: metricGatewayBaseMemoryLimit,
DynamicMemoryLimit: metricGatewayDynamicMemoryLimit,
BaseCPURequest: metricGatewayBaseCPURequest,
DynamicCPURequest: metricGatewayDynamicCPURequest,
BaseMemoryRequest: metricGatewayBaseMemoryRequest,
DynamicMemoryRequest: metricGatewayDynamicMemoryRequest,
},
Deployment: otelcollector.NewDeploymentConfig(
otelcollector.WithImage(config.OTelCollectorImage),
otelcollector.WithPriorityClassName(config.MetricGatewayPriorityClassName),
otelcollector.WithBaseCPULimit(metricGatewayBaseCPULimit),
otelcollector.WithDynamicCPULimit(metricGatewayDynamicCPULimit),
otelcollector.WithBaseMemoryLimit(metricGatewayBaseMemoryLimit),
otelcollector.WithDynamicMemoryLimit(metricGatewayDynamicMemoryLimit),
otelcollector.WithBaseCPURequest(metricGatewayBaseCPURequest),
otelcollector.WithDynamicCPURequest(metricGatewayDynamicCPURequest),
otelcollector.WithBaseMemoryRequest(metricGatewayBaseMemoryRequest),
otelcollector.WithDynamicMemoryRequest(metricGatewayDynamicMemoryRequest),
),
OTLPServiceName: config.MetricGatewayServiceName,
}

Expand Down
28 changes: 4 additions & 24 deletions controllers/telemetry/tracepipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -59,17 +58,6 @@ const (
traceGatewayBaseName = "telemetry-trace-gateway"
)

var (
traceGatewayBaseCPULimit = resource.MustParse("700m")
traceGatewayDynamicCPULimit = resource.MustParse("500m")
traceGatewayBaseMemoryLimit = resource.MustParse("500Mi")
traceGatewayDynamicMemoryLimit = resource.MustParse("1500Mi")
traceGatewayBaseCPURequest = resource.MustParse("100m")
traceGatewayDynamicCPURequest = resource.MustParse("100m")
traceGatewayBaseMemoryRequest = resource.MustParse("32Mi")
traceGatewayDynamicMemoryRequest = resource.MustParse("0")
)

// TracePipelineController reconciles a TracePipeline object
type TracePipelineController struct {
client.Client
Expand Down Expand Up @@ -149,18 +137,10 @@ func newTraceGatewayApplierDeleter(config TracePipelineControllerConfig) *otelco
BaseName: traceGatewayBaseName,
Namespace: config.TelemetryNamespace,
},
Deployment: otelcollector.DeploymentConfig{
Image: config.OTelCollectorImage,
PriorityClassName: config.TraceGatewayPriorityClassName,
BaseCPULimit: traceGatewayBaseCPULimit,
DynamicCPULimit: traceGatewayDynamicCPULimit,
BaseMemoryLimit: traceGatewayBaseMemoryLimit,
DynamicMemoryLimit: traceGatewayDynamicMemoryLimit,
BaseCPURequest: traceGatewayBaseCPURequest,
DynamicCPURequest: traceGatewayDynamicCPURequest,
BaseMemoryRequest: traceGatewayBaseMemoryRequest,
DynamicMemoryRequest: traceGatewayDynamicMemoryRequest,
},
Deployment: otelcollector.NewDeploymentConfig(
otelcollector.WithImage(config.OTelCollectorImage),
otelcollector.WithPriorityClassName(config.TraceGatewayPriorityClassName),
),
OTLPServiceName: config.TraceGatewayServiceName,
}

Expand Down
13 changes: 13 additions & 0 deletions internal/reconciler/logpipeline/fluentbit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import (
"github.com/kyma-project/telemetry-manager/internal/resources/fluentbit"
)

var (
defaultCPULimit = resource.MustParse("1")
defaultMemoryLimit = resource.MustParse("1Gi")
defaultCPURequest = resource.MustParse("100m")
defaultMemoryRequest = resource.MustParse("50Mi")
)

type Config struct {
DaemonSet types.NamespacedName
SectionsConfigMap types.NamespacedName
Expand Down Expand Up @@ -77,6 +84,12 @@ func NewConfig(baseName string, namespace string, options ...ConfigOption) *Conf
EnvConfigSecret: types.NamespacedName{Name: baseName + "-env", Namespace: namespace},
TLSFileConfigSecret: types.NamespacedName{Name: baseName + "-output-tls-config", Namespace: namespace},
DaemonSet: types.NamespacedName{Name: baseName, Namespace: namespace},
DaemonSetConfig: fluentbit.DaemonSetConfig{
CPULimit: defaultCPULimit,
MemoryLimit: defaultMemoryLimit,
CPURequest: defaultCPURequest,
MemoryRequest: defaultMemoryRequest,
},
}

for _, opt := range options {
Expand Down
92 changes: 92 additions & 0 deletions internal/resources/otelcollector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
)

var (
defaultBaseCPULimit = resource.MustParse("700m")
defaultDynamicCPULimit = resource.MustParse("500m")
defaultBaseMemoryLimit = resource.MustParse("500Mi")
defaultDynamicMemoryLimit = resource.MustParse("1500Mi")
defaultBaseCPURequest = resource.MustParse("100m")
defaultDynamicCPURequest = resource.MustParse("100m")
defaultBaseMemoryRequest = resource.MustParse("32Mi")
defaultDynamicMemoryRequest = resource.MustParse("0")
)

type Config struct {
BaseName string
Namespace string
Expand All @@ -29,6 +40,87 @@ type DeploymentConfig struct {
DynamicMemoryRequest resource.Quantity
}

type DeploymentConfigOption func(*DeploymentConfig)

func WithImage(image string) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.Image = image
}
}

func WithPriorityClassName(name string) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.PriorityClassName = name
}
}

func WithBaseCPULimit(limit resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.BaseCPULimit = limit
}
}

func WithDynamicCPULimit(limit resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.DynamicCPULimit = limit
}
}

func WithBaseMemoryLimit(limit resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.BaseMemoryLimit = limit
}
}

func WithDynamicMemoryLimit(limit resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.DynamicMemoryLimit = limit
}
}

func WithBaseCPURequest(request resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.BaseCPURequest = request
}
}

func WithDynamicCPURequest(request resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.DynamicCPURequest = request
}
}

func WithBaseMemoryRequest(request resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.BaseMemoryRequest = request
}
}

func WithDynamicMemoryRequest(request resource.Quantity) DeploymentConfigOption {
return func(c *DeploymentConfig) {
c.DynamicMemoryRequest = request
}
}

func NewDeploymentConfig(opts ...DeploymentConfigOption) DeploymentConfig {
config := DeploymentConfig{
BaseCPULimit: defaultBaseCPULimit,
DynamicCPULimit: defaultDynamicCPULimit,
BaseMemoryLimit: defaultBaseMemoryLimit,
DynamicMemoryLimit: defaultDynamicMemoryLimit,
BaseCPURequest: defaultBaseCPURequest,
DynamicCPURequest: defaultDynamicCPURequest,
BaseMemoryRequest: defaultBaseMemoryRequest,
DynamicMemoryRequest: defaultDynamicMemoryRequest,
}

for _, opt := range opts {
opt(&config)
}

return config
}

type AgentConfig struct {
Config

Expand Down

0 comments on commit eea858c

Please sign in to comment.