Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Disk Manager] improve collect lister metrics task #2288

Merged
merged 1 commit into from
Oct 16, 2024
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
22 changes: 19 additions & 3 deletions cloud/tasks/collect_lister_metrics_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ import (

////////////////////////////////////////////////////////////////////////////////

const totalHangingTaskCountGaugeName = "totalHangingTaskCount"

////////////////////////////////////////////////////////////////////////////////

type collectListerMetricsTask struct {
registry metrics.Registry
storage storage.Storage
metricsCollectionInterval time.Duration

taskTypes []string
hangingTaskGaugesByID map[string]metrics.Gauge
maxHangingTaskIDsToReport int64
}
Expand Down Expand Up @@ -134,6 +139,9 @@ func (c *collectListerMetricsTask) collectTasksMetrics(
) error {

tasksByType := make(map[string]uint64)
for _, taskType := range c.taskTypes {
tasksByType[taskType] = 0
}

taskInfos, err := getTaskInfos(ctx)
if err != nil {
Expand All @@ -158,14 +166,22 @@ func (c *collectListerMetricsTask) collectHangingTasksMetrics(
ctx context.Context,
) error {

totalHangingTasksGauge := c.registry.Gauge("totalHangingTaskCount")

taskInfos, err := c.storage.ListHangingTasks(ctx, ^uint64(0))
if err != nil {
return err
}

totalHangingTasksGauge.Set(float64(len(taskInfos)))
err = c.collectTasksMetrics(
ctx,
func(context.Context) ([]storage.TaskInfo, error) {
return taskInfos, nil
},
totalHangingTaskCountGaugeName,
)
if err != nil {
return err
}

taskInfoByID := make(map[string]storage.TaskInfo)
for _, taskInfo := range taskInfos {
taskInfoByID[taskInfo.ID] = taskInfo
Expand Down
1 change: 1 addition & 0 deletions cloud/tasks/scheduler_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ func NewScheduler(
storage: storage,
metricsCollectionInterval: listerMetricsCollectionInterval,

taskTypes: registry.TaskTypesForExecution(),
SvartMetal marked this conversation as resolved.
Show resolved Hide resolved
hangingTaskGaugesByID: make(map[string]metrics.Gauge),
maxHangingTaskIDsToReport: config.GetMaxHangingTaskIDsToReport(),
}
Expand Down
22 changes: 18 additions & 4 deletions cloud/tasks/tasks_tests/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,11 +1252,25 @@ func TestHangingTasksMetrics(t *testing.T) {
gaugeSetWg := sync.WaitGroup{}
gaugeUnsetWg := sync.WaitGroup{}

registry.GetGauge("totalHangingTaskCount", map[string]string{}).On(
totalHangingTaskCountGaugeSetCall := registry.GetGauge(
"totalHangingTaskCount",
map[string]string{"type": "tasks.hanging"},
).On(
"Set",
mock.Anything,
float64(1),
).Return(mock.Anything)
gaugeSetCall := registry.GetGauge(

registry.GetGauge(
"totalHangingTaskCount",
map[string]string{"type": "tasks.hanging"},
).On(
"Set",
float64(0),
).NotBefore(
totalHangingTaskCountGaugeSetCall,
).Return(mock.Anything)

hangingTasksGaugeSetCall := registry.GetGauge(
"hangingTasks",
map[string]string{"type": "tasks.hanging", "id": taskID},
).On("Set", float64(1)).Return(mock.Anything).Run(
Expand All @@ -1273,7 +1287,7 @@ func TestHangingTasksMetrics(t *testing.T) {
"Set",
float64(0),
).NotBefore(
gaugeSetCall,
hangingTasksGaugeSetCall,
).Return(mock.Anything).Run(
func(args mock.Arguments) {
gaugeUnsetWg.Done()
Expand Down
Loading