Skip to content

Fix: Preserve Elasticsearch URL path in stats requests - #1123

Open
Robert-Steiner wants to merge 1 commit into
prometheus-community:masterfrom
Robert-Steiner:fix/all-path
Open

Fix: Preserve Elasticsearch URL path in stats requests#1123
Robert-Steiner wants to merge 1 commit into
prometheus-community:masterfrom
Robert-Steiner:fix/all-path

Conversation

@Robert-Steiner

@Robert-Steiner Robert-Steiner commented Jan 15, 2026

Copy link
Copy Markdown

Description

When the Elasticsearch URL contains a path (e.g., http://example.com/elasticsearch/), the path is incorrectly stripped when making _all/_stats requests, resulting in requests to http://example.com/_all/_stats instead of http://example.com/elasticsearch/_all/_stats.

The regression was introduced in v1.10.0 when the URL resolution logic was changed from using path.Join to url.ResolveReference.

package main

import (
    "fmt"
    "net/url"
)

func main() {
    base, _ := url.Parse("http://example.com/elasticsearch/")
    fmt.Println(base.ResolveReference(&url.URL{Path: "/_all/_stats"}))
    fmt.Println(base.ResolveReference(&url.URL{Path: "_all/_stats"}))
}

Output

http://example.com/_all/_stats
http://example.com/elasticsearch/_all/_stats

This PR fixes the URL path handling to ensure custom paths in the Elasticsearch URL are properly preserved when constructing API endpoint requests.

Signed-off-by: Robert Steiner <robert.steiner@noxtua.com>

@ArthurSens ArthurSens left a comment

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.

Hi @Robert-Steiner, sorry for the delay here. Looks like the PR needs a rebase now.

Also, could you add a test to prevent us from re-introducing this bug again in the future?

Comment thread collector/indices.go
var isr indexStatsResponse

u := i.url.ResolveReference(&url.URL{Path: "/_all/_stats"})
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.

Maybe we should be using i.url.JoinPath here?

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.

Based on my research, I think JoinPath should become our standard. It covers the prefix needs we have.

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.

3 participants