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

chore: Refactor OTel resources #1659

Merged
merged 28 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
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: 83
skhalash marked this conversation as resolved.
Show resolved Hide resolved
path: ^internal/resources/otelcollector$
- threshold: 78
path: ^internal/resources/selfmonitor$
Expand Down
54 changes: 2 additions & 52 deletions controllers/telemetry/logpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (
)

const (
// FluentBit
fbBaseName = "telemetry-fluent-bit"
fbSectionsConfigMapName = fbBaseName + "-sections"
fbFilesConfigMapName = fbBaseName + "-files"
Expand All @@ -61,9 +60,6 @@ const (
fbEnvConfigSecretName = fbBaseName + "-env"
fbTLSFileConfigSecretName = fbBaseName + "-output-tls-config"
fbDaemonSetName = fbBaseName

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

var (
Expand All @@ -72,17 +68,6 @@ var (
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
Expand All @@ -99,7 +84,6 @@ type LogPipelineControllerConfig struct {
OTelCollectorImage string
FluentBitPriorityClassName string
LogGatewayPriorityClassName string
LogGatewayServiceName string
RestConfig *rest.Config
SelfMonitorName string
TelemetryNamespace string
Expand Down Expand Up @@ -216,48 +200,14 @@ func configureFluentBitReconciler(client client.Client, config LogPipelineContro

//nolint:unparam // error is always nil: An error could be returned after implementing the IstioStatusChecker (TODO)
func configureOtelReconciler(client client.Client, config LogPipelineControllerConfig, _ *prober.LogPipelineProber) (*logpipelineotel.Reconciler, error) {
otelConfig := logpipelineotel.Config{
LogGatewayName: otelLogGatewayName,
TelemetryNamespace: config.TelemetryNamespace,
}

gatewayConfig := otelcollector.GatewayConfig{
Config: otelcollector.Config{
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,
},
OTLPServiceName: config.LogGatewayServiceName,
}

pipelineValidator := &logpipelineotel.Validator{
// TODO: Add validators
}

rbac := otelcollector.MakeLogGatewayRBAC(
types.NamespacedName{
Name: otelLogGatewayName,
Namespace: config.TelemetryNamespace,
})

otelReconciler := logpipelineotel.New(
client,
otelConfig,
&otelcollector.GatewayApplierDeleter{
Config: gatewayConfig,
RBAC: rbac,
},
config.TelemetryNamespace,
otelcollector.NewLogGatewayApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.LogGatewayPriorityClassName),
&gateway.Builder{Reader: client},
&workloadstatus.DeploymentProber{Client: client},
pipelineValidator,
Expand Down
112 changes: 14 additions & 98 deletions controllers/telemetry/metricpipeline_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 @@ -56,25 +55,7 @@ import (
)

const (
maxMetricPipelines = 3
metricGatewayBaseName = "telemetry-metric-gateway"
metricAgentBaseName = "telemetry-metric-agent"
)

var (
metricAgentCPULimit = resource.MustParse("1")
metricAgentMemoryLimit = resource.MustParse("1200Mi")
metricAgentCPURequest = resource.MustParse("15m")
metricAgentMemoryRequest = resource.MustParse("50Mi")

metricGatewayBaseCPULimit = resource.MustParse("900m")
metricGatewayDynamicCPULimit = resource.MustParse("100m")
metricGatewayBaseMemoryLimit = resource.MustParse("512Mi")
metricGatewayDynamicMemoryLimit = resource.MustParse("512Mi")
metricGatewayBaseCPURequest = resource.MustParse("25m")
metricGatewayDynamicCPURequest = resource.MustParse("0")
metricGatewayBaseMemoryRequest = resource.MustParse("32Mi")
metricGatewayDynamicMemoryRequest = resource.MustParse("0")
maxMetricPipelines = 3
)

// MetricPipelineController reconciles a MetricPipeline object
Expand All @@ -88,7 +69,6 @@ type MetricPipelineController struct {
type MetricPipelineControllerConfig struct {
MetricAgentPriorityClassName string
MetricGatewayPriorityClassName string
MetricGatewayServiceName string
ModuleVersion string
OTelCollectorImage string
RestConfig *rest.Config
Expand Down Expand Up @@ -123,25 +103,24 @@ func NewMetricPipelineController(client client.Client, reconcileTriggerChan <-ch
return nil, err
}

reconcilerConfig := metricpipeline.Config{
AgentName: metricAgentBaseName,
GatewayName: metricGatewayBaseName,
ModuleVersion: config.ModuleVersion,
TelemetryNamespace: config.TelemetryNamespace,
agentConfigBuilder := &agent.Builder{
Config: agent.BuilderConfig{
GatewayOTLPServiceName: types.NamespacedName{Namespace: config.TelemetryNamespace, Name: otelcollector.MetricOTLPServiceName},
},
}

gatewayConfigBuilder := &gateway.Builder{Reader: client}

reconciler := metricpipeline.New(
client,
reconcilerConfig,
newMetricAgentApplierDeleter(config),
&agent.Builder{
Config: agent.BuilderConfig{
GatewayOTLPServiceName: types.NamespacedName{Namespace: config.TelemetryNamespace, Name: config.MetricGatewayServiceName},
},
},
config.TelemetryNamespace,
config.ModuleVersion,
otelcollector.NewMetricAgentApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.MetricAgentPriorityClassName),
agentConfigBuilder,
&workloadstatus.DaemonSetProber{Client: client},
flowHealthProber,
newMetricGatewayApplierDeleter(config),
&gateway.Builder{Reader: client},
otelcollector.NewMetricGatewayApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.MetricGatewayPriorityClassName),
gatewayConfigBuilder,
&workloadstatus.DeploymentProber{Client: client},
istiostatus.NewChecker(discoveryClient),
overrides.New(client, overrides.HandlerConfig{SystemNamespace: config.TelemetryNamespace}),
Expand All @@ -157,69 +136,6 @@ func NewMetricPipelineController(client client.Client, reconcileTriggerChan <-ch
}, nil
}

func newMetricAgentApplierDeleter(config MetricPipelineControllerConfig) *otelcollector.AgentApplierDeleter {
rbac := otelcollector.MakeMetricAgentRBAC(
types.NamespacedName{
Name: metricAgentBaseName,
Namespace: config.TelemetryNamespace,
},
)

agentConfig := otelcollector.AgentConfig{
Config: otelcollector.Config{
BaseName: metricAgentBaseName,
Namespace: config.TelemetryNamespace,
},
DaemonSet: otelcollector.DaemonSetConfig{
Image: config.OTelCollectorImage,
PriorityClassName: config.MetricAgentPriorityClassName,
CPULimit: metricAgentCPULimit,
MemoryLimit: metricAgentMemoryLimit,
CPURequest: metricAgentCPURequest,
MemoryRequest: metricAgentMemoryRequest,
},
}

return &otelcollector.AgentApplierDeleter{
Config: agentConfig,
RBAC: rbac,
}
}

func newMetricGatewayApplierDeleter(config MetricPipelineControllerConfig) *otelcollector.GatewayApplierDeleter {
rbac := otelcollector.MakeMetricGatewayRBAC(
types.NamespacedName{
Name: metricGatewayBaseName,
Namespace: config.TelemetryNamespace,
},
)

gatewayConfig := otelcollector.GatewayConfig{
Config: otelcollector.Config{
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,
},
OTLPServiceName: config.MetricGatewayServiceName,
}

return &otelcollector.GatewayApplierDeleter{
Config: gatewayConfig,
RBAC: rbac,
}
}

func (r *MetricPipelineController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return r.reconciler.Reconcile(ctx, req)
}
Expand Down
57 changes: 3 additions & 54 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 @@ -55,19 +54,7 @@ import (
)

const (
maxTracePipelines = 3
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")
maxTracePipelines = 3
)

// TracePipelineController reconciles a TracePipeline object
Expand All @@ -83,7 +70,6 @@ type TracePipelineControllerConfig struct {
TelemetryNamespace string
OTelCollectorImage string
TraceGatewayPriorityClassName string
TraceGatewayServiceName string
}

func NewTracePipelineController(client client.Client, reconcileTriggerChan <-chan event.GenericEvent, config TracePipelineControllerConfig) (*TracePipelineController, error) {
Expand Down Expand Up @@ -113,15 +99,11 @@ func NewTracePipelineController(client client.Client, reconcileTriggerChan <-cha
return nil, err
}

reconcilerConfig := tracepipeline.Config{
TraceGatewayName: traceGatewayBaseName,
TelemetryNamespace: config.TelemetryNamespace,
}
reconciler := tracepipeline.New(
client,
reconcilerConfig,
config.TelemetryNamespace,
flowHealthProber,
newTraceGatewayApplierDeleter(config),
otelcollector.NewTraceGatewayApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.TraceGatewayPriorityClassName),
&gateway.Builder{Reader: client},
&workloadstatus.DeploymentProber{Client: client},
istiostatus.NewChecker(discoveryClient),
Expand All @@ -137,39 +119,6 @@ func NewTracePipelineController(client client.Client, reconcileTriggerChan <-cha
}, nil
}

func newTraceGatewayApplierDeleter(config TracePipelineControllerConfig) *otelcollector.GatewayApplierDeleter {
rbac := otelcollector.MakeTraceGatewayRBAC(
types.NamespacedName{
Name: traceGatewayBaseName,
Namespace: config.TelemetryNamespace,
})

gatewayConfig := otelcollector.GatewayConfig{
Config: otelcollector.Config{
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,
},
OTLPServiceName: config.TraceGatewayServiceName,
}

return &otelcollector.GatewayApplierDeleter{
Config: gatewayConfig,
RBAC: rbac,
}
}

func (r *TracePipelineController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return r.reconciler.Reconcile(ctx, req)
}
Expand Down
Loading
Loading