Skip to content

Commit

Permalink
Some style changes + logging and a changelog entry for new operation
Browse files Browse the repository at this point in the history
modes

Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Jul 24, 2024
1 parent 9caa882 commit b2d4a96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 10 additions & 6 deletions metrics/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -231,17 +231,21 @@ 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, &currentSeriesCount, 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, &currentSeriesCount, changeSeriesTick.C, 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)
}
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, &currentSeriesCount, changeSeriesTick, updateNotify)
go handleGradualChangeMode(metricCount, metricLength, metricCycle, seriesCycle, labelKeys, labelValues,
seriesChangeRate, minSeriesCount, maxSeriesCount, &currentSeriesCount, changeSeriesTick.C, updateNotify)
go handleValueTicks(&labelKeys, &labelValues, &currentSeriesCount, &seriesCycle, updateNotify, valueTick)
go handleSeriesTicks(&labelKeys, &labelValues, &currentSeriesCount, &seriesCycle, updateNotify, seriesTick)

Expand Down

0 comments on commit b2d4a96

Please sign in to comment.