fix(plugins): report metrics for all plugin types, not only MetadataAgents (#4303)
- Add ErrNotImplemented error to plugins/api package with proper documentation - Refactor callMethod in wasm_base_plugin to use api.ErrNotImplemented - Improve metrics recording logic to exclude not-implemented methods - Add better tracing and context handling for plugin calls - Reorganize error definitions with clear documentation
This commit is contained in:
@@ -3,6 +3,10 @@ package api
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNotFound = errors.New("plugin:not_found")
|
// ErrNotImplemented indicates that the plugin does not implement the requested method.
|
||||||
|
// No logic should be executed by the plugin.
|
||||||
ErrNotImplemented = errors.New("plugin:not_implemented")
|
ErrNotImplemented = errors.New("plugin:not_implemented")
|
||||||
|
|
||||||
|
// ErrNotFound indicates that the requested resource was not found by the plugin.
|
||||||
|
ErrNotFound = errors.New("plugin:not_found")
|
||||||
)
|
)
|
||||||
|
|||||||
+13
-14
@@ -6,10 +6,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/core/agents"
|
|
||||||
"github.com/navidrome/navidrome/core/metrics"
|
"github.com/navidrome/navidrome/core/metrics"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model/id"
|
"github.com/navidrome/navidrome/model/id"
|
||||||
|
"github.com/navidrome/navidrome/plugins/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newWasmBasePlugin creates a new instance of wasmBasePlugin with the required parameters.
|
// newWasmBasePlugin creates a new instance of wasmBasePlugin with the required parameters.
|
||||||
@@ -101,19 +101,18 @@ func callMethod[S any, R any](ctx context.Context, w wasmPlugin[S], methodName s
|
|||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
if em, ok := any(w).(errorMapper); ok {
|
if em, ok := any(w).(errorMapper); ok {
|
||||||
mappedErr := em.mapError(err)
|
err = em.mapError(err)
|
||||||
|
|
||||||
if !errors.Is(mappedErr, agents.ErrNotFound) {
|
|
||||||
id := w.PluginID()
|
|
||||||
isOk := mappedErr == nil
|
|
||||||
metrics := w.getMetrics()
|
|
||||||
if metrics != nil {
|
|
||||||
metrics.RecordPluginRequest(ctx, id, methodName, isOk, elapsed.Milliseconds())
|
|
||||||
}
|
|
||||||
log.Trace(ctx, "callMethod", "plugin", id, "method", methodName, "ok", isOk, elapsed)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r, mappedErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !errors.Is(err, api.ErrNotImplemented) {
|
||||||
|
id := w.PluginID()
|
||||||
|
isOk := err == nil
|
||||||
|
metrics := w.getMetrics()
|
||||||
|
if metrics != nil {
|
||||||
|
metrics.RecordPluginRequest(ctx, id, methodName, isOk, elapsed.Milliseconds())
|
||||||
|
log.Trace(ctx, "callMethod: sending metrics", "plugin", id, "method", methodName, "ok", isOk, elapsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user