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

fix shards computation when there is no metrics yet #26

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Manage prometheus-agent configs

## [0.0.2] - 2024-04-08

### Fixed
Expand Down
15 changes: 11 additions & 4 deletions pkg/monitoring/mimir/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
"github.com/prometheus/common/model"
)

var (
ErrorNoTimeSeries = errors.New("no time series found")
ErrorFailedToConvertValueToVector = errors.New("failed to convert value to vector")
ErrorMoreThanOneTimeSeriesFound = errors.New("more than one time series found")
ErrorFailedToGetTimeSeries = errors.New("failed to get time series")
)

// QueryTSDBHeadSeries performs an instant query against Mimir.
func QueryTSDBHeadSeries(ctx context.Context, clusterName string) (float64, error) {
config := api.Config{
Expand Down Expand Up @@ -38,16 +45,16 @@ func QueryTSDBHeadSeries(ctx context.Context, clusterName string) (float64, erro
case model.ValVector:
vector, ok := val.(model.Vector)
if !ok {
return 0, errors.New("failed to convert value to vector")
return 0, ErrorFailedToConvertValueToVector
}
if len(vector) == 0 {
return 0, errors.New("no time series found")
return 0, ErrorNoTimeSeries
}
if len(vector) > 1 {
return 0, errors.New("more than one time series found")
return 0, ErrorMoreThanOneTimeSeriesFound
}
return float64(vector[0].Value), nil
default:
return 0, errors.New("failed to get current number of time series")
return 0, ErrorFailedToGetTimeSeries
}
}
5 changes: 3 additions & 2 deletions pkg/monitoring/prometheusagent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func getServicePriority(cluster *clusterv1.Cluster) string {
func getShardsCountForCluster(ctx context.Context, cluster *clusterv1.Cluster, currentShardCount int) (int, error) {
headSeries, err := querier.QueryTSDBHeadSeries(ctx, cluster.Name)
if err != nil {
// Verify that Prometheus is accessible. If not, return the default number of shards.
// If Prometheus is not accessible (DNSError), or if we don't have any data yet (ErrNoTimeSeries)
// Then, return the default number of shards.
var dnsError *net.DNSError
if errors.As(err, &dnsError) {
if errors.As(err, &dnsError) || errors.Is(err, querier.ErrorNoTimeSeries) {
return shards.ComputeShards(currentShardCount, defaultShards), nil
}
return 0, errors.WithStack(err)
Expand Down