diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d1d7b46..aad5cba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/monitoring/mimir/querier/querier.go b/pkg/monitoring/mimir/querier/querier.go index 276279af..4a40215a 100644 --- a/pkg/monitoring/mimir/querier/querier.go +++ b/pkg/monitoring/mimir/querier/querier.go @@ -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{ @@ -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 } } diff --git a/pkg/monitoring/prometheusagent/config.go b/pkg/monitoring/prometheusagent/config.go index d6890521..0ce7100a 100644 --- a/pkg/monitoring/prometheusagent/config.go +++ b/pkg/monitoring/prometheusagent/config.go @@ -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)