Skip to content

Commit

Permalink
Ignore prometheus-agent-config-if-mimir-enabled (#1592)
Browse files Browse the repository at this point in the history
* Ignore prometheus-agent-config-if-mimir-enabled

Signed-off-by: QuentinBisson <[email protected]>

* Update querier.go

* fix build

---------

Signed-off-by: QuentinBisson <[email protected]>
  • Loading branch information
QuentinBisson authored May 16, 2024
1 parent 3bf3366 commit d89275c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 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.75.0] - 2024-05-13

### Added
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
22 changes: 17 additions & 5 deletions service/controller/clusterapi/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,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 @@ -208,8 +213,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 All @@ -226,8 +235,11 @@ func New(config Config) ([]resource.Interface, error) {
}
}

// This resource is not used in latest observability bundle versions.
var remoteWriteAPIEndpointConfigSecretResource resource.Interface
{
if config.MimirEnabled {
remoteWriteAPIEndpointConfigSecretResource = noop.New(noop.Config{Logger: config.Logger})
} else {
c := remotewriteapiendpointconfigsecret.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand Down Expand Up @@ -395,13 +407,13 @@ func New(config Config) ([]resource.Interface, error) {
rbacResource,
heartbeatWebhookConfigResource,
scrapeConfigResource,
alertmanagerWiringResource,
prometheusResource,
remoteWriteConfigResource,
remoteWriteSecretResource,
remoteWriteAPIEndpointConfigSecretResource,
remoteWriteIngressAuthResource,
remoteWriteIngressResource,
alertmanagerWiringResource,
prometheusResource,
verticalPodAutoScalerResource,
ingressResource,
heartbeatResource,
Expand Down
23 changes: 17 additions & 6 deletions service/controller/managementcluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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 @@ -242,7 +243,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 @@ -342,8 +342,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 @@ -365,8 +369,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 All @@ -383,8 +391,11 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
}
}

// This resource is not used in latest observability bundle versions.
var remoteWriteAPIEndpointConfigSecretResource resource.Interface
{
if config.MimirEnabled {
remoteWriteAPIEndpointConfigSecretResource = noop.New(noop.Config{Logger: config.Logger})
} else {
c := remotewriteapiendpointconfigsecret.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand Down Expand Up @@ -414,13 +425,13 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
ciliumnetpolResource,
heartbeatWebhookConfigResource,
alertmanagerWiringResource,
scrapeConfigResource,
prometheusResource,
remoteWriteConfigResource,
remoteWriteSecretResource,
remoteWriteAPIEndpointConfigSecretResource,
remoteWriteIngressAuthResource,
remoteWriteIngressResource,
scrapeConfigResource,
prometheusResource,
verticalPodAutoScalerResource,
monitoringIngressResource,
heartbeatResource,
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 @@ -43,12 +43,12 @@ func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error {
return microerror.Mask(err)
}

shards, err := r.getShardsCountForCluster(cluster, currentShards)
shards, err := r.getShardsCountForCluster(ctx, cluster, currentShards)
if err != nil {
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 @@ -103,7 +103,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 @@ -157,14 +157,14 @@ 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(cluster metav1.Object, currentShardCount int) (int, error) {
func (r *Resource) getShardsCountForCluster(ctx context.Context, cluster metav1.Object, currentShardCount int) (int, error) {
clusterShardingStrategy, err := key.GetClusterShardingStrategy(cluster)
if err != nil {
return 0, microerror.Mask(err)
}

shardingStrategy := r.shardingStrategy.Merge(clusterShardingStrategy)
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 @@ -177,13 +177,13 @@ func (r *Resource) getShardsCountForCluster(cluster metav1.Object, currentShardC
return shardingStrategy.ComputeShards(currentShardCount, headSeries), nil
}

func (r *Resource) createConfigMap(ctx context.Context, cluster metav1.Object, name string, namespace string, version string) error {
shards, err := r.getShardsCountForCluster(cluster, 1)
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 d89275c

Please sign in to comment.