generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: QuentinBisson <[email protected]>
- Loading branch information
1 parent
af400f5
commit faffcbe
Showing
14 changed files
with
232 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Introduction | ||
|
||
The Observability Operator is in charge of configuring the Prometheus Agent instances running in workload clusters like remote write configuration, [sharding](sharding.md) and so on. | ||
|
||
TODO(atlas): Add documentation here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
# Prometheus Agent Sharding | ||
|
||
To be able to ingest metrics without disrupting the workload running in the clusters, the observability operator decides on the number of running __prometheus agent shards__ for each workload cluster based . The number of shards depends on the __total number of time series__ stored for a given cluster. | ||
|
||
__By default__, the operator configures a shard for every 1M time series present in Mimir for the workload cluster. To avoid scaling down too abruptly, we defined a scale down threshold of 20%. | ||
|
||
As this default value was not enough to avoid workload disruptions, we added 2 ways to be able to override the scale up series count target and the scale down percentage. | ||
|
||
1. Those values can be configured at the installation level by overriding the following values: | ||
|
||
```yaml | ||
monitoring: | ||
sharding: | ||
scaleUpSeriesCount: 1000000 | ||
scaleDownPercentage: 0.20 | ||
``` | ||
2. Those values can also be set per cluster using the following cluster annotations: | ||
```yaml | ||
monitoring.giantswarm.io/prometheus-agent-scale-up-series-count: 1000000 | ||
monitoring.giantswarm.io/prometheus-agent-scale-down-percentage: 0.20 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package monitoring | ||
|
||
// Config represents the configuration used by the monitoring package. | ||
type Config struct { | ||
Enabled bool | ||
ShardingScaleUpSeriesCount float64 | ||
ShardingScaleDownPercentage float64 | ||
// TODO(atlas): validate prometheus version | ||
PrometheusVersion string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package sharding | ||
|
||
import "math" | ||
|
||
type ShardingStrategy struct { | ||
// Configures the number of series needed to add a new shard. Computation is number of series / ScaleUpSeriesCount | ||
ScaleUpSeriesCount float64 | ||
// Percentage of needed series based on ScaleUpSeriesCount to scale down agents | ||
ScaleDownPercentage float64 | ||
} | ||
|
||
func (pass1 ShardingStrategy) Merge(pass2 *ShardingStrategy) ShardingStrategy { | ||
strategy := ShardingStrategy{ | ||
pass1.ScaleUpSeriesCount, | ||
pass1.ScaleDownPercentage, | ||
} | ||
if pass2 != nil { | ||
if pass2.ScaleUpSeriesCount > 0 { | ||
strategy.ScaleUpSeriesCount = pass2.ScaleUpSeriesCount | ||
} | ||
if pass2.ScaleDownPercentage > 0 { | ||
strategy.ScaleDownPercentage = pass2.ScaleDownPercentage | ||
} | ||
} | ||
return strategy | ||
} | ||
|
||
// We want to start with 1 prometheus-agent for each 1M time series with a scale down 20% threshold. | ||
func (pass ShardingStrategy) ComputeShards(currentShardCount int, timeSeries float64) int { | ||
shardScaleDownThreshold := pass.ScaleDownPercentage * pass.ScaleUpSeriesCount | ||
desiredShardCount := int(math.Ceil(timeSeries / pass.ScaleUpSeriesCount)) | ||
|
||
// Compute Scale Down | ||
if currentShardCount > desiredShardCount { | ||
// We get the rest of a division of timeSeries by shardStep and we compare it with the scale down threshold | ||
if math.Mod(timeSeries, pass.ScaleUpSeriesCount) > pass.ScaleUpSeriesCount-shardScaleDownThreshold { | ||
desiredShardCount = currentShardCount | ||
} | ||
} | ||
|
||
// We always have a minimum of 1 agent, even if there is no worker node | ||
if desiredShardCount <= 0 { | ||
return 1 | ||
} | ||
return desiredShardCount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package sharding | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestShardComputationScaleUp(t *testing.T) { | ||
pass := ShardingStrategy{ScaleUpSeriesCount: float64(1_000_000), ScaleDownPercentage: float64(0.20)} | ||
|
||
expected := 1 | ||
result := pass.ComputeShards(0, float64(1_000_000)) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(0, 1_000_000) to be %d, got %d`, expected, result) | ||
} | ||
|
||
expected = 2 | ||
result = pass.ComputeShards(0, float64(1_000_001)) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(0, 1_000_001) to be %d, got %d`, expected, result) | ||
} | ||
|
||
expected = 3 | ||
result = pass.ComputeShards(0, float64(2_000_001)) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(0, 2_000_001) to be %d, got %d`, expected, result) | ||
} | ||
} | ||
|
||
func TestShardComputationReturnsAtLeast1Shart(t *testing.T) { | ||
pass := ShardingStrategy{ScaleUpSeriesCount: float64(1_000_000), ScaleDownPercentage: float64(0.20)} | ||
|
||
expected := 1 | ||
result := pass.ComputeShards(0, 0) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(0, 0) to be %d, got %d`, expected, result) | ||
} | ||
|
||
expected = 1 | ||
result = pass.ComputeShards(0, -5) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(0, -5) to be %d, got %d`, expected, result) | ||
} | ||
} | ||
|
||
func TestShardComputationScaleDown(t *testing.T) { | ||
pass := ShardingStrategy{ScaleUpSeriesCount: float64(1_000_000), ScaleDownPercentage: float64(0.20)} | ||
expected := 2 | ||
result := pass.ComputeShards(1, 1_000_001) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(1, 1_000_001) to be %d, got %d`, expected, result) | ||
} | ||
|
||
expected = 2 | ||
result = pass.ComputeShards(2, 999_999) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(2, 999_999) to be %d, got %d`, expected, result) | ||
} | ||
|
||
expected = 2 | ||
result = pass.ComputeShards(2, 800_001) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(2, 800_001) to be %d, got %d`, expected, result) | ||
} | ||
|
||
// threshold hit | ||
expected = 1 | ||
result = pass.ComputeShards(2, 800_000) | ||
if result != expected { | ||
t.Errorf(`expected computeShards(2, 800_000) to be %d, got %d`, expected, result) | ||
} | ||
} |
Oops, something went wrong.