Skip to content

Commit

Permalink
chore: Optimize reconciliation triggered by the self-monitor webhook (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Khalash authored Apr 4, 2024
1 parent e6dfed3 commit 05d90fd
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 170 deletions.
11 changes: 1 addition & 10 deletions controllers/telemetry/metricpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *MetricPipelineController) SetupWithManager(mgr ctrl.Manager) error {

b.WatchesRawSource(
&source.Channel{Source: r.reconcileTriggerChan},
handler.EnqueueRequestsFromMapFunc(r.mapReconcileTriggerEvent),
&handler.EnqueueRequestForObject{},
)

ownedResourceTypesToWatch := []client.Object{
Expand Down Expand Up @@ -131,15 +131,6 @@ func (r *MetricPipelineController) mapTelemetryChanges(ctx context.Context, obje
return requests
}

func (r *MetricPipelineController) mapReconcileTriggerEvent(ctx context.Context, _ client.Object) []reconcile.Request {
logf.FromContext(ctx).V(1).Info("Reconcile trigger event received")
requests, err := r.createRequestsForAllPipelines(ctx)
if err != nil {
logf.FromContext(ctx).Error(err, "Unable to create reconcile requests")
}
return requests
}

func (r *MetricPipelineController) createRequestsForAllPipelines(ctx context.Context) ([]reconcile.Request, error) {
var pipelines telemetryv1alpha1.MetricPipelineList
var requests []reconcile.Request
Expand Down
11 changes: 1 addition & 10 deletions controllers/telemetry/tracepipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *TracePipelineController) SetupWithManager(mgr ctrl.Manager) error {

b.WatchesRawSource(
&source.Channel{Source: r.reconcileTriggerChan},
handler.EnqueueRequestsFromMapFunc(r.mapReconcileTriggerEvent),
&handler.EnqueueRequestForObject{},
)

ownedResourceTypesToWatch := []client.Object{
Expand Down Expand Up @@ -110,15 +110,6 @@ func (r *TracePipelineController) mapTelemetryChanges(ctx context.Context, objec
return requests
}

func (r *TracePipelineController) mapReconcileTriggerEvent(ctx context.Context, _ client.Object) []reconcile.Request {
logf.FromContext(ctx).V(1).Info("Reconcile trigger event received")
requests, err := r.createRequestsForAllPipelines(ctx)
if err != nil {
logf.FromContext(ctx).Error(err, "Unable to create reconcile requests")
}
return requests
}

func (r *TracePipelineController) createRequestsForAllPipelines(ctx context.Context) ([]reconcile.Request, error) {
var pipelines telemetryv1alpha1.TracePipelineList
var requests []reconcile.Request
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/reconciler/metricpipeline/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/kyma-project/telemetry-manager/internal/overrides"
"github.com/kyma-project/telemetry-manager/internal/resources/otelcollector"
"github.com/kyma-project/telemetry-manager/internal/secretref"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/prober"
)

const defaultReplicaCount int32 = 2
Expand All @@ -44,7 +44,7 @@ type DaemonSetProber interface {

//go:generate mockery --name FlowHealthProber --filename flow_health_prober.go
type FlowHealthProber interface {
Probe(ctx context.Context, pipelineName string) (flowhealth.ProbeResult, error)
Probe(ctx context.Context, pipelineName string) (prober.ProbeResult, error)
}

type Reconciler struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/reconciler/metricpipeline/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1"
"github.com/kyma-project/telemetry-manager/internal/conditions"
"github.com/kyma-project/telemetry-manager/internal/secretref"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/prober"
)

func (r *Reconciler) updateStatus(ctx context.Context, pipelineName string, withinPipelineCountLimit bool) error {
Expand Down Expand Up @@ -159,7 +159,7 @@ func (r *Reconciler) setFlowHealthCondition(ctx context.Context, pipeline *telem
meta.SetStatusCondition(&pipeline.Status.Conditions, condition)
}

func flowHealthReasonFor(probeResult flowhealth.ProbeResult) string {
func flowHealthReasonFor(probeResult prober.ProbeResult) string {
if probeResult.AllDataDropped {
return conditions.ReasonAllDataDropped
}
Expand Down
20 changes: 10 additions & 10 deletions internal/reconciler/metricpipeline/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/kyma-project/telemetry-manager/internal/conditions"
"github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/mocks"
"github.com/kyma-project/telemetry-manager/internal/resources/otelcollector"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/prober"
"github.com/kyma-project/telemetry-manager/internal/testutils"
)

Expand Down Expand Up @@ -315,7 +315,7 @@ func TestUpdateStatus(t *testing.T) {
t.Run("flow healthy", func(t *testing.T) {
tests := []struct {
name string
probe flowhealth.ProbeResult
probe prober.ProbeResult
probeErr error
expectedStatus metav1.ConditionStatus
expectedReason string
Expand All @@ -328,31 +328,31 @@ func TestUpdateStatus(t *testing.T) {
},
{
name: "healthy",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
Healthy: true,
},
expectedStatus: metav1.ConditionTrue,
expectedReason: conditions.ReasonFlowHealthy,
},
{
name: "throttling",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
Throttling: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonGatewayThrottling,
},
{
name: "buffer filling up",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
QueueAlmostFull: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonBufferFillingUp,
},
{
name: "buffer filling up shadows other problems",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
QueueAlmostFull: true,
Throttling: true,
},
Expand All @@ -361,15 +361,15 @@ func TestUpdateStatus(t *testing.T) {
},
{
name: "some data dropped",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
SomeDataDropped: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonSomeDataDropped,
},
{
name: "some data dropped shadows other problems",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
SomeDataDropped: true,
Throttling: true,
},
Expand All @@ -378,15 +378,15 @@ func TestUpdateStatus(t *testing.T) {
},
{
name: "all data dropped",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
AllDataDropped: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonAllDataDropped,
},
{
name: "all data dropped shadows other problems",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
AllDataDropped: true,
Throttling: true,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/reconciler/telemetry/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/kyma-project/telemetry-manager/internal/k8sutils"
"github.com/kyma-project/telemetry-manager/internal/overrides"
"github.com/kyma-project/telemetry-manager/internal/resources/selfmonitor"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/alertrules"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/config"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/webhookcert"
)

Expand Down Expand Up @@ -158,7 +158,7 @@ func (r *Reconciler) reconcileSelfMonitor(ctx context.Context, telemetry operato
return fmt.Errorf("failed to marshal selfmonitor config: %w", err)
}

rules := flowhealth.MakeRules()
rules := alertrules.MakeRules()
rulesYAML, err := yaml.Marshal(rules)
if err != nil {
return fmt.Errorf("failed to marshal rules: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions internal/reconciler/tracepipeline/mocks/flow_health_prober.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/reconciler/tracepipeline/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/kyma-project/telemetry-manager/internal/overrides"
"github.com/kyma-project/telemetry-manager/internal/resources/otelcollector"
"github.com/kyma-project/telemetry-manager/internal/secretref"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/prober"
)

const defaultReplicaCount int32 = 2
Expand All @@ -53,7 +53,7 @@ type DeploymentProber interface {

//go:generate mockery --name FlowHealthProber --filename flow_health_prober.go
type FlowHealthProber interface {
Probe(ctx context.Context, pipelineName string) (flowhealth.ProbeResult, error)
Probe(ctx context.Context, pipelineName string) (prober.ProbeResult, error)
}

type Reconciler struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/reconciler/tracepipeline/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1"
"github.com/kyma-project/telemetry-manager/internal/conditions"
"github.com/kyma-project/telemetry-manager/internal/secretref"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/prober"
)

func (r *Reconciler) updateStatus(ctx context.Context, pipelineName string, withinPipelineCountLimit bool) error {
Expand Down Expand Up @@ -133,7 +133,7 @@ func (r *Reconciler) setFlowHealthCondition(ctx context.Context, pipeline *telem
meta.SetStatusCondition(&pipeline.Status.Conditions, condition)
}

func flowHealthReasonFor(probeResult flowhealth.ProbeResult) string {
func flowHealthReasonFor(probeResult prober.ProbeResult) string {
if probeResult.AllDataDropped {
return conditions.ReasonAllDataDropped
}
Expand Down
20 changes: 10 additions & 10 deletions internal/reconciler/tracepipeline/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/kyma-project/telemetry-manager/internal/conditions"
"github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline/mocks"
"github.com/kyma-project/telemetry-manager/internal/resources/otelcollector"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/flowhealth"
"github.com/kyma-project/telemetry-manager/internal/selfmonitor/prober"
"github.com/kyma-project/telemetry-manager/internal/testutils"
)

Expand Down Expand Up @@ -349,7 +349,7 @@ func TestUpdateStatus(t *testing.T) {
t.Run("flow healthy", func(t *testing.T) {
tests := []struct {
name string
probe flowhealth.ProbeResult
probe prober.ProbeResult
probeErr error
expectedStatus metav1.ConditionStatus
expectedReason string
Expand All @@ -362,31 +362,31 @@ func TestUpdateStatus(t *testing.T) {
},
{
name: "healthy",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
Healthy: true,
},
expectedStatus: metav1.ConditionTrue,
expectedReason: conditions.ReasonFlowHealthy,
},
{
name: "throttling",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
Throttling: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonGatewayThrottling,
},
{
name: "buffer filling up",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
QueueAlmostFull: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonBufferFillingUp,
},
{
name: "buffer filling up shadows other problems",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
QueueAlmostFull: true,
Throttling: true,
},
Expand All @@ -395,15 +395,15 @@ func TestUpdateStatus(t *testing.T) {
},
{
name: "some data dropped",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
SomeDataDropped: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonSomeDataDropped,
},
{
name: "some data dropped shadows other problems",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
SomeDataDropped: true,
Throttling: true,
},
Expand All @@ -412,15 +412,15 @@ func TestUpdateStatus(t *testing.T) {
},
{
name: "all data dropped",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
AllDataDropped: true,
},
expectedStatus: metav1.ConditionFalse,
expectedReason: conditions.ReasonAllDataDropped,
},
{
name: "all data dropped shadows other problems",
probe: flowhealth.ProbeResult{
probe: prober.ProbeResult{
AllDataDropped: true,
Throttling: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flowhealth
package alertrules

import (
"fmt"
Expand All @@ -16,7 +16,7 @@ type labelSelector func(string) string

func selectService(serviceName string) labelSelector {
return func(metric string) string {
return fmt.Sprintf("%s{%s=\"%s\"}", metric, serviceLabelKey, serviceName)
return fmt.Sprintf("%s{%s=\"%s\"}", metric, LabelService, serviceName)
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/selfmonitor/alertrules/pipeline_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package alertrules

type PipelineType string

const (
MetricPipeline PipelineType = "MetricPipeline"
TracePipeline PipelineType = "TracePipeline"
)
Loading

0 comments on commit 05d90fd

Please sign in to comment.