Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sharding strategy support #20

Merged
merged 9 commits into from
Jun 25, 2024
Merged

Conversation

QuentinBisson
Copy link
Contributor

What this PR does / why we need it

This PR adds the code that was added to PMO towards this issue https://github.com/giantswarm/giantswarm/issues/30673 to be able to configure the sharding strategy for some installations or some clusters only

Checklist

  • Update changelog in CHANGELOG.md.

@QuentinBisson QuentinBisson self-assigned this May 13, 2024
@QuentinBisson QuentinBisson requested a review from a team as a code owner May 13, 2024 12:18
@QuentinBisson QuentinBisson force-pushed the add-sharding-strategy-support branch 2 times, most recently from 659b618 to a9ada66 Compare May 13, 2024 12:41
@QuentinBisson QuentinBisson force-pushed the add-sharding-strategy-support branch 2 times, most recently from 0d9c03a to 26e1691 Compare May 29, 2024 09:24
@QuentinBisson
Copy link
Contributor Author

@giantswarm/team-atlas I'd love some eyes ;)

Copy link
Member

@TheoBrigitte TheoBrigitte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the comments

docs/monitoring/README.md Outdated Show resolved Hide resolved
docs/monitoring/sharding.md Outdated Show resolved Hide resolved
docs/monitoring/sharding.md Outdated Show resolved Hide resolved
docs/monitoring/sharding.md Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
ScaleDownPercentage float64
}

func (pass1 ShardingStrategy) Merge(pass2 *ShardingStrategy) ShardingStrategy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a pointer here and just modify the current object instead of returning a new one.

Suggested change
func (pass1 ShardingStrategy) Merge(pass2 *ShardingStrategy) ShardingStrategy {
func (s *ShardingStrategy) Merge(newShardingStrategy *ShardingStrategy) {

Copy link
Contributor Author

@QuentinBisson QuentinBisson Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer immutability because I do not want to change the origin object. I suppose it would be fine as I construct a new strategy from the monitoring config but if we create the sharding strategy as a member of the config then we should not use a pointer.

Also, I'm not sure creating a few objects once every 12 h is really a concern :D

Copy link
Member

@TheoBrigitte TheoBrigitte Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a concerns in terms of performance, just trying to simplify the code for the readers.

Comment on lines 13 to 16
strategy := ShardingStrategy{
pass1.ScaleUpSeriesCount,
pass1.ScaleDownPercentage,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
strategy := ShardingStrategy{
pass1.ScaleUpSeriesCount,
pass1.ScaleDownPercentage,
}

Comment on lines 17 to 25
if pass2 != nil {
if pass2.ScaleUpSeriesCount > 0 {
strategy.ScaleUpSeriesCount = pass2.ScaleUpSeriesCount
}
if pass2.ScaleDownPercentage > 0 {
strategy.ScaleDownPercentage = pass2.ScaleDownPercentage
}
}
return strategy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if pass2 != nil {
if pass2.ScaleUpSeriesCount > 0 {
strategy.ScaleUpSeriesCount = pass2.ScaleUpSeriesCount
}
if pass2.ScaleDownPercentage > 0 {
strategy.ScaleDownPercentage = pass2.ScaleDownPercentage
}
}
return strategy
if newShardingStrategy != nil {
if newShardingStrategy.ScaleUpSeriesCount > 0 {
s.ScaleUpSeriesCount = newShardingStrategy.ScaleUpSeriesCount
}
if newShardingStrategy.ScaleDownPercentage > 0 {
s.ScaleDownPercentage = newShardingStrategy.ScaleDownPercentage
}
}

Comment on lines 104 to 107
shardingStrategy := sharding.ShardingStrategy{
ScaleUpSeriesCount: pas.MonitoringConfig.ShardingScaleUpSeriesCount,
ScaleDownPercentage: pas.MonitoringConfig.ShardingScaleDownPercentage,
}.Merge(clusterShardingStrategy)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shardingStrategy := sharding.ShardingStrategy{
ScaleUpSeriesCount: pas.MonitoringConfig.ShardingScaleUpSeriesCount,
ScaleDownPercentage: pas.MonitoringConfig.ShardingScaleDownPercentage,
}.Merge(clusterShardingStrategy)
shardingStrategy := pas.MonitoringConfig
shardingStrategy.Merge(clusterShardingStrategy)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MonitoringConfig is a struct. Merge will not work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could however create a shardingstrategy in the config instead

pkg/monitoring/prometheusagent/sharding/sharding.go Outdated Show resolved Hide resolved
@QuentinBisson QuentinBisson force-pushed the add-sharding-strategy-support branch from efa2965 to 6ac51b6 Compare June 10, 2024 10:04
@QuentinBisson
Copy link
Contributor Author

@TheoBrigitte could you take another look? I think I addressed all your concerns :)

@QuentinBisson QuentinBisson force-pushed the add-sharding-strategy-support branch 2 times, most recently from 959f2e0 to 6d92c26 Compare June 18, 2024 12:16
)

func TestShardComputationScaleUp(t *testing.T) {
pass := Strategy{ScaleUpSeriesCount: float64(1_000_000), ScaleDownPercentage: float64(0.20)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test coverage, but for multiple test cases we usually wrap test cases into a slice and iterate over via t.Run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pair on this on thursday ? I quite like having functions as the name make for a nice description but i'm eager to learn how to bé more idiomatic :)

@QuentinBisson QuentinBisson force-pushed the add-sharding-strategy-support branch from 6d92c26 to eeea937 Compare June 22, 2024 12:42
},
}

func TestShardComputationLogic(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheoBrigitte let me know what you think now

@QuentinBisson QuentinBisson force-pushed the add-sharding-strategy-support branch from 051a347 to f61bb41 Compare June 22, 2024 13:12
@QuentinBisson QuentinBisson merged commit d3491bd into main Jun 25, 2024
7 checks passed
@QuentinBisson QuentinBisson deleted the add-sharding-strategy-support branch June 25, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants