Skip to content

feat: add optional node label to elasticsearch_indices_aliases metric - #1157

Open
pincher95 wants to merge 2 commits into
prometheus-community:masterfrom
pincher95:feature/add-node-label-to-aliases
Open

feat: add optional node label to elasticsearch_indices_aliases metric#1157
pincher95 wants to merge 2 commits into
prometheus-community:masterfrom
pincher95:feature/add-node-label-to-aliases

Conversation

@pincher95

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in --es.aliases.node-labels flag that appends a node label to the
elasticsearch_indices_aliases metric, showing which nodes host shards for each
aliased index.

  • When disabled (default): metric keeps the original 3 labels {index, alias, cluster} — fully backward compatible
  • When enabled: emits one series per (index, alias, node) with 4 labels {index, alias, node, cluster}

Resolves #1156

Changes

collector/indices.go

  • Added indicesAliasesWithNode descriptor with 4 labels alongside the original 3-label indicesAliases
  • Added aliasNodeLabels and aliasesDesc fields to Indices struct; constructor selects descriptor based on flag
  • Added populateShardRouting() to fetch shard placement when --es.shards is off
  • Added collectAliasNodes() helper to extract sorted unique node IDs from shard data
  • Collect() branches on aliasNodeLabels: legacy path emits 3 labels, node-aware path emits per-node series

collector/indices_test.go

  • Existing test cases unchanged (verify backward-compatible 3-label output)
  • Added TestIndicesAliasNodeLabels validating node labels are populated from shard routing fixtures

main.go

  • Added --es.aliases.node-labels flag (default false)
  • Passed to NewIndices() in both single-target and /probe paths

README.md

  • Documented new flag in CLI table

Add an opt-in --es.aliases.node-labels flag that appends a node label
to the elasticsearch_indices_aliases metric, showing which nodes host
shards for each aliased index.

When disabled (default): metric keeps the original 3 labels
{index, alias, cluster} — fully backward compatible.

When enabled: emits one series per (index, alias, node) with 4 labels.
When --es.shards is disabled, an extra lightweight call to
/_all/_stats?level=shards&metric=docs fetches shard-to-node placement.

Signed-off-by: pincher95 <yuri.tsuprun@logz.io>
Comment thread collector/indices.go
}

func (i *Indices) populateShardRouting(ctx context.Context, isr *indexStatsResponse) error {
u := i.url.ResolveReference(&url.URL{Path: "/_all/_stats"})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This won't work for clusters that have a path prefix because the reference has a leading slash.

@sysadmind

Copy link
Copy Markdown
Contributor

Isn't this already possible by joining labels in Prometheus? There is already an elasticsearch_indices_aliases which would allow you to know which index an alias is associated with. And from that, you could know the node that an index is associated with right? I think this is already possible without adding more functionality.

Signed-off-by: Yuri Tsuprun <51751791+pincher95@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add optional node label to elasticsearch_indices_aliases metric

2 participants