Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 215631d

Browse files
[issue-464] Create a Prometheus ServiceMonitor object that can capture/collect metrics from deployed SonataFlow instances
1 parent 5eddf46 commit 215631d

39 files changed

+824
-67
lines changed

.github/workflows/e2e.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ env:
1717
PYTHON_VERSION: "3.10"
1818
KIND_VERSION: v0.20.0
1919
KNATIVE_VERSION: v1.12.5
20+
PROMETHEUS_VERSION: v0.70.0
2021
OPERATOR_IMAGE_NAME: "127.0.0.1:5001/kogito-serverless-operator:0.0.1"
2122

2223
jobs:
@@ -68,6 +69,9 @@ jobs:
6869
- name: Deploy Knative Eventing and Serving
6970
run: make KNATIVE_VERSION=${{ env.KNATIVE_VERSION }} deploy-knative
7071

72+
- name: Deploy Prometheus
73+
run: make PROMETHEUS_VERSION=${{ env.PROMETHEUS_VERSION }} deploy-prometheus
74+
7175
- name: Set OPERATOR_IMAGE_NAME to Point to Kind's Local Registry
7276
run: echo "OPERATOR_IMAGE_NAME=${{ env.OPERATOR_IMAGE_NAME }}" >> $GITHUB_ENV
7377

@@ -92,6 +96,9 @@ jobs:
9296
- name: Run E2E Tests for Persistent Flows
9397
run: make test-e2e label=flows-persistence
9498

99+
- name: Run E2E Tests for Workflow Monitoring
100+
run: make test-e2e label=flows-monitoring
101+
95102
- name: Run E2E Tests for Platform
96103
run: make test-e2e label=platform
97104

Makefile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ test: manifests generate envtest test-api ## Run tests.
123123
@$(MAKE) vet
124124
@$(MAKE) fmt
125125
@echo "🔍 Running controller tests..."
126-
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
127-
go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out > /dev/null 2>&1
126+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
128127
@echo "✅ Tests completed successfully. Coverage report generated: cover.out."
129128

130129
.PHONY: test-api
@@ -264,6 +263,8 @@ GOLANGCI_LINT_VERSION ?= v1.57.2
264263
KIND_VERSION ?= v0.20.0
265264
KNATIVE_VERSION ?= v1.13.2
266265
TIMEOUT_SECS ?= 180s
266+
PROMETHEUS_VERSION ?= v0.70.0
267+
GRAFANA_VERSION ?= v5.13.0
267268

268269
KNATIVE_SERVING_PREFIX ?= "https://github.com/knative/serving/releases/download/knative-$(KNATIVE_VERSION)"
269270
KNATIVE_EVENTING_PREFIX ?= "https://github.com/knative/eventing/releases/download/knative-$(KNATIVE_VERSION)"
@@ -402,7 +403,7 @@ generate-all: generate generate-deploy bundle
402403
@$(MAKE) fmt
403404

404405
.PHONY: test-e2e # You will need to have a Minikube/Kind cluster up and running to run this target, and run container-builder before the test
405-
label = "flows-ephemeral" # possible values are flows-ephemeral, flows-persistence, platform, cluster
406+
label = "flows-ephemeral" # possible values are flows-ephemeral, flows-persistence, flows-monitoring, platform, cluster
406407
test-e2e:
407408
ifeq ($(label), cluster)
408409
@echo "🌐 Running e2e tests for cluster..."
@@ -424,8 +425,13 @@ else ifeq ($(label), flows-persistence)
424425
go test ./test/e2e/e2e_suite_test.go ./test/e2e/helpers.go ./test/e2e/workflow_test.go \
425426
-v -ginkgo.v -ginkgo.no-color -ginkgo.github-output -ginkgo.label-filter=$(label) \
426427
-ginkgo.junit-report=./e2e-test-report-workflow_test.xml -timeout 60m KUSTOMIZE=$(KUSTOMIZE);
428+
else ifeq ($(label), flows-monitoring)
429+
@echo "🔁 Running e2e tests for flows-monitoring..."
430+
go test ./test/e2e/e2e_suite_test.go ./test/e2e/helpers.go ./test/e2e/workflow_test.go \
431+
-v -ginkgo.v -ginkgo.no-color -ginkgo.github-output -ginkgo.label-filter=$(label) \
432+
-ginkgo.junit-report=./e2e-test-report-workflow_test.xml -timeout 60m KUSTOMIZE=$(KUSTOMIZE);
427433
else
428-
@echo "❌ Invalid label. Please use one of: cluster, platform, flows-ephemeral, flows-persistence"
434+
@echo "❌ Invalid label. Please use one of: cluster, platform, flows-ephemeral, flows-persistence, flows-monitoring"
429435
endif
430436

