Skip to content

Commit

Permalink
ROX-12921: initialize counter metrics with 0 value (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-degtiarenko authored Jan 16, 2023
1 parent 96a8b44 commit 3d62108
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/golang/glog"
)

const acceptedCentralWorkerType = "accepted_dinosaur"

// AcceptedCentralManager represents a manager that periodically reconciles central requests
type AcceptedCentralManager struct {
workers.BaseWorker
Expand All @@ -32,10 +34,11 @@ type AcceptedCentralManager struct {

// NewAcceptedCentralManager creates a new manager
func NewAcceptedCentralManager(centralService services.DinosaurService, quotaServiceFactory services.QuotaServiceFactory, clusterPlmtStrategy services.ClusterPlacementStrategy, dataPlaneClusterConfig *config.DataplaneClusterConfig, centralConfig *config.CentralConfig) *AcceptedCentralManager {
metrics.InitReconcilerMetricsForType(acceptedCentralWorkerType)
return &AcceptedCentralManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "accepted_dinosaur",
WorkerType: acceptedCentralWorkerType,
Reconciler: workers.Reconciler{},
},
centralService: centralService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"net/http"

"github.com/stackrox/acs-fleet-manager/pkg/metrics"

"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
Expand All @@ -19,6 +21,8 @@ import (
"github.com/golang/glog"
)

const deletingCentralWorkerType = "deleting_dinosaur"

// DeletingDinosaurManager represents a dinosaur manager that periodically reconciles dinosaur requests.
type DeletingDinosaurManager struct {
workers.BaseWorker
Expand All @@ -31,10 +35,11 @@ type DeletingDinosaurManager struct {
// NewDeletingDinosaurManager creates a new dinosaur manager.
func NewDeletingDinosaurManager(dinosaurService services.DinosaurService, iamConfig *iam.IAMConfig,
quotaServiceFactory services.QuotaServiceFactory) *DeletingDinosaurManager {
metrics.InitReconcilerMetricsForType(deletingCentralWorkerType)
return &DeletingDinosaurManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "deleting_dinosaur",
WorkerType: deletingCentralWorkerType,
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/stackrox/acs-fleet-manager/pkg/metrics"

"github.com/stackrox/rox/pkg/stringutils"

"github.com/golang/glog"
Expand Down Expand Up @@ -41,12 +43,13 @@ var _ workers.Worker = (*CentralAuthConfigManager)(nil)
// In case this function fails, fleet-manager will fail on the startup.
func NewCentralAuthConfigManager(centralService services.DinosaurService, iamConfig *iam.IAMConfig, centralConfig *config.CentralConfig) (*CentralAuthConfigManager, error) {
realmConfig := iamConfig.RedhatSSORealm

if !centralConfig.HasStaticAuth() && !realmConfig.IsConfigured() {
return nil, errors.Errorf("failed to create %s worker: neither static nor dynamic auth configuration was provided", centralAuthConfigManagerWorkerType)
}

dynamicClientsAPI := dynamicclients.NewDynamicClientsAPI(realmConfig)

metrics.InitReconcilerMetricsForType(centralAuthConfigManagerWorkerType)

return &CentralAuthConfigManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"github.com/pkg/errors"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/config"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
"github.com/stackrox/acs-fleet-manager/pkg/metrics"
"github.com/stackrox/acs-fleet-manager/pkg/workers"
)

const centralDNSWorkerType = "dinosaur_dns"

// DinosaurRoutesCNAMEManager ...
type DinosaurRoutesCNAMEManager struct {
workers.BaseWorker
Expand All @@ -20,10 +23,11 @@ var _ workers.Worker = &DinosaurRoutesCNAMEManager{}

// NewDinosaurCNAMEManager ...
func NewDinosaurCNAMEManager(dinosaurService services.DinosaurService, kafkfConfig *config.CentralConfig) *DinosaurRoutesCNAMEManager {
metrics.InitReconcilerMetricsForType(centralDNSWorkerType)
return &DinosaurRoutesCNAMEManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "dinosaur_dns",
WorkerType: centralDNSWorkerType,
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
serviceErr "github.com/stackrox/acs-fleet-manager/pkg/errors"
)

const preparingCentralWorkerType = "preparing_dinosaur"

// PreparingDinosaurManager represents a dinosaur manager that periodically reconciles dinosaur requests
type PreparingDinosaurManager struct {
workers.BaseWorker
Expand All @@ -28,10 +30,11 @@ type PreparingDinosaurManager struct {

// NewPreparingDinosaurManager creates a new dinosaur manager
func NewPreparingDinosaurManager(dinosaurService services.DinosaurService, centralConfig *config.CentralConfig) *PreparingDinosaurManager {
metrics.InitReconcilerMetricsForType(preparingCentralWorkerType)
return &PreparingDinosaurManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "preparing_dinosaur",
WorkerType: preparingCentralWorkerType,
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/golang/glog"
)

const provisioningCentralWorkerType = "provisioning_dinosaur"

// ProvisioningDinosaurManager represents a dinosaur manager that periodically reconciles dinosaur requests
type ProvisioningDinosaurManager struct {
workers.BaseWorker
Expand All @@ -26,10 +28,11 @@ type ProvisioningDinosaurManager struct {

// NewProvisioningDinosaurManager creates a new dinosaur manager
func NewProvisioningDinosaurManager(dinosaurService services.DinosaurService, observatoriumService services.ObservatoriumService, centralConfig *config.CentralConfig) *ProvisioningDinosaurManager {
metrics.InitReconcilerMetricsForType(provisioningCentralWorkerType)
return &ProvisioningDinosaurManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "provisioning_dinosaur",
WorkerType: provisioningCentralWorkerType,
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
constants2 "github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
"github.com/stackrox/acs-fleet-manager/pkg/client/iam"
"github.com/stackrox/acs-fleet-manager/pkg/metrics"
"github.com/stackrox/acs-fleet-manager/pkg/services/sso"
"github.com/stackrox/acs-fleet-manager/pkg/workers"
)

const readyCentralWorkerType = "ready_dinosaur"

// ReadyDinosaurManager represents a dinosaur manager that periodically reconciles dinosaur requests
type ReadyDinosaurManager struct {
workers.BaseWorker
Expand All @@ -21,10 +24,11 @@ type ReadyDinosaurManager struct {

// NewReadyDinosaurManager creates a new dinosaur manager
func NewReadyDinosaurManager(dinosaurService services.DinosaurService, iamService sso.IAMService, iamConfig *iam.IAMConfig) *ReadyDinosaurManager {
metrics.InitReconcilerMetricsForType(readyCentralWorkerType)
return &ReadyDinosaurManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "ready_dinosaur",
WorkerType: readyCentralWorkerType,
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
Expand Down
10 changes: 10 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,13 @@ func Reset() {
databaseRequestCountMetric.Reset()
databaseQueryDurationMetric.Reset()
}

// InitReconcilerMetricsForType initalizes reconciler metrics for specific reconciler type.
func InitReconcilerMetricsForType(reconcilerType string) {
labels := prometheus.Labels{
labelWorkerType: reconcilerType,
}
reconcilerFailureCountMetric.With(labels).Add(0)
reconcilerSuccessCountMetric.With(labels).Add(0)
reconcilerErrorsCountMetric.With(labels).Add(0)
}

0 comments on commit 3d62108

Please sign in to comment.