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 9 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
28 changes: 28 additions & 0 deletions cmd/kogito/command/converter/prometheus_converter.go
@@ -0,0 +1,28 @@
// 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"
)

// FromPrometheusFlagToPrometheus converts given PrometheusFlags into Prometheus
func FromPrometheusFlagToPrometheus(prometheusFlags *flag.PrometheusFlags) v1alpha1.Prometheus {
return v1alpha1.Prometheus{
Scheme: prometheusFlags.Scheme,
Path: prometheusFlags.Path,
}
}
32 changes: 32 additions & 0 deletions cmd/kogito/command/converter/prometheus_converter_test.go
@@ -0,0 +1,32 @@
// 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/stretchr/testify/assert"
"testing"
)

func Test_FromPrometheusFlagToPrometheus(t *testing.T) {
prometheusFlags := &flag.PrometheusFlags{
Scheme: "http",
Path: "/metrix",
}

prometheus := FromPrometheusFlagToPrometheus(prometheusFlags)
assert.Equal(t, "http", prometheus.Scheme)
assert.Equal(t, "/metrix", prometheus.Path)
}
37 changes: 37 additions & 0 deletions cmd/kogito/command/flag/prometheus_flag.go
@@ -0,0 +1,37 @@
// 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"
)

// PrometheusFlags is common properties used to configure Prometheus
type PrometheusFlags struct {
Scheme string
Path string
}

// AddPrometheusFlags adds the prometheus flags to the given command
func AddPrometheusFlags(command *cobra.Command, flags *PrometheusFlags) {
command.Flags().StringVar(&flags.Scheme, "prome-scheme", v1alpha1.PrometheusDefaultScheme, "HTTP scheme to use for scraping.")
vaibhavjainwiz marked this conversation as resolved.
Show resolved Hide resolved
command.Flags().StringVar(&flags.Path, "prome-path", v1alpha1.PrometheusDefaultPath, "HTTP path to scrape for metrics")
}

// CheckPrometheusArgs validates the PrometheusFlags flags
func CheckPrometheusArgs(flags *PrometheusFlags) 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
PrometheusFlags
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)
AddPrometheusFlags(command, &flags.PrometheusFlags)
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 := CheckPrometheusArgs(&flags.PrometheusFlags); 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),
Prometheus: converter.FromPrometheusFlagToPrometheus(&flags.PrometheusFlags),
KogitoServiceSpec: v1alpha1.KogitoServiceSpec{
Replicas: &flags.Replicas,
Envs: converter.FromStringArrayToEnvs(flags.Env, flags.SecretEnv),
Expand Down
10 changes: 10 additions & 0 deletions deploy/crds/app.kiegroup.org_kogitoruntimes_crd.yaml
Expand Up @@ -258,6 +258,16 @@ spec:
infrastructure.
type: boolean
type: object
prometheus:
description: Create Service monitor instance to connect with Prometheus
properties:
path:
description: HTTP path to scrape for metrics.
type: string
scheme:
description: HTTP scheme to use for scraping.
type: string
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,16 @@ spec:
infrastructure.
type: boolean
type: object
prometheus:
description: Create Service monitor instance to connect with Prometheus
properties:
path:
description: HTTP path to scrape for metrics.
type: string
scheme:
description: HTTP scheme to use for scraping.
type: string
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 Prometheus
displayName: Prometheus
path: prometheus
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,16 @@ spec:
infrastructure.
type: boolean
type: object
prometheus:
description: Create Service monitor instance to connect with Prometheus
properties:
path:
description: HTTP path to scrape for metrics.
type: string
scheme:
description: HTTP scheme to use for scraping.
type: string
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 Prometheus
displayName: Prometheus
path: prometheus
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 Prometheus
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Prometheus"
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:label"
Prometheus Prometheus `json:"prometheus,omitempty"`
}

// KogitoRuntimeStatus defines the observed state of KogitoRuntime.
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/app/v1alpha1/prometheus.go
@@ -0,0 +1,35 @@
// 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 (

// PrometheusDefaultPath default path
PrometheusDefaultPath = "/metrics"

// PrometheusDefaultScheme default scheme
PrometheusDefaultScheme = "http"
)

// Prometheus properties to connect with prometheus
type Prometheus struct {
// 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