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 Nov 29, 2024
1 parent 83bbc81 commit d82f44b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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

## 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

0 comments on commit d82f44b

Please sign in to comment.