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

prometheus.operator.*: allow setting informer_sync_timeout #2161

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ v1.5.0

- Add `proxy_url` to `otelcol.exporter.otlphttp`. (@wildum)

- Allow setting `informer_sync_timeout` in prometheus.operator.* components. (@captncraig)

### Bugfixes

- Fixed a bug in `import.git` which caused a `"non-fast-forward update"` error message. (@ptodev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Name | Type | Description | Default | Required
---- | ---- | ----------- | ------- | --------
`forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes
`namespaces` | `list(string)` | List of namespaces to search for PodMonitor resources. If not specified, all namespaces will be searched. || no
`informer_sync_timeout` | `duration` | Timeout for initial sync of PodMonitor resources. | `1m` | no
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's for the initial sync, should it be called initial_sync_timeout? Is "informer" a k8s term?


## Blocks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Name | Type | Description | Default | Required
---- | ---- | ----------- | ------- | --------
`forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes
`namespaces` | `list(string)` | List of namespaces to search for Probe resources. If not specified, all namespaces will be searched. || no
`informer_sync_timeout` | `duration` | Timeout for initial sync of Probe resources. | `1m` | no

## Blocks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Name | Type | Description
`forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes
`namespaces` | `list(string)` | List of namespaces to search for ServiceMonitor resources. If not specified, all namespaces will be searched. | | no
`kubernetes_role` | `string` | The Kubernetes role used for discovery. Supports `endpoints` or `endpointslice`. | `endpoints` | no
`informer_sync_timeout` | `duration` | Timeout for initial sync of ServiceMonitor resources. | `1m` | no

## Blocks

Expand Down
8 changes: 3 additions & 5 deletions internal/component/prometheus/operator/common/crdmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"errors"
"fmt"
promk8s "github.com/prometheus/prometheus/discovery/kubernetes"
"sort"
"strings"
"sync"
"time"

promk8s "github.com/prometheus/prometheus/discovery/kubernetes"

"github.com/go-kit/log"
"github.com/grafana/ckit/shard"
promopv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
Expand Down Expand Up @@ -38,9 +39,6 @@ import (
"github.com/grafana/alloy/internal/util"
)

// Generous timeout period for configuring all informers
const informerSyncTimeout = 10 * time.Second

type crdManagerInterface interface {
Run(ctx context.Context) error
ClusteringUpdated()
Expand Down Expand Up @@ -333,7 +331,7 @@ func (c *crdManager) configureInformers(ctx context.Context, informers cache.Inf
return fmt.Errorf("unknown kind to configure Informers: %s", c.kind)
}

informerCtx, cancel := context.WithTimeout(ctx, informerSyncTimeout)
informerCtx, cancel := context.WithTimeout(ctx, c.args.InformerSyncTimeout)
defer cancel()

informer, err := informers.GetInformer(informerCtx, prototype)
Expand Down
8 changes: 6 additions & 2 deletions internal/component/prometheus/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package operator

import (
"fmt"
promk8s "github.com/prometheus/prometheus/discovery/kubernetes"
"time"

promk8s "github.com/prometheus/prometheus/discovery/kubernetes"

"github.com/grafana/alloy/internal/component/common/config"
"github.com/grafana/alloy/internal/component/common/kubernetes"
alloy_relabel "github.com/grafana/alloy/internal/component/common/relabel"
Expand Down Expand Up @@ -36,6 +37,8 @@ type Arguments struct {
RelabelConfigs []*alloy_relabel.Config `alloy:"rule,block,optional"`

Scrape ScrapeOptions `alloy:"scrape,block,optional"`

InformerSyncTimeout time.Duration `alloy:"informer_sync_timeout,attr,optional"`
}

// ScrapeOptions holds values that configure scraping behavior.
Expand All @@ -58,7 +61,8 @@ var DefaultArguments = Arguments{
Client: kubernetes.ClientArguments{
HTTPClientConfig: config.DefaultHTTPClientConfig,
},
KubernetesRole: string(promk8s.RoleEndpoint),
KubernetesRole: string(promk8s.RoleEndpoint),
InformerSyncTimeout: time.Minute,
}

// SetToDefault implements syntax.Defaulter.
Expand Down
Loading