Data source plugin: Improve error message when plugin has connection issues (#102625)

* Improve data source error message when stackID

* Update comment

* Revert "Update comment"

This reverts commit 48922bc552.

* Revert "Improve data source error message when stackID"

This reverts commit 4bf0a2f7b7.

* Make public messagic configurable based on context

* Update, simplify

* Update

* Update getting stack

* Update pkg/plugins/errors.go

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>

* Refactor test to test for when context has stack value

* Remove duplicated test

* Fix error checking logic

---------

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
This commit is contained in:
Ivana Huckova
2025-03-31 12:00:40 +02:00
committed by GitHub
co-authored by Andres Martinez Gotor
parent ffb6fb59a3
commit 54a51bd3e3
5 changed files with 83 additions and 10 deletions
+16 -6
View File
@@ -1,6 +1,12 @@
package plugins
import "github.com/grafana/grafana/pkg/apimachinery/errutil"
import (
"context"
"github.com/grafana/authlib/types"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
"github.com/grafana/grafana/pkg/apimachinery/identity"
)
var (
errPluginNotRegisteredBase = errutil.NotFound("plugin.notRegistered",
@@ -42,9 +48,13 @@ var (
errutil.WithPublicMessage("The response is too large. Please try to reduce the time range or narrow down your query to return fewer data points."),
errutil.WithDownstream())
// ErrPluginGrpcConnectionUnavailableBase error returned when a plugin connection issue occurs.
// Exposed as a base error to wrap it with plugin connection issue errors.
ErrPluginGrpcConnectionUnavailableBase = errutil.Internal("plugin.connectionUnavailable",
errutil.WithPublicMessage("Data source became unavailable during request. Please try again."),
errutil.WithDownstream())
ErrPluginGrpcConnectionUnavailableBaseFn = func(ctx context.Context) errutil.Base {
pubMsg := "Data source became unavailable during request. Please try again."
if requester, err := identity.GetRequester(ctx); err == nil && requester != nil {
if namespace, err := types.ParseNamespace(requester.GetNamespace()); err == nil && namespace.StackID != 0 {
pubMsg += " If the problem persists, please contact customer support."
}
}
return errutil.Internal("plugin.connectionUnavailable", errutil.WithPublicMessage(pubMsg))
}
)