Skip to content

Commit 9646a61

Browse files
committed
Add CallId to Scan Iterator
1 parent 0ca8f8c commit 9646a61

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

hub/hub.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,24 +648,23 @@ func (h *Hub) shouldPushdownLimit(table string, qualMap map[string]*proto.Quals,
648648

649649
// StartScan starts a scan (for scanIterators only = legacy iterators will have already started)
650650
func (h *Hub) StartScan(i Iterator) error {
651+
// iterator must be a scan iterator
651652
// if iterator is not a scan iterator, do nothing
652653
iterator, ok := i.(*scanIterator)
653654
if !ok {
654655
return nil
655656
}
656657

657-
// iterator must be a scan iterator
658658
// ensure we do not call execute too frequently
659659
h.throttle()
660660

661661
table := iterator.table
662662
connectionPlugin := iterator.connectionPlugin
663-
callId := grpc.BuildCallId()
664663

665664
req := &proto.ExecuteRequest{
666-
Table: table,
667-
QueryContext: iterator.queryContext,
668-
CallId: callId,
665+
Table: table,
666+
QueryContext: iterator.queryContext,
667+
CallId: iterator.callId,
669668
// pass connection name - used for aggregators
670669
Connection: iterator.ConnectionName(),
671670
TraceContext: grpc.CreateCarrierFromContext(iterator.traceCtx.Ctx),
@@ -684,7 +683,7 @@ func (h *Hub) StartScan(i Iterator) error {
684683
req.ExecuteConnectionData[connectionName] = data
685684
}
686685

687-
log.Printf("[INFO] StartScan for table: %s, callId %s, cache enabled: %v, iterator %p", table, callId, req.CacheEnabled, iterator)
686+
log.Printf("[INFO] StartScan for table: %s, cache enabled: %v, iterator %p, %d quals (%s)", table, req.CacheEnabled, iterator, len(iterator.queryContext.Quals), iterator.callId)
688687
stream, ctx, cancel, err := connectionPlugin.PluginClient.Execute(req)
689688
// format GRPC errors and ignore not implemented errors for backwards compatibility
690689
err = grpc.HandleGrpcError(err, connectionPlugin.PluginName, "Execute")
@@ -773,7 +772,7 @@ func (h *Hub) cacheTTL(connectionName string) time.Duration {
773772
// ask the steampipe config for resolved plugin options - this will use default values where needed
774773
connectionOptions := steampipeconfig.GlobalConfig.GetConnectionOptions(connectionName)
775774

776-
// the config loading code shouls ALWAYS populate the connection options, using defaults if needed
775+
// the config loading code should ALWAYS populate the connection options, using defaults if needed
777776
if connectionOptions.CacheTTL == nil {
778777
panic(fmt.Sprintf("No cache options found for connection %s", connectionName))
779778
}

hub/scan_iterator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc"
78
"log"
89
"time"
910

@@ -45,6 +46,7 @@ type scanIterator struct {
4546
queryContext *proto.QueryContext
4647

4748
startTime time.Time
49+
callId string
4850
}
4951

5052
func newScanIterator(hub *Hub, connectionPlugin *steampipeconfig.ConnectionPlugin, connectionName, table string, connectionLimitMap map[string]int64, qualMap map[string]*proto.Quals, columns []string, limit int64, traceCtx *telemetry.TraceCtx) *scanIterator {
@@ -60,6 +62,7 @@ func newScanIterator(hub *Hub, connectionPlugin *steampipeconfig.ConnectionPlugi
6062
traceCtx: traceCtx,
6163
startTime: time.Now(),
6264
queryContext: proto.NewQueryContext(columns, qualMap, limit),
65+
callId: grpc.BuildCallId(),
6366
}
6467
}
6568

@@ -269,7 +272,7 @@ func (i *scanIterator) readPluginResult(ctx context.Context) bool {
269272
continueReading = false
270273
case rowResult := <-rcvChan:
271274
if rowResult == nil {
272-
log.Printf("[TRACE] readPluginResult nil row received - stop reading (%p)", i)
275+
log.Printf("[TRACE] readPluginResult nil row received - stop reading (%p) (%s)", i, i.callId)
273276
// stop reading
274277
continueReading = false
275278
} else {
@@ -281,7 +284,7 @@ func (i *scanIterator) readPluginResult(ctx context.Context) bool {
281284
}
282285
case err := <-errChan:
283286
if err.Error() == "EOF" {
284-
log.Printf("[TRACE] readPluginResult EOF error received - stop reading (%p)", i)
287+
log.Printf("[TRACE] readPluginResult EOF error received - stop reading (%p) (%s)", i, i.callId)
285288
} else {
286289
log.Printf("[WARN] stream receive error %v (%p)\n", err, i)
287290
i.setError(err)

0 commit comments

Comments
 (0)