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

Ignore prometheus-agent-config-if-mimir-enabled #1592

Merged
merged 4 commits into from
May 16, 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

- 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})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces the resources with a noop resource

} 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