Skip to content

Commit

Permalink
feat(deepql): add support for new deepql
Browse files Browse the repository at this point in the history
  • Loading branch information
Umaaz committed Apr 8, 2024
1 parent 1823861 commit 070a7ff
Show file tree
Hide file tree
Showing 3 changed files with 2,234 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/intergral/go-deep-proto/common/v1"
deepPoll "github.com/intergral/go-deep-proto/poll/v1"
deepTp "github.com/intergral/go-deep-proto/tracepoint/v1"
"github.com/intergral/grafana-deep-datasource/pkg/plugin/deeppb"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -231,7 +232,7 @@ func snapshotLocation(snapshot *SnapshotSearchMetadata) string {
return strings.TrimLeft(fmt.Sprintf("%s %s:%d", snapshot.ServiceName, snapshot.FilePath, snapshot.LineNo), " ")
}

func pollResponseToFrame(pollResponse *deepPoll.PollResponse, pluginContext backend.PluginContext) (*data.Frame, error) {
func pollResponseToFrame(pollResponse []*deepTp.TracePointConfig, pluginContext backend.PluginContext) (*data.Frame, error) {
frame := &data.Frame{
Name: "Tracepoint",
Fields: []*data.Field{
Expand Down Expand Up @@ -287,7 +288,7 @@ func pollResponseToFrame(pollResponse *deepPoll.PollResponse, pluginContext back
},
}

for _, tp := range pollResponse.Response {
for _, tp := range pollResponse {
tpArgs, _ := json.Marshal(tp.Args)
tpWatches, _ := json.Marshal(tp.Watches)
tpTargeting, _ := json.Marshal(keyValuesToMap(tp.Targeting))
Expand Down Expand Up @@ -530,12 +531,15 @@ func (d *DeepDatasource) queryDeepQl(ctx context.Context, pluginContext backend.
}
}
if responseType == "tracepoint" {
var pollResponse deepPoll.PollResponse
err := jsonpb.Unmarshal(response.Body, &pollResponse)
var pollResponse deeppb.DeepQlResponse
err = jsonpb.Unmarshal(response.Body, &pollResponse)
if err != nil {
return backend.ErrDataResponse(backend.StatusBadRequest, fmt.Sprintf("response failed: %v", err.Error()))
}
return d.processTracepointResponse(query, &pollResponse, pluginContext)
if pollResponse.Type == "list" {
return d.processTracepointResponse(query, pollResponse.Affected, pluginContext)
}
return d.processTracepointResponse(query, pollResponse.All, pluginContext)
}

return backend.DataResponse{
Expand Down Expand Up @@ -563,10 +567,10 @@ func (d *DeepDatasource) processProtoTracepointResponse(query backend.DataQuery,
return backend.ErrDataResponse(backend.StatusBadRequest, fmt.Sprintf("response failed: %v", err.Error()))
}

return d.processTracepointResponse(query, &pollResponse, pluginContext)
return d.processTracepointResponse(query, pollResponse.Response, pluginContext)
}

func (d *DeepDatasource) processTracepointResponse(query backend.DataQuery, pollResponse *deepPoll.PollResponse, pluginContext backend.PluginContext) backend.DataResponse {
func (d *DeepDatasource) processTracepointResponse(query backend.DataQuery, pollResponse []*deepTp.TracePointConfig, pluginContext backend.PluginContext) backend.DataResponse {
frame, err := pollResponseToFrame(pollResponse, pluginContext)
if err != nil {
return backend.ErrDataResponse(backend.StatusBadRequest, fmt.Sprintf("convertion failed: %v", err.Error()))
Expand Down
15 changes: 15 additions & 0 deletions pkg/plugin/deeppb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Proto definition

This package contains some definitions of proto compiled files. These files are not part of deep-proto (yet).

For now, we have simply copied the generated source
from [deep.pg.go](https://github.com/intergral/deep/blob/master/pkg/deeppb/deep.pb.go)

if updating the source - copy the full source from deep then update the imports for tracepoing and poll to use the real version.

e.g.

```go
v11 "github.com/intergral/go-deep-proto/poll/v1"
v1 "github.com/intergral/go-deep-proto/tracepoint/v1"
```
Loading

0 comments on commit 070a7ff

Please sign in to comment.