Skip to content

Commit

Permalink
temperary remove profileStatusPerNode until otel support reset metric
Browse files Browse the repository at this point in the history
  • Loading branch information
UgOrange committed Nov 13, 2024
1 parent 1f358f6 commit 1ebe1b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
32 changes: 16 additions & 16 deletions internal/status/api/v1/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ type StatusManager struct {
PolicyStatuses map[string]varmortypes.PolicyStatus
// Use "namespace/VarmorPolicyName" as key. One VarmorPolicy object corresponds to one ModelingStatus
// TODO: Rebuild ModelingStatuses from ArmorProfile object when leader change occurs.
ModelingStatuses map[string]varmortypes.ModelingStatus
ResetCh chan string
DeleteCh chan string
UpdateStatusCh chan string
UpdateModeCh chan string
statusQueue workqueue.RateLimitingInterface
dataQueue workqueue.RateLimitingInterface
statusUpdateCycle time.Duration
debug bool
log logr.Logger
metricsModule *varmormetrics.MetricsModule
profileSuccess metric.Float64Counter
profileFailure metric.Float64Counter
profileChangeCount metric.Float64Counter
profileStatusPerNode metric.Float64Gauge
ModelingStatuses map[string]varmortypes.ModelingStatus
ResetCh chan string
DeleteCh chan string
UpdateStatusCh chan string
UpdateModeCh chan string
statusQueue workqueue.RateLimitingInterface
dataQueue workqueue.RateLimitingInterface
statusUpdateCycle time.Duration
debug bool
log logr.Logger
metricsModule *varmormetrics.MetricsModule
profileSuccess metric.Float64Counter
profileFailure metric.Float64Counter
profileChangeCount metric.Float64Counter
//profileStatusPerNode metric.Float64Gauge
}

func NewStatusManager(coreInterface corev1.CoreV1Interface,
Expand Down Expand Up @@ -99,7 +99,7 @@ func NewStatusManager(coreInterface corev1.CoreV1Interface,
m.profileSuccess = metricsModule.RegisterFloat64Counter("profile_processing_success", "Number of successful profile processing")
m.profileFailure = metricsModule.RegisterFloat64Counter("profile_processing_failure", "Number of failed profile processing")
m.profileChangeCount = metricsModule.RegisterFloat64Counter("profile_change_count", "Number of profile change")
m.profileStatusPerNode = metricsModule.RegisterFloat64Gauge("profile_status_per_node", "Profile status per node (1=success, 0=failure)")
//m.profileStatusPerNode = metricsModule.RegisterFloat64Gauge("profile_status_per_node", "Profile status per node (1=success, 0=failure)")
}

return &m
Expand Down
61 changes: 31 additions & 30 deletions internal/status/api/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,36 +88,37 @@ func (m *StatusManager) HandleProfileStatusUpdate(status varmortypes.ProfileStat
m.profileChangeCount.Add(ctx, 1, metric.WithAttributeSet(attrSet))
}

func (m *StatusManager) syncStatusMetricsLoop() {
ctx := context.Background()
for {
time.Sleep(time.Duration(m.metricsModule.Refresh) * time.Second)
logger := m.log.WithName("syncStatusMetricsLoop()")
logger.Info("start syncing status metrics")
m.profileStatusPerNode = m.metricsModule.RegisterFloat64Gauge("profile_status_per_node", "Profile status per node (1=success, 0=failure)")
for key, status := range m.PolicyStatuses {
namespace, name, err := PolicyStatusKeyGetInfo(key)
if err != nil {
logger.Error(err, "PolicyStatusKeyGetInfo()")
continue
}
for nodeName, nodeMessage := range status.NodeMessages {
labels := []attribute.KeyValue{
attribute.String("namespace", namespace),
attribute.String("profile_name", name),
attribute.String("node_name", nodeName),
attribute.Int64("timestamp", time.Now().Unix()),
}
attrSet := attribute.NewSet(labels...)
if nodeMessage == string(varmortypes.ArmorProfileReady) {
m.profileStatusPerNode.Record(ctx, 1, metric.WithAttributeSet(attrSet)) // 1 mean success
} else {
m.profileStatusPerNode.Record(ctx, 0, metric.WithAttributeSet(attrSet)) // 0 mean failure
}
}
}
}
}
// disable syncStatusMetricsLoop until otel support clear metrics
//func (m *StatusManager) syncStatusMetricsLoop() {
// ctx := context.Background()
// for {
// time.Sleep(time.Duration(m.metricsModule.Refresh) * time.Second)
// logger := m.log.WithName("syncStatusMetricsLoop()")
// logger.Info("start syncing status metrics")
// m.profileStatusPerNode = m.metricsModule.RegisterFloat64Gauge("profile_status_per_node", "Profile status per node (1=success, 0=failure)")
// for key, status := range m.PolicyStatuses {
// namespace, name, err := PolicyStatusKeyGetInfo(key)
// if err != nil {
// logger.Error(err, "PolicyStatusKeyGetInfo()")
// continue
// }
// for nodeName, nodeMessage := range status.NodeMessages {
// labels := []attribute.KeyValue{
// attribute.String("namespace", namespace),
// attribute.String("profile_name", name),
// attribute.String("node_name", nodeName),
// attribute.Int64("timestamp", time.Now().Unix()),
// }
// attrSet := attribute.NewSet(labels...)
// if nodeMessage == string(varmortypes.ArmorProfileReady) {
// m.profileStatusPerNode.Record(ctx, 1, metric.WithAttributeSet(attrSet)) // 1 mean success
// } else {
// m.profileStatusPerNode.Record(ctx, 0, metric.WithAttributeSet(attrSet)) // 0 mean failure
// }
// }
// }
// }
//}

// updatePolicyStatus update StatusManager.PolicyStatuses[statusKey] with profileStatus which comes from agent.
func (m *StatusManager) updatePolicyStatus(statusKey string, profileStatus *varmortypes.ProfileStatus) error {
Expand Down

0 comments on commit 1ebe1b8

Please sign in to comment.