Skip to content

Commit

Permalink
Ignore prometheus-agent-config-if-mimir-enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson committed Apr 9, 2024
1 parent 49de7c2 commit 512fa75
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
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

- Remove prometheus remote write agent configuration when mimir is enabled.

## [4.72.0] - 2024-04-03

### Changed
Expand Down
4 changes: 2 additions & 2 deletions pkg/prometheusquerier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// QueryInstant performs an instant query against a Prometheus server.
func QueryTSDBHeadSeries(cluster string) (float64, error) {
func QueryTSDBHeadSeries(ctx context.Context, cluster string) (float64, error) {
config := api.Config{
Address: fmt.Sprintf("http://prometheus-operated.%s-prometheus.svc:9090/%s", cluster, cluster),
RoundTripper: http.DefaultTransport,
Expand All @@ -28,7 +28,7 @@ func QueryTSDBHeadSeries(cluster string) (float64, error) {
// Run query against client.
api := v1.NewAPI(c)

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
val, _, err := api.Query(ctx, "max_over_time(prometheus_tsdb_head_series[6h])", time.Now()) // Ignoring warnings for now.
cancel()
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions service/controller/clusterapi/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@ func New(config Config) ([]resource.Interface, error) {
return nil, microerror.Mask(err)
}
}

organizationReader := organization.NewNamespaceReader(config.K8sClient.K8sClient(), config.Installation, config.Provider)
// This resource creates a the prometheus agent remote write configuration.
// This is now managed by the observability-operator when mimir is enabled.
var remoteWriteConfigResource resource.Interface
{
if config.MimirEnabled {
remoteWriteConfigResource = noop.New(noop.Config{Logger: config.Logger})
} else {
c := remotewriteconfig.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand All @@ -203,8 +208,12 @@ func New(config Config) ([]resource.Interface, error) {
}
}

// This resource creates a the prometheus agent remote write secret.
// This is now managed by the observability-operator when mimir is enabled.
var remoteWriteSecretResource resource.Interface
{
if config.MimirEnabled {
remoteWriteSecretResource = noop.New(noop.Config{Logger: config.Logger})
} else {
c := remotewritesecret.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand Down
14 changes: 11 additions & 3 deletions service/controller/managementcluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
var err error

passwordManager := password.SimpleManager{}
organizationReader := organization.NewNamespaceReader(config.K8sClient.K8sClient(), config.Installation, config.Provider)

var namespaceResource resource.Interface
{
Expand Down Expand Up @@ -237,7 +238,6 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
}
}

organizationReader := organization.NewNamespaceReader(config.K8sClient.K8sClient(), config.Installation, config.Provider)
var scrapeConfigResource resource.Interface
{
c := scrapeconfigs.Config{
Expand Down Expand Up @@ -337,8 +337,12 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
}
}

// This resource creates a the prometheus agent remote write configuration.
// This is now managed by the observability-operator when mimir is enabled.
var remoteWriteConfigResource resource.Interface
{
if config.MimirEnabled {
remoteWriteConfigResource = noop.New(noop.Config{Logger: config.Logger})
} else {
c := remotewriteconfig.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand All @@ -358,8 +362,12 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
}
}

// This resource creates a the prometheus agent remote write secret.
// This is now managed by the observability-operator when mimir is enabled.
var remoteWriteSecretResource resource.Interface
{
if config.MimirEnabled {
remoteWriteSecretResource = noop.New(noop.Config{Logger: config.Logger})
} else {
c := remotewritesecret.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error {
// Get the current configmap if it exists.
current, err := r.k8sClient.K8sClient().CoreV1().ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
err = r.createConfigMap(ctx, cluster, name, namespace, r.version)
err = r.createConfigMap(ctx, cluster, name, namespace)
if err != nil {
return microerror.Mask(err)
}
Expand All @@ -48,7 +48,7 @@ func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error {
return microerror.Mask(err)
}

desired, err := r.desiredConfigMap(ctx, cluster, name, namespace, r.version, shards)
desired, err := r.desiredConfigMap(ctx, cluster, name, namespace, shards)
if err != nil {
return microerror.Mask(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *Resource) Name() string {
return Name
}

func (r *Resource) desiredConfigMap(ctx context.Context, cluster metav1.Object, name string, namespace string, version string, shards int) (*corev1.ConfigMap, error) {
func (r *Resource) desiredConfigMap(ctx context.Context, cluster metav1.Object, name string, namespace string, shards int) (*corev1.ConfigMap, error) {
organization, err := r.organizationReader.Read(ctx, cluster)
if err != nil {
return nil, microerror.Mask(err)
Expand Down Expand Up @@ -151,7 +151,7 @@ func (r *Resource) desiredConfigMap(ctx context.Context, cluster metav1.Object,

// We want to compute the number of shards based on the number of nodes.
func (r *Resource) getShardsCountForCluster(ctx context.Context, cluster metav1.Object, currentShardCount int) (int, error) {
headSeries, err := prometheusquerier.QueryTSDBHeadSeries(key.ClusterID(cluster))
headSeries, err := prometheusquerier.QueryTSDBHeadSeries(ctx, key.ClusterID(cluster))
if err != nil {
// If prometheus is not accessible (for instance, not running because this is a new cluster, we check if prometheus is accessible)
var dnsError *net.DNSError
Expand All @@ -164,13 +164,13 @@ func (r *Resource) getShardsCountForCluster(ctx context.Context, cluster metav1.
return computeShards(currentShardCount, headSeries), nil
}

func (r *Resource) createConfigMap(ctx context.Context, cluster metav1.Object, name string, namespace string, version string) error {
func (r *Resource) createConfigMap(ctx context.Context, cluster metav1.Object, name string, namespace string) error {
shards, err := r.getShardsCountForCluster(ctx, cluster, 1)
if err != nil {
return microerror.Mask(err)
}

configMap, err := r.desiredConfigMap(ctx, cluster, name, namespace, version, shards)
configMap, err := r.desiredConfigMap(ctx, cluster, name, namespace, shards)
if err != nil {
return microerror.Mask(err)
}
Expand Down

0 comments on commit 512fa75

Please sign in to comment.