Skip to content

Commit

Permalink
[issue-464] Create a Prometheus ServiceMonitor object that can captur…
Browse files Browse the repository at this point in the history
…e/collect metrics from deployed SonataFlow instances:address review comments
  • Loading branch information
jianrongzhang89 committed Oct 2, 2024
1 parent 6834103 commit d1438cc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
33 changes: 25 additions & 8 deletions internal/controller/sonataflow_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"

"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/monitoring"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"

Expand Down Expand Up @@ -220,15 +221,11 @@ func buildEnqueueRequestsFromMapFunc(c client.Client, b *operatorapi.SonataFlowB

// SetupWithManager sets up the controller with the Manager.
func (r *SonataFlowReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
builder := ctrl.NewControllerManagedBy(mgr).
For(&operatorapi.SonataFlow{}).
Owns(&appsv1.Deployment{}).
Owns(&corev1.Service{}).
Owns(&corev1.ConfigMap{}).
Owns(&servingv1.Service{}).
Owns(&eventingv1.Trigger{}).
Owns(&sourcesv1.SinkBinding{}).
Owns(&prometheus.ServiceMonitor{}).
Owns(&operatorapi.SonataFlowBuild{}).
Watches(&operatorapi.SonataFlowPlatform{}, handler.EnqueueRequestsFromMapFunc(func(c context.Context, a client.Object) []reconcile.Request {
plat, ok := a.(*operatorapi.SonataFlowPlatform)
Expand All @@ -245,7 +242,27 @@ func (r *SonataFlowReconciler) SetupWithManager(mgr ctrl.Manager) error {
return []reconcile.Request{}
}
return buildEnqueueRequestsFromMapFunc(mgr.GetClient(), build)
})).
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)).
Complete(r)
}))

knativeAvail, err := knative.GetKnativeAvailability(mgr.GetConfig())
if err != nil {
return err
}
if knativeAvail.Serving {
builder = builder.Owns(&servingv1.Service{})
}
if knativeAvail.Eventing {
builder = builder.Owns(&eventingv1.Trigger{}).
Owns(&sourcesv1.SinkBinding{}).
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests))
}
promAvail, err := monitoring.GetPrometheusAvailability(mgr.GetConfig())
if err != nil {
return err
}
if promAvail {
builder = builder.Owns(&prometheus.ServiceMonitor{})
}

return builder.Complete(r)
}
19 changes: 13 additions & 6 deletions internal/controller/sonataflowplatform_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,24 @@ func (r *SonataFlowPlatformReconciler) updateIfActiveClusterPlatformExists(ctx c

// SetupWithManager sets up the controller with the Manager.
func (r *SonataFlowPlatformReconciler) SetupWithManager(mgr ctrlrun.Manager) error {
return ctrlrun.NewControllerManagedBy(mgr).
builder := ctrlrun.NewControllerManagedBy(mgr).
For(&operatorapi.SonataFlowPlatform{}).
Owns(&appsv1.Deployment{}).
Owns(&corev1.Service{}).
Owns(&corev1.ConfigMap{}).
Owns(&eventingv1.Trigger{}).
Owns(&sourcesv1.SinkBinding{}).
Watches(&operatorapi.SonataFlowPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapPlatformToPlatformRequests)).
Watches(&operatorapi.SonataFlowClusterPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapClusterPlatformToPlatformRequests)).
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)).
Complete(r)
Watches(&operatorapi.SonataFlowClusterPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapClusterPlatformToPlatformRequests))

knativeAvail, err := knative.GetKnativeAvailability(mgr.GetConfig())
if err != nil {
return err
}
if knativeAvail.Eventing {
builder = builder.Owns(&eventingv1.Trigger{}).
Owns(&sourcesv1.SinkBinding{}).
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests))
}
return builder.Complete(r)
}

// if active clusterplatform object is changed, reconcile all SonataFlowPlatforms in the cluster.
Expand Down

0 comments on commit d1438cc

Please sign in to comment.