Skip to content

Commit c4abb33

Browse files
authored
Add support for Open Telemetry. Closes #195 (#196)
1 parent ece4f47 commit c4abb33

File tree

9 files changed

+649
-220
lines changed

9 files changed

+649
-220
lines changed

fdw.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ func init() {
3535
if logger != nil {
3636
return
3737
}
38-
log.Printf("[INFO] \n******************************************************\n\n\t\tsteampipe postgres fdw init\n\n******************************************************\n")
3938

4039
// HACK: env vars do not all get copied into the Go env vars so explicitly copy them
4140
SetEnvVars()
4241

4342
level := logging.LogLevel()
44-
log.Printf("[INFO] Version v%s\n", version.FdwVersion.String())
4543
log.Printf("[INFO] Log level %s\n", level)
4644
if level != "TRACE" {
4745
// suppress logs
@@ -55,6 +53,10 @@ func init() {
5553
log.SetOutput(logger.StandardWriter(&hclog.StandardLoggerOptions{InferLevels: true}))
5654
log.SetPrefix("")
5755
log.SetFlags(0)
56+
log.Printf("[INFO] .\n******************************************************\n\n\t\tsteampipe postgres fdw init\n\n******************************************************\n")
57+
log.Printf("[INFO] Version: v%s\n", version.FdwVersion.String())
58+
log.Printf("[INFO] Log level: %s\n", level)
59+
5860
}
5961

6062
//export goFdwGetRelSize
@@ -111,8 +113,7 @@ func goFdwGetPathKeys(state *C.FdwPlanState) *C.List {
111113
opts["connection"] = getNamespace(rel)
112114

113115
if opts["connection"] == constants.CommandSchema {
114-
FdwError(fmt.Errorf("cannot select from command schema"))
115-
return nil
116+
return result
116117
}
117118

118119
// ask the hub for path keys - it will use the table schema to create path keys for all key columns
@@ -246,7 +247,9 @@ func goFdwIterateForeignScan(node *C.ForeignScanState) *C.TupleTableSlot {
246247

247248
if len(row) == 0 {
248249
log.Printf("[TRACE] goFdwIterateForeignScan returned empty row - this scan complete (%p)", s.Iter)
249-
250+
// add scan metadata to hub
251+
pluginHub, _ := hub.GetHub()
252+
pluginHub.AddScanMetadata(s.Iter)
250253
logging.LogTime("[fdw] IterateForeignScan end")
251254
// show profiling - ignore intervals less than 1ms
252255
//logging.DisplayProfileData(10*time.Millisecond, logger)
@@ -296,18 +299,8 @@ func goFdwEndForeignScan(node *C.ForeignScanState) {
296299
pluginHub, _ := hub.GetHub()
297300
if s != nil && pluginHub != nil {
298301
log.Printf("[TRACE] goFdwEndForeignScan, iterator: %p", s.Iter)
299-
// is the iterator still running? If so it means postgres is stopping a scan before all rows have been read
300-
if s.Iter.Status() == hub.QueryStatusStarted {
301-
// if we have identified a limit from the query (i.e. it is an ungrouped, unordered query from a single table)
302-
// then we can cache the result, using the limit in teh
303-
// but if we have NOT extracted a limit, w e cannot cache the results as we are not certain they are complete
304-
writeToCache := s.State.limit != -1
305-
log.Printf("[TRACE] ending scan before iterator complete - limit: %v, writeToCache: %v, iterator: %p", s.State.limit, writeToCache, s.Iter)
306-
s.Iter.Close(writeToCache)
307-
308-
}
302+
pluginHub.EndScan(s.Iter, int64(s.State.limit))
309303

310-
pluginHub.RemoveIterator(s.Iter)
311304
}
312305
ClearExecState(node.fdw_state)
313306
node.fdw_state = nil
@@ -376,7 +369,7 @@ func handleCommandInsert(rinfo *C.ResultRelInfo, slot *C.TupleTableSlot, rel C.R
376369
opts := GetFTableOptions(types.Oid(relid))
377370

378371
switch opts["table"] {
379-
case constants.CacheCommandTable:
372+
case constants.CommandTableCache:
380373
// we know there is just a single column - operation
381374
var isNull C.bool
382375
datum := C.slot_getattr(slot, 1, &isNull)
@@ -406,6 +399,7 @@ func handleCommandInsert(rinfo *C.ResultRelInfo, slot *C.TupleTableSlot, rel C.R
406399

407400
//export goFdwShutdown
408401
func goFdwShutdown() {
402+
log.Printf("[INFO] .\n******************************************************\n\n\t\tsteampipe postgres fdw shutdown\n\n******************************************************\n")
409403
pluginHub, err := hub.GetHub()
410404
if err != nil {
411405
FdwError(err)

go.mod

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ require (
66
github.com/dgraph-io/ristretto v0.1.0
77
github.com/golang/protobuf v1.5.2
88
github.com/hashicorp/go-hclog v1.2.0
9-
github.com/hashicorp/go-version v1.4.0
9+
github.com/hashicorp/go-version v1.5.0
1010
github.com/turbot/go-kit v0.3.0
11-
github.com/turbot/steampipe v0.14.0-pgescape
12-
github.com/turbot/steampipe-plugin-sdk/v3 v3.2.0
11+
// telemetry
12+
github.com/turbot/steampipe v1.7.0-rc.0.0.20220616124100-27feba1f2965
13+
github.com/turbot/steampipe-plugin-sdk/v3 v3.3.0-rc.0
14+
go.opentelemetry.io/otel v1.7.0
1315
google.golang.org/protobuf v1.28.0
1416
)
1517

18+
require go.opentelemetry.io/otel/metric v0.30.0
19+
1620
require (
1721
github.com/Machiel/slugify v1.0.1 // indirect
1822
github.com/Masterminds/semver v1.5.0 // indirect
@@ -22,89 +26,113 @@ require (
2226
github.com/agext/levenshtein v1.2.2 // indirect
2327
github.com/apparentlymart/go-cidr v1.1.0 // indirect
2428
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
29+
github.com/apparentlymart/go-versions v1.0.1 // indirect
30+
github.com/bgentry/speakeasy v0.1.0 // indirect
2531
github.com/bmatcuk/doublestar v1.3.4 // indirect
2632
github.com/briandowns/spinner v1.18.1 // indirect
2733
github.com/btubbs/datetime v0.1.1 // indirect
34+
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
2835
github.com/cespare/xxhash/v2 v2.1.2 // indirect
2936
github.com/containerd/cgroups v1.0.1 // indirect
3037
github.com/containerd/containerd v1.4.12 // indirect
3138
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
3239
github.com/deislabs/oras v0.8.1 // indirect
3340
github.com/dustin/go-humanize v1.0.0 // indirect
3441
github.com/fatih/color v1.13.0 // indirect
35-
github.com/fsnotify/fsnotify v1.5.1 // indirect
36-
github.com/gertd/go-pluralize v0.2.0 // indirect
42+
github.com/fsnotify/fsnotify v1.5.4 // indirect
43+
github.com/gertd/go-pluralize v0.2.1 // indirect
3744
github.com/ghodss/yaml v1.0.0 // indirect
45+
github.com/go-logr/logr v1.2.3 // indirect
46+
github.com/go-logr/stdr v1.2.2 // indirect
3847
github.com/go-ole/go-ole v1.2.6 // indirect
3948
github.com/gogo/protobuf v1.3.2 // indirect
4049
github.com/golang/glog v1.0.0 // indirect
4150
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
42-
github.com/google/go-cmp v0.5.7 // indirect
51+
github.com/google/go-cmp v0.5.8 // indirect
4352
github.com/google/uuid v1.3.0 // indirect
53+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
4454
github.com/hashicorp/errwrap v1.1.0 // indirect
4555
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
4656
github.com/hashicorp/go-multierror v1.1.1 // indirect
4757
github.com/hashicorp/go-plugin v1.4.4 // indirect
58+
github.com/hashicorp/go-retryablehttp v0.5.2 // indirect
4859
github.com/hashicorp/go-uuid v1.0.1 // indirect
4960
github.com/hashicorp/hcl v1.0.0 // indirect
50-
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
61+
github.com/hashicorp/hcl/v2 v2.12.0 // indirect
5162
github.com/hashicorp/terraform v0.15.1 // indirect
63+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
5264
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
5365
github.com/iancoleman/strcase v0.2.0 // indirect
5466
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
55-
github.com/jackc/pgconn v1.11.0 // indirect
67+
github.com/jackc/pgconn v1.12.1 // indirect
5668
github.com/jackc/pgio v1.0.0 // indirect
5769
github.com/jackc/pgpassfile v1.0.0 // indirect
58-
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
70+
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
5971
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
60-
github.com/jackc/pgtype v1.10.0 // indirect
61-
github.com/jackc/pgx/v4 v4.15.0 // indirect
72+
github.com/jackc/pgtype v1.11.0 // indirect
73+
github.com/jackc/pgx/v4 v4.16.1 // indirect
6274
github.com/karrick/gows v0.3.0 // indirect
6375
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
6476
github.com/magiconair/properties v1.8.6 // indirect
6577
github.com/mattn/go-colorable v0.1.12 // indirect
6678
github.com/mattn/go-isatty v0.0.14 // indirect
6779
github.com/mattn/go-runewidth v0.0.13 // indirect
80+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
6881
github.com/mitchellh/go-homedir v1.1.0 // indirect
6982
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
7083
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
71-
github.com/mitchellh/mapstructure v1.4.3 // indirect
84+
github.com/mitchellh/mapstructure v1.5.0 // indirect
85+
github.com/mitchellh/panicwrap v1.0.0 // indirect
7286
github.com/oklog/run v1.0.0 // indirect
7387
github.com/olekukonko/tablewriter v0.0.5 // indirect
7488
github.com/opencontainers/go-digest v1.0.0 // indirect
7589
github.com/opencontainers/image-spec v1.0.2 // indirect
76-
github.com/pelletier/go-toml v1.9.4 // indirect
77-
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
90+
github.com/pelletier/go-toml v1.9.5 // indirect
91+
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
7892
github.com/pkg/errors v0.9.1 // indirect
7993
github.com/rivo/uniseg v0.2.0 // indirect
8094
github.com/sethvargo/go-retry v0.1.0 // indirect
8195
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
8296
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
8397
github.com/sirupsen/logrus v1.8.1 // indirect
8498
github.com/spf13/afero v1.8.2 // indirect
85-
github.com/spf13/cast v1.4.1 // indirect
99+
github.com/spf13/cast v1.5.0 // indirect
86100
github.com/spf13/jwalterweatherman v1.1.0 // indirect
87101
github.com/spf13/pflag v1.0.5 // indirect
88-
github.com/spf13/viper v1.11.0 // indirect
102+
github.com/spf13/viper v1.12.0 // indirect
89103
github.com/stevenle/topsort v0.0.0-20130922064739-8130c1d7596b // indirect
90-
github.com/subosito/gotenv v1.2.0 // indirect
104+
github.com/subosito/gotenv v1.3.0 // indirect
91105
github.com/tklauser/go-sysconf v0.3.9 // indirect
92106
github.com/tklauser/numcpus v0.3.0 // indirect
93107
github.com/tkrajina/go-reflector v0.5.4 // indirect
108+
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
109+
github.com/vmihailenco/tagparser v0.1.1 // indirect
94110
github.com/xlab/treeprint v1.1.0 // indirect
95111
github.com/yusufpapurcu/wmi v1.2.2 // indirect
96112
github.com/zclconf/go-cty v1.10.0 // indirect
97113
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
98114
go.opencensus.io v0.23.0 // indirect
115+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
116+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.30.0 // indirect
117+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.30.0 // indirect
118+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.7.0 // indirect
119+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.7.0 // indirect
120+
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
121+
go.opentelemetry.io/otel/sdk/metric v0.30.0 // indirect
122+
go.opentelemetry.io/otel/trace v1.7.0 // indirect
123+
go.opentelemetry.io/proto/otlp v0.16.0 // indirect
99124
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
100-
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
125+
golang.org/x/mod v0.5.1 // indirect
126+
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
127+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
101128
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
102-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
129+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
103130
golang.org/x/text v0.3.7 // indirect
104-
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac // indirect
105-
google.golang.org/grpc v1.46.0 // indirect
131+
google.golang.org/appengine v1.6.7 // indirect
132+
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
133+
google.golang.org/grpc v1.46.2 // indirect
106134
gopkg.in/ini.v1 v1.66.4 // indirect
107135
gopkg.in/yaml.v2 v2.4.0 // indirect
108-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
136+
gopkg.in/yaml.v3 v3.0.0 // indirect
109137
sigs.k8s.io/yaml v1.3.0 // indirect
110138
)

0 commit comments

Comments
 (0)