Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Add custom metrics to operator #198

Merged
merged 10 commits into from
Mar 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
# Individual's name <submission email address> (@GITHUB_HANDLE)

Sébastien Allamand <sebastien.allamand@orange.com> (@allamand)
Cyril Scetbon <cscetbon.ext@orange.com> (@scetbon)
Jean Armel Luce <jeanarmel.luce@orange.com> (@jal06)
Cyril Scetbon <cscetbon.ext@orange.com> (@cscetbon)
Jean Armel Luce <jeanarmel.luce@orange.com> (@jal06)
Alexandre Guitton <aguitton.ext@orange.com> (@erdrix)
Franck Dehay <franck.dehay@orange.com> (@fdehay)
43 changes: 12 additions & 31 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"context"
"fmt"
"os"
"runtime"
"strconv"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/Orange-OpenSource/casskop/pkg/apis"
api "github.com/Orange-OpenSource/casskop/pkg/apis/db/v1alpha1"
"github.com/Orange-OpenSource/casskop/pkg/controller"
"github.com/Orange-OpenSource/casskop/pkg/controller/cassandracluster"
"github.com/Orange-OpenSource/casskop/version"
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/leader"
Expand All @@ -37,6 +39,7 @@ import (
sdkVersion "github.com/operator-framework/operator-sdk/version"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
prometheusMetrics "sigs.k8s.io/controller-runtime/pkg/metrics"

"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -101,37 +104,12 @@ func getResyncPeriod() int {
}

