diff --git a/Makefile b/Makefile index 7aa7535..2915a45 100644 --- a/Makefile +++ b/Makefile @@ -57,13 +57,14 @@ app-via-docker-windows-amd64: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(MAKE) app-via-docker-windows-goarch victorialogs-backend-plugin-build: \ - victorialogs-backend-plugin-linux-amd64-prod \ - victorialogs-backend-plugin-linux-arm-prod \ - victorialogs-backend-plugin-linux-arm64-prod \ - victorialogs-backend-plugin-linux-386-prod \ - victorialogs-backend-plugin-amd64-prod \ - victorialogs-backend-plugin-arm64-prod \ - victorialogs-backend-plugin-windows-prod + victorialogs-backend-plugin-amd64-prod +# victorialogs-backend-plugin-linux-amd64-prod \ +# victorialogs-backend-plugin-linux-arm-prod \ +# victorialogs-backend-plugin-linux-arm64-prod \ +# victorialogs-backend-plugin-linux-386-prod \ + +# victorialogs-backend-plugin-arm64-prod \ +# victorialogs-backend-plugin-windows-prod victorialogs-frontend-plugin-build: \ frontend-build diff --git a/pkg/plugin/datasource.go b/pkg/plugin/datasource.go index cd25123..e39a76a 100644 --- a/pkg/plugin/datasource.go +++ b/pkg/plugin/datasource.go @@ -116,13 +116,34 @@ func (d *Datasource) query(ctx context.Context, _ backend.PluginContext, query b return newResponseError(err, backend.Status(resp.StatusCode)) } - // TODO implement correct response - var r interface{} - if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { - err = fmt.Errorf("failed to decode body response: %w", err) + dec := json.NewDecoder(resp.Body) + + t, err := dec.Token() + if err != nil { return newResponseError(err, backend.StatusInternal) } + if t != json.Delim('{') { + return newResponseError(fmt.Errorf("expected {, got %v", t), backend.StatusInternal) + } + + for dec.More() { + var r Response + err := dec.Decode(&r) + if err != nil { + return newResponseError(err, backend.StatusInternal) + } + + log.DefaultLogger.Info("RESPONSE => %#v", r) + } + + // var r Response + // if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { + // err = fmt.Errorf("failed to decode body response: %w", err) + // return newResponseError(err, backend.StatusInternal) + // } + + // log.DefaultLogger.Info("RESPONSE => %#v", r) // TODO convert response to the data Frames // frames, err := r.getDataFrames() // if err != nil { diff --git a/pkg/plugin/response.go b/pkg/plugin/response.go index d426286..9741331 100644 --- a/pkg/plugin/response.go +++ b/pkg/plugin/response.go @@ -12,6 +12,7 @@ type Data struct { // Response contains fields from query response type Response struct { - Status string `json:"status"` - Data Data `json:"data"` + Message string `json:"_msg"` + Stream string `json:"_stream"` + Time string `json:"_time"` }