Skip to content

Commit

Permalink
fix: remove unnecessary assertion to any (#1333)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

- in #1329 , we introduced the assertion to `any` as the intermediate
step to check whether a Sampler is a ClusterSizer.
- It turns out that this intermediate step is unnecessary.

## Short description of the changes

- remove assertion to `any` in `SetClusterSize`
  • Loading branch information
VinozzZ authored and TylerHelmuth committed Oct 16, 2024
1 parent f6589e1 commit 19d24ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions sample/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ func (s *RulesBasedSampler) Start() error {

func (s *RulesBasedSampler) SetClusterSize(size int) {
for _, sampler := range s.samplers {
// Sampler does not implement ClusterSizer.
// By asserting Sampler to an empty interface, we will have access to the underlying pointer.
// We can then assert that pointer to the ClusterSizer.
if sampler, ok := sampler.(any).(ClusterSizer); ok {
if sampler, ok := sampler.(ClusterSizer); ok {
sampler.SetClusterSize(size)
}
}
Expand Down
8 changes: 4 additions & 4 deletions sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (s *SamplerFactory) updatePeerCounts() {

// all the samplers who want it should use the stored count
for _, sampler := range s.samplers {
// Sampler does not implement ClusterSizer.
// By asserting Sampler to an empty interface, we will have access to the underlying pointer.
// We can then assert that pointer to the ClusterSizer.
if clusterSizer, ok := sampler.(any).(ClusterSizer); ok {
if clusterSizer, ok := sampler.(ClusterSizer); ok {
s.Logger.Warn().Logf("set cluster size to %d", s.peerCount)
clusterSizer.SetClusterSize(s.peerCount)
} else {
s.Logger.Warn().Logf("sampler does not implement ClusterSizer")
}
}
}
Expand Down

0 comments on commit 19d24ee

Please sign in to comment.