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
  • Loading branch information
jianrongzhang89 committed Sep 23, 2024
1 parent 2b857b1 commit a93423e
Show file tree
Hide file tree
Showing 39 changed files with 301 additions and 182 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ deploy-knative: create-cluster
deploy-monitoring: create-cluster
kubectl create -f https://github.com/prometheus-operator/prometheus-operator/releases/download/$(PROMETHEUS_VERSION)/bundle.yaml
kubectl wait --for=condition=Available=True deploy/prometheus-operator -n default --timeout=$(TIMEOUT_SECS)
kubectl create -f https://github.com/grafana/grafana-operator/releases/$(GRAFANA_VERSION)/download/kustomize-cluster_scoped.yaml
kubectl create -f https://github.com/grafana/grafana-operator/releases/download/$(GRAFANA_VERSION)/kustomize-cluster_scoped.yaml
kubectl wait --for=condition=Available=True deploy/grafana-operator-controller-manager -n grafana --timeout=$(TIMEOUT_SECS)
kubectl apply -f ./test/testdata/monitoring.yaml
kubectl wait --for=condition=Available=True prometheus/prometheus -n default --timeout=$(TIMEOUT_SECS)
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha08/sonataflowplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type SonataFlowPlatformSpec struct {
// These properties MAY NOT be propagated to a SonataFlowClusterPlatform since PropertyVarSource can only refer local context sources.
// +optional
Properties *PropertyPlatformSpec `json:"properties,omitempty"`
// MonitoringEnabled indicates whether prometheus service monitors should be created for metrics scraping
// +optional
// +default: false
MonitoringEnabled bool `json:"monitoringEnabled"`
}

// PlatformEventingSpec specifies the Knative Eventing integration details in the platform.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha08/zz_generated.deepcopy.go

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

2 changes: 0 additions & 2 deletions api/zz_generated.deepcopy.go

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

17 changes: 14 additions & 3 deletions bundle/manifests/sonataflow-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/apache/incubator-kie-kogito-serverless-operator
support: Red Hat
name: sonataflow-operator.v0.0.104
name: sonataflow-operator.v999.0.0-snapshot
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -487,6 +487,17 @@ spec:
- patch
- update
- watch
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- sonataflow.org
resources:
Expand Down Expand Up @@ -777,7 +788,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: quay.io/jianrzha/kogito-serverless-operator:0.0.104
image: docker.io/apache/incubator-kie-sonataflow-operator:latest
livenessProbe:
httpGet:
path: /healthz
Expand Down Expand Up @@ -899,4 +910,4 @@ spec:
minKubeVersion: 1.23.0
provider:
name: Red Hat
version: 0.0.104
version: 999.0.0-snapshot
4 changes: 4 additions & 0 deletions bundle/manifests/sonataflow.org_sonataflowplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ spec:
type: string
type: object
type: object
monitoringEnabled:
description: MonitoringEnabled indicates whether prometheus service
monitors should be created for metrics scraping
type: boolean
persistence:
description: Persistence defines the platform persistence configuration.
When this field is set, the configuration is used as the persistence
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/sonataflow.org_sonataflowplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ spec:
type: string
type: object
type: object
monitoringEnabled:
description: MonitoringEnabled indicates whether prometheus service
monitors should be created for metrics scraping
type: boolean
persistence:
description: Persistence defines the platform persistence configuration.
When this field is set, the configuration is used as the persistence
Expand Down
4 changes: 2 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/jianrzha/kogito-serverless-operator
newTag: 0.0.104
newName: docker.io/apache/incubator-kie-sonataflow-operator
newTag: latest
# Patching the manager deployment file to add an env var with the operator namespace in
patchesJson6902:
- patch: |-
Expand Down
11 changes: 11 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- sonataflow.org
resources:
Expand Down
2 changes: 1 addition & 1 deletion container-builder/api/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion controllers/discovery/knative_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"context"
"fmt"

"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/log"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/knative"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"

Expand Down
2 changes: 1 addition & 1 deletion controllers/platform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/client"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/platform/services"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common/constants"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common/variables"
"github.com/apache/incubator-kie-kogito-serverless-operator/log"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/knative"
kubeutil "github.com/apache/incubator-kie-kogito-serverless-operator/utils/kubernetes"
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
"github.com/imdario/mergo"
Expand Down
2 changes: 1 addition & 1 deletion controllers/platform/services/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"k8s.io/klog/v2"

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common/constants"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/workflowdef"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/knative"

"github.com/magiconair/properties"
)
Expand Down
2 changes: 1 addition & 1 deletion controllers/platform/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"fmt"

"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/cfg"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/kubernetes"
"github.com/imdario/mergo"
"github.com/magiconair/properties"
Expand Down
2 changes: 1 addition & 1 deletion controllers/profiles/common/knative_eventing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"context"

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/log"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/knative"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down
21 changes: 4 additions & 17 deletions controllers/profiles/common/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"context"

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/log"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/monitoring"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -34,7 +34,6 @@ type monitoringObjectManager struct {
func NewMonitoringEventingHandler(support *StateSupport) MonitoringEventingHandler {
return &monitoringObjectManager{
serviceMonitor: NewObjectEnsurer(support.C, ServiceMonitorCreator),
dataSource: NewObjectEnsurer(support.C, DataSourceCreator),
StateSupport: support,
}
}
Expand All @@ -46,12 +45,12 @@ type MonitoringEventingHandler interface {
func (k monitoringObjectManager) Ensure(ctx context.Context, workflow *operatorapi.SonataFlow) ([]client.Object, error) {
var objs []client.Object

MonitoringAvail, err := knative.GetMonitoringAvailability(k.Cfg)
monitoringAvail, err := monitoring.GetPrometheusAvailability(k.Cfg)
if err != nil {
klog.V(log.I).InfoS("Error checking Monitoring Eventing: %v", err)
klog.V(log.I).InfoS("Error checking Prometheus availability: %v", err)
return nil, err
}
if !MonitoringAvail.Prometheus {
if !monitoringAvail {
klog.V(log.I).InfoS("Prometheus is not installed")
} else {
// create serviceMonitor
Expand All @@ -62,17 +61,5 @@ func (k monitoringObjectManager) Ensure(ctx context.Context, workflow *operatora
objs = append(objs, serviceMonitor)
}
}

if !MonitoringAvail.Grafana {
klog.V(log.I).InfoS("Grafana is not installed")
} else {
// create grafana data source
dataSource, _, err := k.dataSource.Ensure(ctx, workflow)
if err != nil {
return objs, err
} else if dataSource != nil {
objs = append(objs, dataSource)
}
}
return objs, nil
}
2 changes: 1 addition & 1 deletion controllers/profiles/common/mutate_visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/discovery"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common/properties"
"github.com/apache/incubator-kie-kogito-serverless-operator/utils/knative"
kubeutil "github.com/apache/incubator-kie-kogito-serverless-operator/utils/kubernetes"
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
"github.com/imdario/mergo"
Expand Down
Loading

0 comments on commit a93423e

Please sign in to comment.