Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

[KOGITO-2960] - Prometheus integration with kogito-cloud-operator #521

Merged
merged 13 commits into from Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions cmd/kogito/command/converter/monitoring_converter.go
@@ -0,0 +1,29 @@
// Copyright 2020 Red Hat, Inc. and/or its affiliates
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package converter

import (
"github.com/kiegroup/kogito-cloud-operator/cmd/kogito/command/flag"
"github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1"
)

// FromMonitoringFlagToMonitoring converts given MonitoringFlags into Monitoring
func FromMonitoringFlagToMonitoring(monitoringFlags *flag.MonitoringFlags) v1alpha1.Monitoring {
return v1alpha1.Monitoring{
Scrape: monitoringFlags.Scrape,
Scheme: monitoringFlags.Scheme,
Path: monitoringFlags.Path,
}
}
@@ -1,4 +1,4 @@
// Copyright 2019 Red Hat, Inc. and/or its affiliates
// Copyright 2020 Red Hat, Inc. and/or its affiliates
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,21 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package prometheus
package converter

import (
"github.com/kiegroup/kogito-cloud-operator/pkg/client"
"github.com/kiegroup/kogito-cloud-operator/pkg/logger"
"github.com/kiegroup/kogito-cloud-operator/cmd/kogito/command/flag"
"github.com/stretchr/testify/assert"
"testing"
)

