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

Kube annotations scrape fixes #28

Merged
merged 5 commits into from
Aug 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
28 changes: 14 additions & 14 deletions modules/kubernetes/annotations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ Handles discovery of kubernetes targets and exports them, this component does no
| `label_selectors` | _no_ | `[]` | The [label selectors](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) to use to find matching targets |
| `annotation` | _no_ | `metrics.grafana.com` | The domain to use when looking for annotations, Kubernetes selectors do not support a logical `OR`, if multiple types of annotations are needed, this module should be invoked multiple times. |
| `tenant` | _no_ | `.*` | The tenant to write metrics to. This does not have to be the tenantId, this is the value to look for in the `{{argument.annotation.value}}/tenant` annotation i.e. (`metrics.grafana.com/tenant`), and this can be a regular expression. It is recommended to use a default i.e. `primary\|`, which would match the primary tenant or an empty string meaning the tenant is not set. |
| `scrape_interval` | _no_ | `60s` | How often to scrape metrics from the targets |
| `scrape_timeout` | _no_ | `10s` | How long before a scrape times out |
| `blackbox_url` | _no_ | `""` | The address of the blackbox exporter to use (without the protocol), only the hostname and port i.e. `blackbox-prometheus-blackbox-exporter.default.svc.cluster.local:9115` |

#### Exports
Expand All @@ -263,16 +265,14 @@ The following labels are automatically added to exported targets.

#### Arguments

| Name | Required | Default | Description |
| :---------------- | :------- | :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
| `targets` | _yes_ | `list(map(string))` | List of targets to scrape |
| `forward_to` | _yes_ | `list(MetricsReceiver)` | Must be a where scraped should be forwarded to |
| `keep_metrics` | _no_ | [see code](module.alloy#L228) | A regular expression of metrics to keep |
| `drop_metrics` | _no_ | [see code](module.alloy#L235) | A regular expression of metrics to drop |
| `scrape_interval` | _no_ | `60s` | How often to scrape metrics from the targets |
| `scrape_timeout` | _no_ | `10s` | How long before a scrape times out |
| `max_cache_size` | _no_ | `100000` | The maximum number of elements to hold in the relabeling cache. This should be at least 2x-5x your largest scrape target or samples appended rate. |
| `clustering` | _no_ | `false` | Whether or not [clustering](https://grafana.com/docs/agent/latest/flow/concepts/clustering/) should be enabled |
| Name | Required | Default | Description |
| :--------------- | :------- | :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
| `targets` | _yes_ | `list(map(string))` | List of targets to scrape |
| `forward_to` | _yes_ | `list(MetricsReceiver)` | Must be a where scraped should be forwarded to |
| `keep_metrics` | _no_ | [see code](module.alloy#L228) | A regular expression of metrics to keep |
| `drop_metrics` | _no_ | [see code](module.alloy#L235) | A regular expression of metrics to drop |
| `max_cache_size` | _no_ | `100000` | The maximum number of elements to hold in the relabeling cache. This should be at least 2x-5x your largest scrape target or samples appended rate. |
| `clustering` | _no_ | `false` | Whether or not [clustering](https://grafana.com/docs/agent/latest/flow/concepts/clustering/) should be enabled |

#### Labels

Expand All @@ -288,7 +288,7 @@ The following example will scrape all metric annotation instances in cluster.

```alloy
import.git "metric_annotations" {
repository = "https://github.com/grafana/flow-modules.git"
repository = "https://github.com/grafana/alloy-modules.git"
revision = "main"
path = "modules/kubernetes/annotations/metrics.alloy"
pull_frequency = "15m"
Expand All @@ -300,7 +300,7 @@ metric_annotations.kubernetes "targets" {
}

// scrape the annotations
metric_annotations.scrape "metrics" {
metric_annotations.metrics "scrape" {
targets = metric_annotations.kubernetes.targets.output
forward_to = [
prometheus.remote_write.default.receiver,
Expand All @@ -326,7 +326,7 @@ The following example will scrape all probe annotation instances in cluster.

```alloy
import.git "probe_annotations" {
repository = "https://github.com/grafana/flow-modules.git"
repository = "https://github.com/grafana/alloy-modules.git"
revision = "main"
path = "modules/kubernetes/annotations/probes.alloy"
pull_frequency = "15m"
Expand All @@ -338,7 +338,7 @@ probe_annotations.kubernetes "targets" {
}

// scrape the annotations
probe_annotations.scrape "probes" {
probe_annotations.probe "scrape" {
targets = probe_annotations.kubernetes.targets.output
forward_to = [
prometheus.remote_write.default.receiver,
Expand Down
24 changes: 10 additions & 14 deletions modules/kubernetes/annotations/metrics.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ declare "kubernetes" {
default = false
}

argument "scrape_interval" {
comment = "How often to scrape metrics from the targets (default: 60s)"
optional = true
}

argument "scrape_timeout" {
comment = "How long before a scrape times out (default: 10s)"
optional = true
}

/*
Hidden Arguments
These arguments are used to set reusable variables to avoid repeating logic
Expand Down Expand Up @@ -503,16 +513,6 @@ declare "metrics" {
optional = true
}

argument "scrape_interval" {
comment = "How often to scrape metrics from the targets (default: 60s)"
optional = true
}

argument "scrape_timeout" {
comment = "How long before a scrape times out (default: 10s)"
optional = true
}

argument "max_cache_size" {
comment = "The maximum number of elements to hold in the relabeling cache (default: 100000). This should be at least 2x-5x your largest scrape target or samples appended rate."
optional = true
Expand Down Expand Up @@ -541,8 +541,6 @@ declare "metrics" {
forward_to = [prometheus.relabel.annotations.receiver]
targets = discovery.relabel.http_annotations.output
scheme = "http"
scrape_interval = coalesce(argument.scrape_interval.value, "60s")
scrape_timeout = coalesce(argument.scrape_timeout.value, "10s")

clustering {
enabled = coalesce(argument.clustering.value, false)
Expand All @@ -566,8 +564,6 @@ declare "metrics" {
forward_to = [prometheus.relabel.annotations.receiver]
targets = discovery.relabel.https_annotations.output
scheme = "https"
scrape_interval = coalesce(argument.scrape_interval.value, "60s")
scrape_timeout = coalesce(argument.scrape_timeout.value, "10s")
bearer_token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"

tls_config {
Expand Down
Loading