Skip to content

Commit

Permalink
extend lookups feature, create preprocessed & array support (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav91 authored Dec 31, 2019
1 parent 36efd3e commit 042cbf9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/inputs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func handleJSON(dataStore *[]interface{}, body []byte, resp *gorequest.Response,
// load.StoreAppend(theSample)
*dataStore = append(*dataStore, theSample)

if theSample["error"] != nil {
if theSample["error"] != nil && fmt.Sprintf("%v", theSample["error"]) != "false" {
load.Logrus.Debug(fmt.Sprintf("http: request failed %v", theSample["error"]))
}

Expand Down
10 changes: 10 additions & 0 deletions internal/processor/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ func RunDataHandler(dataSets []interface{}, samplesToMerge *map[string][]interfa
func processDataSet(dataSet *map[string]interface{}, samplesToMerge *map[string][]interface{}, i int, cfg *load.Config) {
ds := (*dataSet)

if cfg.LookupStore == nil {
cfg.LookupStore = map[string][]string{}
}

// perform an early lookup store
// useful for arrays of data
for k, v := range ds {
StoreLookups(cfg.APIs[i].StoreLookups, &k, &cfg.LookupStore, &v)
}

FindStartKey(&ds, cfg.APIs[i].StartKey, cfg.APIs[i].InheritAttributes) // start at a later part in the received data
StripKeys(&ds, cfg.APIs[i].StripKeys) // remove before flattening
RunLazyFlatten(&ds, cfg, i) // perform lazy flatten if needed
Expand Down
13 changes: 12 additions & 1 deletion internal/processor/lookups.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ func StoreLookups(storeLookups map[string]string, key *string, lookupStore *map[
lookupStoreKey: fmt.Sprintf("%v", *v),
}).Debug("create: store lookup")

(*lookupStore)[lookupStoreKey] = append((*lookupStore)[lookupStoreKey], fmt.Sprintf("%v", *v))
switch data := (*v).(type) {
case []interface{}:
load.Logrus.WithFields(logrus.Fields{
"lookupFindKey": lookupFindKey,
}).Debug("splitting array")

for _, dataKey := range data {
(*lookupStore)[lookupStoreKey] = append((*lookupStore)[lookupStoreKey], fmt.Sprintf("%v", dataKey))
}
default:
(*lookupStore)[lookupStoreKey] = append((*lookupStore)[lookupStoreKey], fmt.Sprintf("%v", *v))
}
}
}
}
Expand Down

0 comments on commit 042cbf9

Please sign in to comment.