431437

@@ -450,6 +456,18 @@ deploy-knative:
450456
kubectl wait --for=condition=Ready=True KnativeServing/knative-serving -n knative-serving --timeout=$(TIMEOUT_SECS)
451457
kubectl wait --for=condition=Ready=True KnativeEventing/knative-eventing -n knative-eventing --timeout=$(TIMEOUT_SECS)
452458

459+
.PHONY: deploy-prometheus
460+
deploy-prometheus: create-cluster
461+
kubectl create -f https://github.com/prometheus-operator/prometheus-operator/releases/download/$(PROMETHEUS_VERSION)/bundle.yaml
462+
kubectl wait --for=condition=Available=True deploy/prometheus-operator -n default --timeout=$(TIMEOUT_SECS)
463+
kubectl apply -f ./test/testdata/prometheus.yaml -n default
464+
kubectl wait --for=condition=Available=True prometheus/prometheus -n default --timeout=$(TIMEOUT_SECS)
465+
466+
.PHONY: deploy-grafana
467+
deploy-grafana: create-cluster
468+
kubectl create -f https://github.com/grafana/grafana-operator/releases/download/$(GRAFANA_VERSION)/kustomize-cluster_scoped.yaml
469+
kubectl wait --for=condition=Available=True deploy/grafana-operator-controller-manager -n grafana --timeout=$(TIMEOUT_SECS)
470+
453471
.PHONY: delete-cluster
454472
delete-cluster: install-kind
455473
kind delete cluster && $(BUILDER) rm -f kind-registry

api/v1alpha08/sonataflowplatform_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ type SonataFlowPlatformSpec struct {
6363
// These properties MAY NOT be propagated to a SonataFlowClusterPlatform since PropertyVarSource can only refer local context sources.
6464
// +optional
6565
Properties *PropertyPlatformSpec `json:"properties,omitempty"`
66+
// Settings for Prometheus monitoring
67+
// +optional
68+
Monitoring *PlatformMonitoringOptionsSpec `json:"monitoring,omitempty"`
6669
}
6770

6871
// PlatformEventingSpec specifies the Knative Eventing integration details in the platform.
@@ -74,6 +77,15 @@ type PlatformEventingSpec struct {
7477
Broker *duckv1.Destination `json:"broker,omitempty"`
7578
}
7679

80+
// PlatformMonitoringOptionsSpec specifies the settings for monitoring
81+
// +k8s:openapi-gen=true
82+
type PlatformMonitoringOptionsSpec struct {
83+
// Enabled indicates whether monitoring with Prometheus metrics is enabled
84+
// +optional
85+
// +default: false
86+
Enabled bool `json:"enabled,omitempty"`
87+
}
88+
7789
// PlatformCluster is the kind of orchestration cluster the platform is installed into
7890
// +kubebuilder:validation:Enum=kubernetes;openshift
7991
type PlatformCluster string

api/v1alpha08/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/sonataflow.org_sonataflowplatforms.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,14 @@ spec:
524524
type: string
525525
type: object
526526
type: object
527+
monitoring:
528+
description: Settings for Prometheus monitoring
529+
properties:
530+
enabled:
531+
description: Enabled indicates whether monitoring with Prometheus
532+
metrics is enabled
533+
type: boolean
534+
type: object
527535
persistence:
528536
description: |-
529537
Persistence defines the platform persistence configuration. When this field is set,

