Skip to content

Commit

Permalink
Specify overwriting behavior in flag and add validation
Browse files Browse the repository at this point in the history
Signed-off-by: haanhvu <haanh6594@gmail.com>
  • Loading branch information
haanhvu committed Sep 25, 2022
1 parent 8067669 commit 38fccca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func (rc *receiveConfig) registerFlag(cmd extkingpin.FlagClause) {
cmd.Flag("receive.hashrings", "Alternative to 'receive.hashrings-file' flag (lower priority). Content of file that contains the hashring configuration.").PlaceHolder("<content>").StringVar(&rc.hashringsFileContent)

hashringAlgorithmsHelptext := strings.Join([]string{string(receive.AlgorithmHashmod), string(receive.AlgorithmKetama)}, ", ")
cmd.Flag("receive.hashrings-algorithm", "The algorithm used when distributing series in the hashrings. Must be one of "+hashringAlgorithmsHelptext).
cmd.Flag("receive.hashrings-algorithm", "The algorithm used when distributing series in the hashrings. Must be one of "+hashringAlgorithmsHelptext+". Will be overwritten by the algorithm in the hashring config.").
Default(string(receive.AlgorithmHashmod)).
EnumVar(&rc.hashringsAlgorithm, string(receive.AlgorithmHashmod), string(receive.AlgorithmKetama))

Expand Down
5 changes: 5 additions & 0 deletions pkg/receive/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package receive
import (
"context"
"fmt"
"log"
"sort"
"strconv"
"sync"
Expand Down Expand Up @@ -291,6 +292,10 @@ func HashringFromConfig(algorithm HashringAlgorithm, replicationFactor uint64, c
if len(config) == 0 {
return nil, errors.Wrapf(err, "failed to load configuration")
}

if (algorithm != "hashmod") && (algorithm != "ketama") {
log.Println("The specified algorithm is incorrect. Fall back to hashmod algorithm")
}

return newMultiHashring(algorithm, replicationFactor, config), err
}
Expand Down

0 comments on commit 38fccca

Please sign in to comment.