fix(observability-proxy): keep store error text out of lookup answers

A store error other than the series limit was built into the lookup's
502 message, and that text can name vmstorage nodes and addresses.
The handler happened to replace the message before it reached the
client, but nothing held it there. The text now goes to the log only.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-10 04:03:24 +07:00
1 parent 0bb98ced05
commit 41e61cb288
3 files changed
+21 -1

No files matched your search

+3 -1
View File
@@ -200,6 +200,8 @@ func lookupRefusal(label string, body io.Reader) *HTTPError {
case strings.Contains(answer.Error, "timeout exceeded"):
return errorf(http.StatusGatewayTimeout, "the application's %s lookup did not answer in time", label)
default:
return errorf(http.StatusBadGateway, "the application's %s lookup failed: %s", label, answer.Error)
// The text may name vmstorage nodes, so it stays in the log.
slog.Warn("application lookup refused by the store", "label", label, "error", answer.Error)
return errorf(http.StatusBadGateway, "the application's %s lookup failed", label)
}
}
@@ -17,10 +17,12 @@ limitations under the License.
package observabilityproxy
import (
"net/http"
"net/url"
"regexp"
"slices"
"strconv"
"strings"
"testing"
"time"
)
@@ -114,3 +116,14 @@ func TestMetricsRequestScope(t *testing.T) {
t.Errorf("range window = [%s, %s]", rng.from, rng.to)
}
}
// TestLookupRefusalKeepsStoreErrorsInternal: a store error other than the
// series limit may name vmstorage nodes; it goes to the log, not into a
// message that could reach the client.
func TestLookupRefusalKeepsStoreErrorsInternal(t *testing.T) {
body := strings.NewReader(`{"status":"error","error":"cannot fetch from vmstorage-longterm-0.vmstorage:8401: connection refused"}`)
herr := lookupRefusal("pod", body)
if herr.Code != http.StatusBadGateway || strings.Contains(herr.Message, "vmstorage") {
t.Fatalf("lookupRefusal = %d %q, want 502 without the store's text", herr.Code, herr.Message)
}
}
@@ -485,6 +485,11 @@ func TestServerApplicationLookupStoreErrors(t *testing.T) {
if strings.Contains(string(body), `"errorType"`) {
t.Errorf("the store's raw JSON reached the client: %q", body)
}
// Other store errors may name vmstorage nodes; only the limit
// message, which the client can act on, is passed on.
if tc.want != http.StatusUnprocessableEntity && strings.Contains(string(body), "vmstorage") {
t.Errorf("the store's error text reached the client: %q", body)
}
}
}