cmd/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import (
2727
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller"
2828
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/cfg"
2929
"github.com/apache/incubator-kie-kogito-serverless-operator/version"
30+
prometheus "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
31+
"k8s.io/klog/v2/klogr"
3032
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
3133
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
3234
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
3335
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3436
"sigs.k8s.io/controller-runtime/pkg/webhook"
3537

36-
"k8s.io/klog/v2/klogr"
37-
3838
"k8s.io/klog/v2"
3939

4040
"github.com/apache/incubator-kie-kogito-serverless-operator/utils"
@@ -66,6 +66,7 @@ func init() {
6666
utilruntime.Must(sourcesv1.AddToScheme(scheme))
6767
utilruntime.Must(eventingv1.AddToScheme(scheme))
6868
utilruntime.Must(servingv1.AddToScheme(scheme))
69+
utilruntime.Must(prometheus.AddToScheme(scheme))
6970
//+kubebuilder:scaffold:scheme
7071
}
7172

config/crd/bases/sonataflow.org_sonataflowplatforms.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,14 @@ spec:
524524
type: string
525525
type: object
526526
type: object
527+
monitoring:
528+
description: Settings for Prometheus monitoring
529+
properties:
530+
enabled:
531+
description: Enabled indicates whether monitoring with Prometheus
532+
metrics is enabled
533+
type: boolean
534+
type: object
527535
persistence:
528536
description: |-
529537
Persistence defines the platform persistence configuration. When this field is set,

config/rbac/role.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ kind: ClusterRole
2121
metadata:
2222
name: manager-role
2323
rules:
24+
- apiGroups:
25+
- monitoring.coreos.com
26+
resources:
27+
- servicemonitors
28+
verbs:
29+
- create
30+
- delete
31+
- get
32+
- list
33+
- update
34+
- watch
2435
- apiGroups:
2536
- sonataflow.org
2637
resources:

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,7 @@ github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-2023020916533
22472247
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
22482248
github.com/google/go-github/v27 v27.0.6 h1:oiOZuBmGHvrGM1X9uNUAUlLgp5r1UUO/M/KnbHnLRlQ=
22492249
github.com/google/go-github/v27 v27.0.6/go.mod h1:/0Gr8pJ55COkmv+S/yPKCczSkUPIM/LnFyubufRNIS0=
2250+
github.com/google/go-jsonnet v0.18.0/go.mod h1:C3fTzyVJDslXdiTqw/bTFk7vSGyCtH3MGRbDfvEwGd0=
22502251
github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9 h1:OF1IPgv+F4NmqmJ98KTjdN97Vs1JxDPB3vbmYzV2dpk=
22512252
github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY=
22522253
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
@@ -2588,6 +2589,7 @@ github.com/openzipkin/zipkin-go v0.3.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0
25882589
github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
25892590
github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
25902591
github.com/operator-framework/api v0.1.1 h1:DbfxRJUPMQlQW6nbfoNzWLxv1rIv13Gt8GbsF2aglFk=
2592+
github.com/operator-framework/operator-lib v0.11.0/go.mod h1:RpyKhFAoG6DmKTDIwMuO6pI3LRc8IE9rxEYWy476o6g=
25912593
github.com/operator-framework/operator-registry v1.6.1 h1:Ow0Ko9DRIZ4xvH55vFAslcTy6A9FhlIeXvm+FhyRd84=
25922594
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
25932595
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=

internal/controller/knative/knative.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
corev1 "k8s.io/api/core/v1"
3131
"k8s.io/apimachinery/pkg/api/errors"
3232
"k8s.io/apimachinery/pkg/types"
33-
"k8s.io/client-go/discovery"
3433
"k8s.io/client-go/rest"
3534
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
3635
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
@@ -44,7 +43,6 @@ import (
4443

4544
var servingClient clientservingv1.ServingV1Interface
4645
var eventingClient clienteventingv1.EventingV1Interface
47-
var discoveryClient discovery.DiscoveryInterface
4846

4947
type Availability struct {
5048
Eventing bool
@@ -92,23 +90,8 @@ func NewKnativeEventingClient(cfg *rest.Config) (*clienteventingv1.EventingV1Cli
9290
return clienteventingv1.NewForConfig(cfg)
9391
}
9492

95-
func getDiscoveryClient(cfg *rest.Config) (discovery.DiscoveryInterface, error) {
96-
if discoveryClient == nil {
97-
if cli, err := discovery.NewDiscoveryClientForConfig(cfg); err != nil {
98-
return nil, err
99-
} else {
100-
discoveryClient = cli
101-
}
102-
}
103-
return discoveryClient, nil
104-
}
105-
106-
func SetDiscoveryClient(cli discovery.DiscoveryInterface) {
107-
discoveryClient = cli
108-
}
109-
11093
func GetKnativeAvailability(cfg *rest.Config) (*Availability, error) {
111-
if cli, err := getDiscoveryClient(cfg); err != nil {
94+
if cli, err := utils.GetDiscoveryClient(cfg); err != nil {
11295
return nil, err
11396
} else {
11497
apiList, err := cli.ServerGroups()

0 commit comments

Comments
 (0)