Skip to content

Commit

Permalink
Update metrics handling logic
Browse files Browse the repository at this point in the history
Signed-off-by: yomek33 <[email protected]>
  • Loading branch information
yomek33 committed Jul 19, 2024
1 parent e4a2d56 commit 8d7c0c5
Showing 1 changed file with 32 additions and 37 deletions.
69 changes: 32 additions & 37 deletions metrics/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,55 +160,46 @@ func changeSeriesDoubleHalve(currentSeriesCount *int, seriesIncrease *bool) {
func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, seriesCount int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) {
currentSeriesCount := seriesCount
seriesIncrease := true
for tick := range changeSeriesTick.C {
metricsMux.Lock()
unregisterMetrics()
registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle)
metricsMux.Unlock()

registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle)

go func() {
for tick := range changeSeriesTick.C {
metricsMux.Lock()
unregisterMetrics()
registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle)
metricsMux.Unlock()

changeSeriesDoubleHalve(&currentSeriesCount, &seriesIncrease)
changeSeriesDoubleHalve(&currentSeriesCount, &seriesIncrease)

fmt.Printf("%v: Adjusting series count. New count: %d\n", tick, currentSeriesCount)
fmt.Printf("%v: Adjusting series count. New count: %d\n", tick, currentSeriesCount)

select {
case updateNotify <- struct{}{}:
default:
}
select {
case updateNotify <- struct{}{}:
default:
}
}()
}

}

func handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, seriesChangeRate, maxSeriesCount, minSeriesCount int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) {
currentSeriesCount := minSeriesCount
seriesIncrease := true

registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, minSeriesCount, seriesCycle)

go func() {
for tick := range changeSeriesTick.C {
metricsMux.Lock()
unregisterMetrics()
registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle)
metricsMux.Unlock()
for tick := range changeSeriesTick.C {
metricsMux.Lock()
unregisterMetrics()
registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle)
metricsMux.Unlock()

changeSeriesGradual(&seriesChangeRate, &maxSeriesCount, &minSeriesCount, &currentSeriesCount, &seriesIncrease)
changeSeriesGradual(&seriesChangeRate, &maxSeriesCount, &minSeriesCount, &currentSeriesCount, &seriesIncrease)

fmt.Printf("%v: Adjusting series count. New count: %d\n", tick, currentSeriesCount)
fmt.Printf("%v: Adjusting series count. New count: %d\n", tick, currentSeriesCount)

select {
case updateNotify <- struct{}{}:
default:
}
select {
case updateNotify <- struct{}{}:
default:
}
}()
}

}

// RunMetrics creates a set of Prometheus test series that update over time
Expand Down Expand Up @@ -242,15 +233,19 @@ func RunMetrics(metricCount, labelCount, seriesCount, seriesChangeRate, maxSerie

switch seriesOperationMode {
case "double-halve":
handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, seriesCount, changeSeriesTick, updateNotify)
registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle)
go handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, seriesCount, changeSeriesTick, updateNotify)
go handleValueTicks(&labelKeys, &labelValues, &currentSeriesCount, &seriesCycle, updateNotify, valueTick)
go handleSeriesTicks(&labelKeys, &labelValues, &currentSeriesCount, &seriesCycle, updateNotify, seriesTick)

case "gradual-change":
if minSeriesCount >= maxSeriesCount {
return nil, fmt.Errorf("error: minSeriesCount must be less than maxSeriesCount, got %d and %d", minSeriesCount, maxSeriesCount)
}
handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, seriesChangeRate, maxSeriesCount, minSeriesCount, changeSeriesTick, updateNotify)
registerMetrics(metricCount, metricLength, metricCycle, labelKeys)
cycleValues(labelKeys, labelValues, minSeriesCount, seriesCycle)
go handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, seriesChangeRate, maxSeriesCount, minSeriesCount, changeSeriesTick, updateNotify)
go handleValueTicks(&labelKeys, &labelValues, &currentSeriesCount, &seriesCycle, updateNotify, valueTick)
go handleSeriesTicks(&labelKeys, &labelValues, &currentSeriesCount, &seriesCycle, updateNotify, seriesTick)

Expand Down

0 comments on commit 8d7c0c5

Please sign in to comment.