Chore: Code cleaning with unit tests in promlib (#99542)

* update request tests

* remove unused functions

* add unit tests

* remove commented code

* fix unit tests
This commit is contained in:
ismail simsek
2025-01-31 10:39:08 +01:00
committed by GitHub
parent 3b231c433f
commit ec836f2760
6 changed files with 177 additions and 60 deletions
-17
View File
@@ -2,7 +2,6 @@ package promlib
import (
"context"
"errors"
"fmt"
"strings"
@@ -11,7 +10,6 @@ import (
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/grafana/grafana/pkg/promlib/client"
"github.com/grafana/grafana/pkg/promlib/instrumentation"
@@ -138,18 +136,3 @@ func (s *Service) getInstance(ctx context.Context, pluginCtx backend.PluginConte
in := i.(instance)
return &in, nil
}
// IsAPIError returns whether err is or wraps a Prometheus error.
func IsAPIError(err error) bool {
// Check if the right error type is in err's chain.
var e *apiv1.Error
return errors.As(err, &e)
}
func ConvertAPIError(err error) error {
var e *apiv1.Error
if errors.As(err, &e) {
return fmt.Errorf("%s: %s", e.Msg, e.Detail)
}
return err
}