func main() {
/*
// Add the zap logger flag set to the CLI. The flag set must
// be added before calling pflag.Parse().
pflag.CommandLine.AddFlagSet(zap.FlagSet())

// avoid glog to write to /tmp
flag.Set("logtostderr", "true")

// Add flags registered by imported packages (e.g. glog and
// controller-runtime)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

pflag.Parse()
*/
// Use a zap logr.Logger implementation. If none of the zap
// flags are configured (or if the zap flag set is not being
// used), this defaults to a production zap logger.
//
// The logger instantiated here can be changed to any logger
// implementing the logr.Logger interface. This logger will
// be propagated through the whole operator, generating
// uniform and structured logs.
//logf.SetLogger(logf.ZapLogger(false))

logType, found := os.LookupEnv("LOG_TYPE")
if found && logType == "json" {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
//logrus.SetOutput(os.Stdout)

logrus.SetLevel(getLogLevel())
// resyncPeriod := getResyncPeriod()

printVersion()

Expand Down Expand Up @@ -171,8 +149,8 @@ func main() {

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{
Namespace: namespace,
//MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Namespace: namespace,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
})
if err != nil {
logrus.Error(err)
Expand All @@ -181,6 +159,8 @@ func main() {

logrus.Info("Registering Components.")

prometheusMetrics.Registry.MustRegister(cassandracluster.ClusterActionMetric, cassandracluster.ClusterPhaseMetric)

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
logrus.Error(err)
Expand All @@ -195,10 +175,11 @@ func main() {

// Create Service object to expose the metrics port.
servicePorts := []v1.ServicePort{
{Name: "metricsPort", TargetPort: intstr.FromInt(int(metricsPort))},
{Name: metrics.OperatorPortName, Port: metricsPort,
TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}},
}
_, err = metrics.CreateMetricsService(ctx, cfg, servicePorts)
if err != nil {

if _, err := metrics.CreateMetricsService(ctx, cfg, servicePorts); err != nil {
logrus.Info(err.Error())
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687 // indirect
github.com/operator-framework/operator-sdk v0.15.0
github.com/pelletier/go-toml v1.3.0 // indirect
github.com/prometheus/client_golang v1.2.1
github.com/r3labs/diff v0.0.0-20190801153147-a71de73c46ad
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.4.2
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.3.0/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
Expand All @@ -944,6 +945,7 @@ github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -1664,6 +1666,7 @@ k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKf
k8s.io/kube-proxy v0.0.0-20191016114407-2e83b6f20229/go.mod h1:2Hxci1uzXO5ipP0h9n2+h18fvNkBTpYlckk5dOPu8zg=
k8s.io/kube-scheduler v0.0.0-20191016114748-65049c67a58b/go.mod h1:BgDUHHC5Wl0xcBUQgo2XEprE5nG5i9tlRR4iNgEFbL0=
k8s.io/kube-state-metrics v1.6.0/go.mod h1:84+q9aGVQPzXYGgtvyhZr/fSI6BdLsbPWXn37RASc9k=
k8s.io/kube-state-metrics v1.7.2 h1:6vdtgXrrRRMSgnyDmgua+qvgCYv954JNfxXAtDkeLVQ=
k8s.io/kube-state-metrics v1.7.2/go.mod h1:U2Y6DRi07sS85rmVPmBFlmv+2peBcL8IWGjM+IjYA/E=
k8s.io/kubectl v0.0.0-20191016120415-2ed914427d51/go.mod h1:gL826ZTIfD4vXTGlmzgTbliCAT9NGiqpCqK2aNYv5MQ=
k8s.io/kubelet v0.0.0-20191016114556-7841ed97f1b2/go.mod h1:SBvrtLbuePbJygVXGGCMtWKH07+qrN2dE1iMnteSG8E=
Expand Down Expand Up @@ -1709,6 +1712,7 @@ sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:w
sigs.k8s.io/structured-merge-diff v0.0.0-20190817042607-6149e4549fca/go.mod h1:IIgPezJWb76P0hotTxzDbWsMYB8APh18qZnxkomBpxA=
sigs.k8s.io/testing_frameworks v0.1.1 h1:cP2l8fkA3O9vekpy5Ks8mmA0NW/F7yBdXf8brkWhVrs=
sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9qL6ht1zEr/U=
sigs.k8s.io/testing_frameworks v0.1.2 h1:vK0+tvjF0BZ/RYFeZ1E6BYBwHJJXhjuZ3TdsEKH+UQM=
sigs.k8s.io/testing_frameworks v0.1.2/go.mod h1:ToQrwSC3s8Xf/lADdZp3Mktcql9CG0UAmdJG9th5i0w=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
Expand Down
2 changes: 1 addition & 1 deletion helm/cassandra-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ spec:
app: {{ template "cassandra-operator.name" . }}
ports:
- name: metrics
port: 9710
port: 8383
protocol: TCP
{{- end }}
3 changes: 2 additions & 1 deletion multi-casskop/pkg/controller/multi-casskop/cmc_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package multicasskop

import (
"context"

"github.com/Orange-OpenSource/casskop/multi-casskop/pkg/controller/multi-casskop/models"

ccv1 "github.com/Orange-OpenSource/casskop/pkg/apis/db/v1alpha1"
Expand All @@ -14,7 +15,7 @@ import (
// ReadyCassandraCluster
// return true if CassandraCluster it Done and Running
func (r *reconciler) ReadyCassandraCluster(cc *ccv1.CassandraCluster) bool {
if cc.Status.Phase != ccv1.ClusterPhaseRunning || cc.Status.LastClusterActionStatus != ccv1.StatusDone {
if cc.Status.Phase != ccv1.ClusterPhaseRunning.Name || cc.Status.LastClusterActionStatus != ccv1.StatusDone {
return false
}
return true
Expand Down
67 changes: 37 additions & 30 deletions pkg/apis/db/v1alpha1/cassandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,36 @@ const (
DefaultUserID int64 = 999
)

type ClusterStateInfo struct {
Id float64
Name string
}

var (
//Cluster phases
ClusterPhaseInitial = ClusterStateInfo{1, "Initializing"}
ClusterPhaseRunning = ClusterStateInfo{2, "Running"}
ClusterPhasePending = ClusterStateInfo{3, "Pending"}

//Available actions
ActionUpdateConfigMap = ClusterStateInfo{1, "UpdateConfigMap"}
ActionUpdateDockerImage = ClusterStateInfo{2, "UpdateDockerImage"}
ActionUpdateSeedList = ClusterStateInfo{3, "UpdateSeedList"}
ActionRollingRestart = ClusterStateInfo{4, "RollingRestart"}
ActionUpdateResources = ClusterStateInfo{5, "UpdateResources"}
ActionUpdateStatefulSet = ClusterStateInfo{6, "UpdateStatefulSet"}
ActionScaleUp = ClusterStateInfo{7, "ScaleUp"}
ActionScaleDown = ClusterStateInfo{8, "ScaleDown"}

ActionDeleteDC = ClusterStateInfo{9, "ActionDeleteDC"}
ActionDeleteRack = ClusterStateInfo{10, "ActionDeleteRack"}

ActionCorrectCRDConfig = ClusterStateInfo{11, "CorrectCRDConfig"} //The Operator has correct a bad CRD configuration

)

const (
AnnotationLastApplied string = "cassandraclusters.db.orange.com/last-applied-configuration"
//Phase du Cluster
ClusterPhaseInitial string = "Initializing"
ClusterPhaseRunning string = "Running"
ClusterPhasePending string = "Pending"

StatusOngoing string = "Ongoing" // The Action is Ongoing
StatusDone string = "Done" // The Action id Done
Expand All @@ -67,21 +91,6 @@ const (
StatusManual string = "Manual"
StatusError string = "Error"

//Available actions
ActionUpdateConfigMap string = "UpdateConfigMap"
ActionUpdateDockerImage string = "UpdateDockerImage"
ActionUpdateSeedList string = "UpdateSeedList"
ActionRollingRestart string = "RollingRestart"
ActionUpdateResources string = "UpdateResources"
ActionUpdateStatefulSet string = "UpdateStatefulSet"
ActionScaleUp string = "ScaleUp"
ActionScaleDown string = "ScaleDown"

ActionDeleteDC string = "ActionDeleteDC"
ActionDeleteRack string = "ActionDeleteRack"

ActionCorrectCRDConfig string = "CorrectCRDConfig" //The Operator has correct a bad CRD configuration

//List of Pods Operations
OperationUpgradeSSTables string = "upgradesstables"
OperationCleanup string = "cleanup"
Expand Down Expand Up @@ -134,7 +143,7 @@ func (cc *CassandraCluster) SetDefaults() bool {
changed = true
}
if len(cc.Status.Phase) == 0 {
cc.Status.Phase = ClusterPhaseInitial
cc.Status.Phase = ClusterPhaseInitial.Name
if cc.InitCassandraRackList() < 1 {
logrus.Errorf("[%s]: We should have at list One Rack, Please correct the Error", cc.Name)
}
Expand Down Expand Up @@ -281,9 +290,9 @@ func (cc *CassandraCluster) initTopology(dcName string, rackName string) {
func (cc *CassandraCluster) initCassandraRack(dcName string, rackName string) {
dcRackName := cc.GetDCRackName(dcName, rackName)
var rackStatus = CassandraRackStatus{
Phase: ClusterPhaseInitial,
Phase: ClusterPhaseInitial.Name,
CassandraLastAction: CassandraLastAction{
Name: ClusterPhaseInitial,
Name: ClusterPhaseInitial.Name,
Status: StatusOngoing,
},
}
Expand All @@ -299,9 +308,9 @@ func (cc *CassandraCluster) initCassandraRack(dcName string, rackName string) {
func (cc *CassandraCluster) InitCassandraRackinStatus(status *CassandraClusterStatus, dcName string, rackName string) {
dcRackName := cc.GetDCRackName(dcName, rackName)
var rackStatus CassandraRackStatus = CassandraRackStatus{
Phase: ClusterPhaseInitial,
Phase: ClusterPhaseInitial.Name,
CassandraLastAction: CassandraLastAction{
Name: ClusterPhaseInitial,
Name: ClusterPhaseInitial.Name,
Status: StatusOngoing,
},
}
Expand Down Expand Up @@ -615,6 +624,7 @@ func (dc *DCSlice) Remove(i int) {
func (rack *RackSlice) Remove(i int) {
*rack = append((*rack)[:i], (*rack)[i+1:]...)
}

// CassandraClusterSpec defines the configuration of CassandraCluster

type CassandraClusterSpec struct {
Expand Down Expand Up @@ -721,12 +731,12 @@ type CassandraClusterSpec struct {
// StorageConfig defines additional storage configurations
type StorageConfig struct {
// Mount path into cassandra container
MountPath string `json:"mountPath"`
MountPath string `json:"mountPath"`
// Name of the pvc
// +kubebuilder:validation:Pattern=[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*
Name string `json:"name"`
Name string `json:"name"`
// Persistent volume claim spec
PVCSpec *v1.PersistentVolumeClaimSpec `json:"pvcSpec"`
PVCSpec *v1.PersistentVolumeClaimSpec `json:"pvcSpec"`
}

// Topology allow to configure the Cassandra Topology according to kubernetes Nodes labels
Expand Down Expand Up @@ -755,7 +765,6 @@ type DC struct {

//NumTokens : configure the CASSANDRA_NUM_TOKENS parameter which can be different for each DD
NumTokens *int32 `json:"numTokens,omitempty"`

}

// Rack allow to configure Cassandra Rack according to kubernetes nodeselector labels
Expand Down Expand Up @@ -898,5 +907,3 @@ type CassandraClusterList struct {
func init() {
SchemeBuilder.Register(&CassandraCluster{}, &CassandraClusterList{})
}


Loading