* Backport PR for: Prometheus: Flavor/version configuration (#57554), and /label match parameter support #56510 * Revert "Revert "Prometheus: Type and flavor configuration (#56496)" (#57552)" This reverts commit2432ce619a. * Adds new fields and documentation for Prometheus datasource configuration: prometheus type, and version (cherry picked from commitf93c3acc51) * Revert "Revert "Prometheus: Provide label values match parameter API when supported prometheus instance is configured (#56510)" (#57551)" (#57553) (#57564) This reverts commite7671bf909. (cherry picked from commite59ddd6bc5) Co-authored-by: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> Co-authored-by: Grot (@grafanabot) <43478413+grafanabot@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
||||
@@ -19,6 +21,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus/buffered"
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus/querydata"
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus/resource"
|
||||
"github.com/patrickmn/go-cache"
|
||||
apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
|
||||
"github.com/yudai/gojsondiff"
|
||||
"github.com/yudai/gojsondiff/formatter"
|
||||
@@ -32,9 +35,10 @@ type Service struct {
|
||||
}
|
||||
|
||||
type instance struct {
|
||||
buffered *buffered.Buffered
|
||||
queryData *querydata.QueryData
|
||||
resource *resource.Resource
|
||||
buffered *buffered.Buffered
|
||||
queryData *querydata.QueryData
|
||||
resource *resource.Resource
|
||||
versionCache *cache.Cache
|
||||
}
|
||||
|
||||
func ProvideService(httpClientProvider httpclient.Provider, cfg *setting.Cfg, features featuremgmt.FeatureToggles, tracer tracing.Tracer) *Service {
|
||||
@@ -75,9 +79,10 @@ func newInstanceSettings(httpClientProvider httpclient.Provider, cfg *setting.Cf
|
||||
}
|
||||
|
||||
return instance{
|
||||
buffered: b,
|
||||
queryData: qd,
|
||||
resource: r,
|
||||
buffered: b,
|
||||
queryData: qd,
|
||||
resource: r,
|
||||
versionCache: cache.New(time.Minute*1, time.Minute*5),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -135,6 +140,20 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.EqualFold(req.Path, "version-detect") {
|
||||
versionObj, found := i.versionCache.Get("version")
|
||||
if found {
|
||||
return sender.Send(versionObj.(*backend.CallResourceResponse))
|
||||
}
|
||||
|
||||
vResp, err := i.resource.DetectVersion(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.versionCache.Set("version", vResp, cache.DefaultExpiration)
|
||||
return sender.Send(vResp)
|
||||
}
|
||||
|
||||
resp, err := i.resource.Execute(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -98,3 +98,23 @@ func (r *Resource) Execute(ctx context.Context, req *backend.CallResourceRequest
|
||||
|
||||
return callResponse, err
|
||||
}
|
||||
|
||||
func (r *Resource) DetectVersion(ctx context.Context, req *backend.CallResourceRequest) (*backend.CallResourceResponse, error) {
|
||||
newReq := &backend.CallResourceRequest{
|
||||
PluginContext: req.PluginContext,
|
||||
Path: "/api/v1/status/buildinfo",
|
||||
}
|
||||
|
||||
resp, err := r.Execute(ctx, newReq)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
callResponse := &backend.CallResourceResponse{
|
||||
Status: 200,
|
||||
Body: resp.Body,
|
||||
}
|
||||
|
||||
return callResponse, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user