Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include _ctx in columns when updating cache request #490

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugin/hydrate_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type HydrateCall struct {
Name string
}

func newHydrateCall(hydrateFunc HydrateFunc, config *HydrateConfig) *HydrateCall {
func newHydrateCall(config *HydrateConfig) *HydrateCall {
res := &HydrateCall{
Name: helpers.GetFunctionName(hydrateFunc),
Func: hydrateFunc,
Name: helpers.GetFunctionName(config.Func),
Func: config.Func,
Config: config,
}
for _, f := range config.Depends {
Expand Down
3 changes: 1 addition & 2 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/turbot/steampipe-plugin-sdk/v4/version"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"golang.org/x/exp/maps"
"golang.org/x/sync/semaphore"
"log"
"runtime/debug"
Expand Down Expand Up @@ -435,7 +434,7 @@ func (p *Plugin) executeForConnection(ctx context.Context, req *proto.ExecuteReq
log.Printf("[INFO] queryCacheGet returned CACHE MISS (%s)", connectionCallId)
// NOTE: update the cache request to include ALL the columns which will be fetched, not just those requested
// this means subsequent queries requesting other columns from same hydrate func(s) can be served from the cache
cacheRequest.Columns = maps.Keys(queryData.columns)
cacheRequest.Columns = queryData.getColumnNames()
p.queryCache.StartSet(ctx, cacheRequest)
} else {
log.Printf("[INFO] Cache DISABLED connectionCallId: %s", connectionCallId)
Expand Down
6 changes: 6 additions & 0 deletions plugin/query_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/turbot/steampipe-plugin-sdk/v4/error_helpers"
"golang.org/x/exp/maps"
"log"
"runtime/debug"
"sync"
Expand Down Expand Up @@ -741,3 +742,8 @@ func (d *QueryData) getCacheQualMap() map[string]*proto.Quals {
}
return res
}

// return the names of all columns that will be returned, adding in the _ctx column
func (d *QueryData) getColumnNames() []string {
return append(maps.Keys(d.columns), ContextColumnName)
}
2 changes: 1 addition & 1 deletion plugin/required_hydrate_calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c requiredHydrateCallBuilder) Add(hydrateFunc HydrateFunc) {
// get the config for this hydrate function
config := c.table.hydrateConfigMap[hydrateName]

c.requiredHydrateCalls[hydrateName] = newHydrateCall(hydrateFunc, config)
c.requiredHydrateCalls[hydrateName] = newHydrateCall(config)

// now add dependencies (we have already checked for circular dependencies so recursion is fine
for _, dep := range config.Depends {
Expand Down