Skip to content

Commit

Permalink
prometheus.operator.*: allow setting informer_sync_timeout (#2161)
Browse files Browse the repository at this point in the history
* prometheus.operator.*: allow setting informer_sync_timeout

* default to 1m

* docs
  • Loading branch information
captncraig authored and ptodev committed Dec 3, 2024
1 parent 90a185d commit c68be7b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ v1.5.1

- Logs from underlying clustering library `memberlist` are now surfaced with correct level (@thampiotr)

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

### Bugfixes

- Fixed issue with reloading configuration and prometheus metrics duplication in `prometheus.write.queue`. (@mattdurham)
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

## 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 @@ -36,6 +36,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 ServiceMonitor resources. If not specified, all namespaces will be searched. || no
`informer_sync_timeout` | `duration` | Timeout for initial sync of ServiceMonitor resources. | `1m` | no

## Blocks

Expand Down
7 changes: 3 additions & 4 deletions internal/component/prometheus/operator/common/crdmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"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 @@ -37,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 @@ -332,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
3 changes: 3 additions & 0 deletions internal/component/prometheus/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 @@ -54,6 +56,7 @@ var DefaultArguments = Arguments{
Client: kubernetes.ClientArguments{
HTTPClientConfig: config.DefaultHTTPClientConfig,
},
InformerSyncTimeout: time.Minute,
}

// SetToDefault implements syntax.Defaulter.
Expand Down

0 comments on commit c68be7b

Please sign in to comment.