var log = logger.GetLogger("prometheus_client")
func Test_FromMonitoringFlagToMonitoring(t *testing.T) {
monitoringFlags := &flag.MonitoringFlags{
Scrape: true,
Scheme: "http",
Path: "/metrix",
}

// ServiceMonitor will call ServiceMonitor custom resource API
func ServiceMonitor() ServiceMonitorInterface {
return newServiceMonitor(&client.Client{})
}

// ServiceMonitorC will call ServiceMonitor custom resource API with the given client
func ServiceMonitorC(c *client.Client) ServiceMonitorInterface {
return newServiceMonitor(c)
monitoring := FromMonitoringFlagToMonitoring(monitoringFlags)
assert.True(t, monitoring.Scrape)
assert.Equal(t, "http", monitoring.Scheme)
assert.Equal(t, "/metrix", monitoring.Path)
}
39 changes: 39 additions & 0 deletions cmd/kogito/command/flag/monitoring_flag.go
@@ -0,0 +1,39 @@
// Copyright 2020 Red Hat, Inc. and/or its affiliates
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flag

import (
"github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1"
"github.com/spf13/cobra"
)

// MonitoringFlags is common properties used to configure Monitoring service
type MonitoringFlags struct {
Scrape bool
Scheme string
Path string
}

// AddMonitoringFlags adds the monitoring flags to the given command
func AddMonitoringFlags(command *cobra.Command, flags *MonitoringFlags) {
command.Flags().BoolVar(&flags.Scrape, "scrape", false, "Flag to allow Kogito operator to expose Kogito service for scraping")
command.Flags().StringVar(&flags.Scheme, "monitoring-scheme", v1alpha1.MonitoringDefaultScheme, "HTTP scheme to use for scraping.")
command.Flags().StringVar(&flags.Path, "monitoring-path", v1alpha1.MonitoringDefaultPath, "HTTP path to scrape for metrics")
}

// CheckMonitoringArgs validates the MonitoringFlags flags
func CheckMonitoringArgs(flags *MonitoringFlags) error {
return nil
}
5 changes: 5 additions & 0 deletions cmd/kogito/command/flag/runtime_flag.go
Expand Up @@ -26,6 +26,7 @@ type RuntimeFlags struct {
InfinispanFlags
KafkaFlags
RuntimeTypeFlags
MonitoringFlags
Name string
EnableIstio bool
EnablePersistence bool
Expand All @@ -38,6 +39,7 @@ func AddRuntimeFlags(command *cobra.Command, flags *RuntimeFlags) {
AddInstallFlags(command, &flags.InstallFlags)
AddInfinispanFlags(command, &flags.InfinispanFlags)
AddKafkaFlags(command, &flags.KafkaFlags)
AddMonitoringFlags(command, &flags.MonitoringFlags)
command.Flags().BoolVar(&flags.EnableIstio, "enable-istio", false, "Enable Istio integration by annotating the Kogito service pods with the right value for Istio controller to inject sidecars on it. Defaults to false")
command.Flags().BoolVar(&flags.EnablePersistence, "enable-persistence", false, "If set to true, deployed Kogito service will support integration with Infinispan server for persistence. Default to false")
command.Flags().BoolVar(&flags.EnableEvents, "enable-events", false, "If set to true, deployed Kogito service will support integration with Kafka cluster for events. Default to false")
Expand All @@ -55,6 +57,9 @@ func CheckRuntimeArgs(flags *RuntimeFlags) error {
if err := CheckKafkaArgs(&flags.KafkaFlags); err != nil {
return err
}
if err := CheckMonitoringArgs(&flags.MonitoringFlags); err != nil {
return err
}
if err := util.CheckKeyPair(flags.ServiceLabels); err != nil {
return fmt.Errorf("service labels are in the wrong format. Valid are key pairs like 'service=myservice', received %s", flags.ServiceLabels)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/kogito/command/service/runtime_service.go
Expand Up @@ -65,6 +65,7 @@ func (i runtimeService) InstallRuntimeService(cli *client.Client, flags *flag.Ru
Spec: v1alpha1.KogitoRuntimeSpec{
EnableIstio: flags.EnableIstio,
Runtime: converter.FromRuntimeFlagsToRuntimeType(&flags.RuntimeTypeFlags),
Monitoring: converter.FromMonitoringFlagToMonitoring(&flags.MonitoringFlags),
KogitoServiceSpec: v1alpha1.KogitoServiceSpec{
Replicas: &flags.Replicas,
Envs: converter.FromStringArrayToEnvs(flags.Env, flags.SecretEnv),
Expand Down
14 changes: 14 additions & 0 deletions deploy/crds/app.kiegroup.org_kogitoruntimes_crd.yaml
Expand Up @@ -258,6 +258,20 @@ spec:
infrastructure.
type: boolean
type: object
monitoring:
description: Create Service monitor instance to connect with Monitoring
service
properties:
path:
description: HTTP path to scrape for metrics.
type: string
scheme:
description: HTTP scheme to use for scraping.
type: string
scrape:
description: Flag to allow Monitoring to scraping Kogito service.
type: boolean
type: object
replicas:
description: 'Number of replicas that the service will have deployed
in the cluster. Default value: 1.'
Expand Down
Expand Up @@ -258,6 +258,20 @@ spec:
infrastructure.
type: boolean
type: object
monitoring:
description: Create Service monitor instance to connect with Monitoring
service
properties:
path:
description: HTTP path to scrape for metrics.
type: string
scheme:
description: HTTP scheme to use for scraping.
type: string
scrape:
description: Flag to allow Monitoring to scraping Kogito service.
type: boolean
type: object
replicas:
description: 'Number of replicas that the service will have deployed
in the cluster. Default value: 1.'
Expand Down
Expand Up @@ -545,6 +545,11 @@ spec:
image.'
displayName: Image
path: image
- description: Create Service monitor instance to connect with Monitoring service
displayName: Monitoring
path: monitoring
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:label
- description: 'Number of replicas that the service will have deployed in the
cluster. Default value: 1.'
displayName: Replicas
Expand Down
Expand Up @@ -258,6 +258,20 @@ spec:
infrastructure.
type: boolean
type: object
monitoring:
description: Create Service monitor instance to connect with Monitoring
service
properties:
path:
description: HTTP path to scrape for metrics.
type: string
scheme:
description: HTTP scheme to use for scraping.
type: string
scrape:
description: Flag to allow Monitoring to scraping Kogito service.
type: boolean
type: object
replicas:
description: 'Number of replicas that the service will have deployed
in the cluster. Default value: 1.'
Expand Down
Expand Up @@ -545,6 +545,11 @@ spec:
image.'
displayName: Image
path: image
- description: Create Service monitor instance to connect with Monitoring service
displayName: Monitoring
path: monitoring
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:label
- description: 'Number of replicas that the service will have deployed in the
cluster. Default value: 1.'
displayName: Replicas
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/app/v1alpha1/kogitoruntime_types.go
Expand Up @@ -37,6 +37,12 @@ type KogitoRuntimeSpec struct {
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:label"
// +kubebuilder:validation:Enum=quarkus;springboot
Runtime RuntimeType `json:"runtime,omitempty"`

// Create Service monitor instance to connect with Monitoring service
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Monitoring"
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:label"
Monitoring Monitoring `json:"monitoring,omitempty"`
}

// KogitoRuntimeStatus defines the observed state of KogitoRuntime.
Expand Down
38 changes: 38 additions & 0 deletions pkg/apis/app/v1alpha1/monitoring.go
@@ -0,0 +1,38 @@
// Copyright 2020 Red Hat, Inc. and/or its affiliates
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

const (

// MonitoringDefaultPath default path
MonitoringDefaultPath = "/metrics"

// MonitoringDefaultScheme default scheme
MonitoringDefaultScheme = "http"
)

// Monitoring properties to connect with Monitoring service
type Monitoring struct {
// Flag to allow Monitoring to scraping Kogito service.
Scrape bool `json:"scrape,omitempty"`

// HTTP scheme to use for scraping.
// +optional
Scheme string `json:"scheme,omitempty"`

// HTTP path to scrape for metrics.
// +optional
Path string `json:"path,omitempty"`
}
17 changes: 17 additions & 0 deletions pkg/apis/app/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions pkg/client/client.go
Expand Up @@ -75,8 +75,8 @@ func NewForConsole() *Client {

// NewForController creates a new client based on the rest config and the controller client created by Operator SDK
// Panic if something goes wrong
func NewForController(config *restclient.Config, client controllercli.Client) *Client {
newClient, err := NewClientBuilder().WithAllClients().UseConfig(config).UseControllerClient(client).Build()
func NewForController(config *restclient.Config) *Client {
newClient, err := NewClientBuilder().WithAllClients().UseConfig(config).Build()
if err != nil {
panic(err)
}
Expand Down