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

Commit 59f71df

Browse files
[issue-464] Create a Prometheus ServiceMonitor object that can capture/collect metrics from deployed SonataFlow instances
1 parent 0bc6d9d commit 59f71df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1480
-158
lines changed

.github/workflows/e2e.yml

Lines changed: 4 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

Makefile

Lines changed: 15 additions & 2 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)"
@@ -450,6 +451,18 @@ deploy-knative:
450451
kubectl wait --for=condition=Ready=True KnativeServing/knative-serving -n knative-serving --timeout=$(TIMEOUT_SECS)
451452
kubectl wait --for=condition=Ready=True KnativeEventing/knative-eventing -n knative-eventing --timeout=$(TIMEOUT_SECS)
452453

454+
.PHONY: deploy-prometheus
455+
deploy-prometheus: create-cluster
456+
kubectl create -f https://github.com/prometheus-operator/prometheus-operator/releases/download/$(PROMETHEUS_VERSION)/bundle.yaml
457+
kubectl wait --for=condition=Available=True deploy/prometheus-operator -n default --timeout=$(TIMEOUT_SECS)
458+
kubectl apply -f ./test/testdata/prometheus.yaml
459+
kubectl wait --for=condition=Available=True prometheus/prometheus -n default --timeout=$(TIMEOUT_SECS)
460+
461+
.PHONY: deploy-grafana
462+
deploy-grafana: create-cluster
463+
kubectl create -f https://github.com/grafana/grafana-operator/releases/download/$(GRAFANA_VERSION)/kustomize-cluster_scoped.yaml
464+
kubectl wait --for=condition=Available=True deploy/grafana-operator-controller-manager -n grafana --timeout=$(TIMEOUT_SECS)
465+
453466
.PHONY: delete-cluster
454467
delete-cluster: install-kind
455468
kind delete cluster && $(BUILDER) rm -f kind-registry

api/v1alpha08/sonataflowplatform_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ 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+
// +default: false
69+
Monitoring *MonitoringSpec `json:"monitoring,omitempty"`
6670
}
6771

6872
// PlatformEventingSpec specifies the Knative Eventing integration details in the platform.
@@ -74,6 +78,15 @@ type PlatformEventingSpec struct {
7478
Broker *duckv1.Destination `json:"broker,omitempty"`
7579
}
7680

81+
// MonitoringSpec specifies the settings for monitoring
82+
// +k8s:openapi-gen=true
83+
type MonitoringSpec struct {
84+
// Enabled indicates whether monitoring with Prometheus metrics is enabled
85+
// +optional
86+
// +default: false
87+
Enabled bool `json:"enabled,omitempty"`
88+
}
89+
7790
// PlatformCluster is the kind of orchestration cluster the platform is installed into
7891
// +kubebuilder:validation:Enum=kubernetes;openshift
7992
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
@@ -503,6 +503,14 @@ spec:
503503
type: string
504504
type: object
505505
type: object
506+
monitoring:
507+
description: Settings for Prometheus monitoring
508+
properties:
509+
enabled:
510+
description: Enabled indicates whether monitoring with Prometheus
511+
metrics is enabled
512+
type: boolean
513+
type: object
506514
persistence:
507515
description: |-
508516
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
@@ -503,6 +503,14 @@ spec:
503503
type: string
504504
type: object
505505
type: object
506+
monitoring:
507+
description: Settings for Prometheus monitoring
508+
properties:
509+
enabled:
510+
description: Enabled indicates whether monitoring with Prometheus
511+
metrics is enabled
512+
type: boolean
513+
type: object
506514
persistence:
507515
description: |-
508516
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
@@ -4,6 +4,17 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7+
- apiGroups:
8+
- monitoring.coreos.com
9+
resources:
10+
- servicemonitors
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- update
17+
- watch
718
- apiGroups:
819
- sonataflow.org
920
resources:

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,7 @@ github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-2023020916533
21742174
github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20230209165335-3624968304fd/go.mod h1:6pjZpt+0dg+Z0kUEn53qLtD57raiZo/bqWzsuX6dDjo=
21752175
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
21762176
github.com/google/go-github/v27 v27.0.6 h1:oiOZuBmGHvrGM1X9uNUAUlLgp5r1UUO/M/KnbHnLRlQ=
2177+
github.com/google/go-jsonnet v0.18.0/go.mod h1:C3fTzyVJDslXdiTqw/bTFk7vSGyCtH3MGRbDfvEwGd0=
21772178
github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9 h1:OF1IPgv+F4NmqmJ98KTjdN97Vs1JxDPB3vbmYzV2dpk=
21782179
github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY=
21792180
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
@@ -2466,6 +2467,7 @@ github.com/openzipkin/zipkin-go v0.3.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0
24662467
github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
24672468
github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
24682469
github.com/operator-framework/api v0.1.1 h1:DbfxRJUPMQlQW6nbfoNzWLxv1rIv13Gt8GbsF2aglFk=
2470+
github.com/operator-framework/operator-lib v0.11.0/go.mod h1:RpyKhFAoG6DmKTDIwMuO6pI3LRc8IE9rxEYWy476o6g=
24692471
github.com/operator-framework/operator-registry v1.6.1 h1:Ow0Ko9DRIZ4xvH55vFAslcTy6A9FhlIeXvm+FhyRd84=
24702472
github.com/otiai10/copy v1.0.2 h1:DDNipYy6RkIkjMwy+AWzgKiNTyj2RUI9yEMeETEpVyc=
24712473
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 h1:o59bHXu8Ejas8Kq6pjoVJQ9/neN66SM8AKh6wI42BBs=

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)