Plugins: Add statusSource to partial data response error log (#78057)
* Plugins: Add statusSource to partial data response error log * Introduce DefaultStatusSource * Add StatusSourceFromPluginErrorSource * Moved StatusSourceFromPluginErrorSource * Update pkg/services/pluginsintegration/clientmiddleware/logger_middleware.go
This commit is contained in:
@@ -3,6 +3,8 @@ package pluginrequestmeta
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
)
|
||||
|
||||
// StatusSource is an enum-like string value representing the source of a
|
||||
@@ -14,16 +16,19 @@ const (
|
||||
StatusSourceDownstream StatusSource = "downstream"
|
||||
)
|
||||
|
||||
// DefaultStatusSource is the default StatusSource that should be used when it is not explicitly set by the plugin.
|
||||
const DefaultStatusSource StatusSource = StatusSourcePlugin
|
||||
|
||||
type statusSourceCtxKey struct{}
|
||||
|
||||
// StatusSourceFromContext returns the plugin request status source stored in the context.
|
||||
// If no plugin request status source is stored in the context, [StatusSourcePlugin] is returned.
|
||||
// If no plugin request status source is stored in the context, [DefaultStatusSource] is returned.
|
||||
func StatusSourceFromContext(ctx context.Context) StatusSource {
|
||||
value, ok := ctx.Value(statusSourceCtxKey{}).(*StatusSource)
|
||||
if ok {
|
||||
return *value
|
||||
}
|
||||
return StatusSourcePlugin
|
||||
return DefaultStatusSource
|
||||
}
|
||||
|
||||
// WithStatusSource sets the plugin request status source for the context.
|
||||
@@ -42,3 +47,13 @@ func WithDownstreamStatusSource(ctx context.Context) error {
|
||||
*v = StatusSourceDownstream
|
||||
return nil
|
||||
}
|
||||
|
||||
// StatusSourceFromPluginErrorSource takes an error source returned by a plugin and returns the corresponding
|
||||
// StatusSource. If the provided value is a zero-value (i.e.: the plugin did not set it), the function returns
|
||||
// DefaultStatusSource.
|
||||
func StatusSourceFromPluginErrorSource(pluginErrorSource backend.ErrorSource) StatusSource {
|
||||
if pluginErrorSource == "" {
|
||||
return DefaultStatusSource
|
||||
}
|
||||
return StatusSource(pluginErrorSource)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user