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

Commit

Permalink
Merge pull request #198 from cscetbon/metrics
Browse files Browse the repository at this point in the history
Add custom metrics to operator
  • Loading branch information
cscetbon authored Mar 6, 2020
2 parents e3cf410 + 1a12019 commit f251372
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 247 deletions.
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
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1666,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
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 @@ -52,12 +52,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 @@ -68,21 +92,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 @@ -135,7 +144,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 @@ -282,9 +291,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 @@ -300,9 +309,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 @@ -616,6 +625,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 @@ -727,12 +737,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 @@ -761,7 +771,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 @@ -912,5 +921,3 @@ type CassandraClusterList struct {
func init() {
SchemeBuilder.Register(&CassandraCluster{}, &CassandraClusterList{})
}


Loading

0 comments on commit f251372

Please sign in to comment.