Skip to content

Commit 04d848c

Browse files
authored
Ensure all hydrate configs are initialised. Closes #683
1 parent a5c4bd7 commit 04d848c

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

.github/workflows/acceptance-test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ jobs:
7676
run: |
7777
echo "PATH=$PATH:$HOME/build::/home/runner/work/steampipe-plugin-sdk/steampipe-plugin-sdk/steampipe-plugin-chaos/tests/acceptance/lib/bats/libexec" >> $GITHUB_ENV
7878
cd /home/runner/work/steampipe-plugin-sdk/steampipe-plugin-sdk/steampipe-plugin-chaos/
79+
go mod edit -replace github.com/turbot/steampipe-plugin-sdk/v5=/home/runner/work/steampipe-plugin-sdk/steampipe-plugin-sdk/sdk
80+
go mod tidy
7981
make
8082
8183
- name: Setup BATS

plugin/hydrate_error.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,11 @@ func WrapHydrate(hydrate namedHydrateFunc, ignoreConfig *IgnoreConfig) namedHydr
154154
}
155155

156156
func shouldRetryError(ctx context.Context, d *QueryData, h *HydrateData, err error, retryConfig *RetryConfig) bool {
157-
log.Printf("[TRACE] shouldRetryError err: %v, retryConfig: %s", err, retryConfig.String())
158-
159157
if retryConfig == nil {
160-
log.Printf("[TRACE] shouldRetryError nil retry config - return false")
158+
log.Printf("[WARN] nil retry config passed to shouldRetryError this is unexpected - returning false")
161159
return false
162160
}
161+
log.Printf("[TRACE] shouldRetryError err: %v, retryConfig: %s", err, retryConfig.String())
163162

164163
if retryConfig.ShouldRetryError != nil {
165164
log.Printf("[TRACE] shouldRetryError - calling legacy ShouldRetryError")

plugin/row_data.go

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (r *rowData) getRow(ctx context.Context) (*proto.Row, error) {
6767
return nil, err
6868
}
6969

70-
log.Printf("[WARN] startAllHydrateCalls started")
7170
return r.waitForHydrateCallsToComplete(rowDataCtx)
7271
}
7372

plugin/table.go

+33-16
Original file line numberDiff line numberDiff line change
@@ -150,36 +150,31 @@ func (t *Table) setColumnNameMap() {
150150
// build map of all hydrate configs, including those specified in the legacy HydrateDependencies,
151151
// and those mentioned only in column config
152152
func (t *Table) buildHydrateConfigMap() {
153+
// TDO tidy this up - initialise at end, set name first?
153154
t.hydrateConfigMap = make(map[string]*HydrateConfig)
154155
for i := range t.HydrateConfig {
155156
// as we are converting into a pointer, we cannot use the array value direct from the range as
156157
// this was causing incorrect values - go must be reusing memory addresses for successive items
157158
h := &t.HydrateConfig[i]
158-
159-
// initialise before adding to map
159+
// NOTE: initialise the hydrate config
160160
h.initialise(t)
161+
161162
t.hydrateConfigMap[h.namedHydrate.Name] = h
162163
}
163164
// add in hydrate config for all hydrate dependencies declared using legacy property HydrateDependencies
164165
for _, d := range t.HydrateDependencies {
165166
hydrateName := newNamedHydrateFunc(d.Func).Name
166-
// if there is already a hydrate config, do nothing here
167+
// if there is already an explicit hydrate config, do nothing here
167168
// (this is a validation error that will be picked up by the validation check later)
168169
if _, ok := t.hydrateConfigMap[hydrateName]; !ok {
169-
t.hydrateConfigMap[hydrateName] = &HydrateConfig{Func: d.Func, Depends: d.Depends}
170+
// create and initialise a new hydrate config for this func
171+
t.hydrateConfigMap[hydrateName] = t.newHydrateConfig(d.Func, d.Depends...)
170172
}
171173
}
172174
// NOTE: the get config may be used as a column hydrate function so add this into the map
173175
if get := t.Get; get != nil {
174-
hydrateName := get.namedHydrate.Name
175-
t.hydrateConfigMap[hydrateName] = &HydrateConfig{
176-
Func: get.Hydrate,
177-
IgnoreConfig: get.IgnoreConfig,
178-
RetryConfig: get.RetryConfig,
179-
Tags: get.Tags,
180-
ShouldIgnoreError: get.ShouldIgnoreError,
181-
MaxConcurrency: get.MaxConcurrency,
182-
}
176+
// create and initialise a new hydrate config for the get func
177+
t.hydrateConfigMap[get.namedHydrate.Name] = t.hydrateConfigFromGet(t.Get)
183178
}
184179

185180
// now add all hydrate functions with no explicit config
@@ -191,13 +186,35 @@ func (t *Table) buildHydrateConfigMap() {
191186
hydrateName := newNamedHydrateFunc(c.Hydrate).Name
192187

193188
if _, ok := t.hydrateConfigMap[hydrateName]; !ok {
194-
t.hydrateConfigMap[hydrateName] = &HydrateConfig{
195-
Func: c.Hydrate,
196-
}
189+
t.hydrateConfigMap[hydrateName] = t.newHydrateConfig(c.Hydrate)
197190
}
198191
}
199192
}
200193

194+
func (t *Table) newHydrateConfig(hydrateFunc HydrateFunc, depends ...HydrateFunc) *HydrateConfig {
195+
c := &HydrateConfig{Func: hydrateFunc, Depends: depends}
196+
// be sure to initialise the config
197+
c.initialise(t)
198+
return c
199+
}
200+
201+
func (t *Table) hydrateConfigFromGet(get *GetConfig) *HydrateConfig {
202+
if t.Get == nil {
203+
return nil
204+
}
205+
c := &HydrateConfig{
206+
Func: get.Hydrate,
207+
IgnoreConfig: get.IgnoreConfig,
208+
RetryConfig: get.RetryConfig,
209+
Tags: get.Tags,
210+
ShouldIgnoreError: get.ShouldIgnoreError,
211+
MaxConcurrency: get.MaxConcurrency,
212+
}
213+
// be sure to initialise the config
214+
c.initialise(t)
215+
return c
216+
}
217+
201218
func (t *Table) getFetchFunc(fetchType fetchType) namedHydrateFunc {
202219
if fetchType == fetchTypeList {
203220
return *t.List.namedHydrate

0 commit comments

Comments
 (0)