diff --git a/pkg/plugin/datasource.go b/pkg/plugin/datasource.go index 5012f67..0cdcc0b 100644 --- a/pkg/plugin/datasource.go +++ b/pkg/plugin/datasource.go @@ -216,7 +216,7 @@ func (d *Datasource) QueryAnnotations(ctx context.Context, req *backend.QueryDat span.AddEvent("Generated PI API URL for annotation query") - r, err := d.apiBatchRequest(ctx, batchReq) + r, err := apiBatchRequest(ctx, d, batchReq) if err != nil { return nil, fmt.Errorf("error getting data from PI Web API: %w", err) } @@ -280,7 +280,7 @@ func (d *Datasource) CallResource(ctx context.Context, req *backend.CallResource }) } - r, err := d.apiGet(ctx, req.URL) + r, err := apiGet(ctx, d, req.URL) if err != nil { return err } diff --git a/pkg/plugin/helpers.go b/pkg/plugin/helpers.go index c5b08df..916da1b 100644 --- a/pkg/plugin/helpers.go +++ b/pkg/plugin/helpers.go @@ -54,7 +54,7 @@ func replaceAccentsWithEscape(s string) string { // apiGet performs a GET request against the PI Web API. It returns the response body as a byte slice. // If the request fails, an error is returned. -func (d Datasource) apiGet(ctx context.Context, path string) ([]byte, error) { +func apiGet(ctx context.Context, d *Datasource, path string) ([]byte, error) { var uri = d.settings.URL var pathEscaped = replaceAccentsWithEscape(path) if strings.HasSuffix(uri, "/") { @@ -86,7 +86,7 @@ func (d Datasource) apiGet(ctx context.Context, path string) ([]byte, error) { // apiBatchRequest performs a batch request against the PI Web API. It returns the response body as a byte slice. // If the request fails, an error is returned. -func (d *Datasource) apiBatchRequest(ctx context.Context, BatchSubRequests interface{}) ([]byte, error) { +func apiBatchRequest(ctx context.Context, d *Datasource, BatchSubRequests interface{}) ([]byte, error) { var uri = d.settings.URL if strings.HasSuffix(uri, "/") { uri = uri + "batch" diff --git a/pkg/plugin/timeseries_query.go b/pkg/plugin/timeseries_query.go index d1559d2..fba4c6e 100644 --- a/pkg/plugin/timeseries_query.go +++ b/pkg/plugin/timeseries_query.go @@ -168,7 +168,7 @@ func (d *Datasource) batchRequest(ctx context.Context, PIWebAPIQueries map[strin } // request the data from the PI Web API - batchRequestResponse, err := d.apiBatchRequest(ctx, batchRequest) + batchRequestResponse, err := apiBatchRequest(ctx, d, batchRequest) // process response if err != nil { diff --git a/pkg/plugin/webidcache.go b/pkg/plugin/webidcache.go index 60a6905..9e100e0 100644 --- a/pkg/plugin/webidcache.go +++ b/pkg/plugin/webidcache.go @@ -173,62 +173,6 @@ func (d *Datasource) _saveWebID(data interface{}, path string, isPiPoint bool) s return entry.WebID } -// func (d *Datasource) getWebID(ctx context.Context, path string, isPiPoint bool) (WebIDCacheEntry, error) { -// entry, ok := d.webIDCache.webIDCache[path] - -// if ok && time.Now().Before(entry.ExpTime) { -// log.DefaultLogger.Debug("WebID cache hit", "path", path) -// d.webIDCache.webIDPaths[entry.WebID] = path -// return entry, nil -// } -// entry = WebIDCacheEntry{} -// c, err := d.requestWebID(ctx, path, isPiPoint) -// if err != nil { -// log.DefaultLogger.Error("WebID cache error", "path", path, "error", err) -// return entry, err -// } -// if c.WebID == "" { -// err = errors.New("WebID not found") -// log.DefaultLogger.Error("WebID cache error", "path", path, "error", err) -// return entry, err -// } -// d.webIDCache.webIDCache[path] = c -// d.webIDCache.webIDPaths[c.WebID] = path -// return c, nil -// } - -// func (d *Datasource) requestWebID(ctx context.Context, path string, isPiPoint bool) (WebIDCacheEntry, error) { -// uri := "" -// if isPiPoint { -// uri = `points?selectedFields=WebId;Name;Path;PointType;DigitalSetName;Descriptor;EngineeringUnits&path=\\` -// uri += strings.Replace(strings.Replace(path, "|", `\`, -1), ";", `\`, -1) -// } else { -// uri = `attributes?selectedFields=WebId;Name;Path;Type;DigitalSetName;Description;DefaultUnitsName&path=\\` -// uri += path -// } -// r, e := d.apiGet(ctx, uri) -// if e != nil { -// return WebIDCacheEntry{}, e -// } -// var response WebIDResponse -// if isPiPoint { -// response = &WebIDResponsePiPoint{} -// } else { -// response = &WebIDResponseAttribute{} -// } -// json.Unmarshal(r, &response) - -// return WebIDCacheEntry{ -// Path: path, -// WebID: response.getWebID(), -// Type: getValueType(response.getType()), -// DigitalState: response.getDigitalSetName() != "", -// ExpTime: time.Now().Add(d.webIDCache.duration), -// PointType: response.getType(), -// Units: response.getUnits(), -// }, nil -// } - func getValueType(Type string) reflect.Type { var dataType reflect.Type switch Type {