From bddbb3beda2adbdb3378f25630cc38a08a77e6a4 Mon Sep 17 00:00:00 2001 From: yomek33 Date: Wed, 24 Jul 2024 04:08:32 +0900 Subject: [PATCH] change currentSeriesCount to be a pointer Signed-off-by: yomek33 --- metrics/serve.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/metrics/serve.go b/metrics/serve.go index 3b95341..26e63a9 100644 --- a/metrics/serve.go +++ b/metrics/serve.go @@ -128,6 +128,7 @@ func handleMetricTicks(metricCount, metricLength, metricCycle *int, labelKeys *[ } func changeSeriesGradual(seriesChangeRate, maxSeriesCount, minSeriesCount, currentSeriesCount *int, seriesIncrease *bool) { + fmt.Printf("Current series count: %d\n", *currentSeriesCount) if *seriesIncrease { *currentSeriesCount += *seriesChangeRate if *currentSeriesCount >= *maxSeriesCount { @@ -136,7 +137,7 @@ func changeSeriesGradual(seriesChangeRate, maxSeriesCount, minSeriesCount, curre } } else { *currentSeriesCount -= *seriesChangeRate - if *currentSeriesCount <= *minSeriesCount { + if *currentSeriesCount < *minSeriesCount { *currentSeriesCount = *minSeriesCount *seriesIncrease = true } @@ -155,19 +156,18 @@ func changeSeriesDoubleHalve(currentSeriesCount *int, seriesIncrease *bool) { *seriesIncrease = !*seriesIncrease } -func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, seriesCount int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) { - currentSeriesCount := seriesCount +func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, currentSeriesCount *int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) { seriesIncrease := true for tick := range changeSeriesTick.C { metricsMux.Lock() unregisterMetrics() registerMetrics(metricCount, metricLength, metricCycle, labelKeys) - cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle) + cycleValues(labelKeys, labelValues, *currentSeriesCount, seriesCycle) metricsMux.Unlock() - changeSeriesDoubleHalve(¤tSeriesCount, &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{}{}: @@ -177,19 +177,19 @@ func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle i } func handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, seriesChangeRate, maxSeriesCount, minSeriesCount int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) { - currentSeriesCount := minSeriesCount + currentSeriesCount := &minSeriesCount seriesIncrease := true for tick := range changeSeriesTick.C { metricsMux.Lock() unregisterMetrics() registerMetrics(metricCount, metricLength, metricCycle, labelKeys) - cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle) + cycleValues(labelKeys, labelValues, *currentSeriesCount, seriesCycle) metricsMux.Unlock() - changeSeriesGradual(&seriesChangeRate, &maxSeriesCount, &minSeriesCount, ¤tSeriesCount, &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{}{}: @@ -225,13 +225,13 @@ func RunMetrics(metricCount, labelCount, seriesCount, seriesChangeRate, maxSerie changeSeriesTick := time.NewTicker(time.Duration(seriesChangeInterval) * time.Second) updateNotify := make(chan struct{}, 1) - var currentSeriesCount int + currentSeriesCount := seriesCount switch seriesOperationMode { case "double-halve": registerMetrics(metricCount, metricLength, metricCycle, labelKeys) cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle) - go handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, seriesCount, changeSeriesTick, updateNotify) + go handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, ¤tSeriesCount, changeSeriesTick, updateNotify) go handleValueTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, valueTick) go handleSeriesTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, seriesTick) @@ -246,9 +246,8 @@ func RunMetrics(metricCount, labelCount, seriesCount, seriesChangeRate, maxSerie go handleSeriesTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, seriesTick) default: - currentSeriesCount = seriesCount registerMetrics(metricCount, metricLength, metricCycle, labelKeys) - cycleValues(labelKeys, labelValues, seriesCount, seriesCycle) + cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle) go handleValueTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, valueTick) go handleSeriesTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, seriesTick) go handleMetricTicks(&metricCount, &metricLength, &metricCycle, &labelKeys, updateNotify, metricTick)