diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c1da28..758e9a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## unreleased +* [FEATURE] add two new operation modes for metrics generation and cycling; gradual-change between min and max and double-halve #64 + ## 0.4.0 / 2022-03-08 Initial release under the Prometheus-community org. diff --git a/metrics/serve.go b/metrics/serve.go index ca49bca..30dcac1 100644 --- a/metrics/serve.go +++ b/metrics/serve.go @@ -156,9 +156,9 @@ func changeSeriesDoubleHalve(currentSeriesCount *int, seriesIncrease *bool) { *seriesIncrease = !*seriesIncrease } -func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, currentSeriesCount *int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) { +func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, currentSeriesCount *int, changeSeriesChan <-chan time.Time, updateNotify chan struct{}) { seriesIncrease := true - for tick := range changeSeriesTick.C { + for tick := range changeSeriesChan { metricsMux.Lock() unregisterMetrics() registerMetrics(metricCount, metricLength, metricCycle, labelKeys) @@ -176,11 +176,11 @@ func handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle i } } -func handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, seriesChangeRate, maxSeriesCount, minSeriesCount int, seriesCount *int, changeSeriesTick *time.Ticker, updateNotify chan struct{}) { +func handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle int, labelKeys, labelValues []string, seriesChangeRate, minSeriesCount, maxSeriesCount int, seriesCount *int, changeSeriesChan <-chan time.Time, updateNotify chan struct{}) { *seriesCount = minSeriesCount seriesIncrease := true - for tick := range changeSeriesTick.C { + for tick := range changeSeriesChan { metricsMux.Lock() unregisterMetrics() registerMetrics(metricCount, metricLength, metricCycle, labelKeys) @@ -231,7 +231,8 @@ func RunMetrics(metricCount, labelCount, seriesCount, seriesChangeRate, maxSerie case "double-halve": registerMetrics(metricCount, metricLength, metricCycle, labelKeys) cycleValues(labelKeys, labelValues, currentSeriesCount, seriesCycle) - go handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, ¤tSeriesCount, changeSeriesTick, updateNotify) + fmt.Printf("Starting double-halve mode; starting series: %d, change series interval: %d seconds\n", currentSeriesCount, seriesChangeInterval) + go handleDoubleHalveMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, ¤tSeriesCount, changeSeriesTick.C, updateNotify) go handleValueTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, valueTick) go handleSeriesTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, seriesTick) @@ -239,9 +240,12 @@ func RunMetrics(metricCount, labelCount, seriesCount, seriesChangeRate, maxSerie if minSeriesCount >= maxSeriesCount { return nil, fmt.Errorf("error: minSeriesCount must be less than maxSeriesCount, got %d and %d", minSeriesCount, maxSeriesCount) } + fmt.Printf("Starting gradual-change mode; min series: %d, max series: %d, series change rate: %d, change series interval: %d seconds\n", minSeriesCount, maxSeriesCount, seriesChangeRate, seriesChangeInterval) + registerMetrics(metricCount, metricLength, metricCycle, labelKeys) cycleValues(labelKeys, labelValues, minSeriesCount, seriesCycle) - go handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, seriesChangeRate, maxSeriesCount, minSeriesCount, ¤tSeriesCount, changeSeriesTick, updateNotify) + go handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues, + seriesChangeRate, minSeriesCount, maxSeriesCount, ¤tSeriesCount, changeSeriesTick.C, updateNotify) go handleValueTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, valueTick) go handleSeriesTicks(&labelKeys, &labelValues, ¤tSeriesCount, &seriesCycle, updateNotify, seriesTick)