Skip to content

Commit

Permalink
add ignore_output feature, and additional error handling for lookups (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav91 authored Jan 8, 2020
1 parent 50d56ea commit 37b7e5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 12 additions & 4 deletions internal/config/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ func FetchLookups(cfg *load.Config, i int) bool {

loopNo := -1
combinations := [][]string{}
loopLookups(loopNo, sliceIndexes, sliceKeys, sliceLookups, &combinations)
if len(sliceLookups) > 0 {
loopLookups(loopNo, sliceIndexes, sliceKeys, sliceLookups, &combinations)
}

load.Logrus.WithFields(logrus.Fields{
"name": cfg.Name,
Expand All @@ -145,10 +147,16 @@ func FetchLookups(cfg *load.Config, i int) bool {
newAPIs := []string{}
for _, combo := range combinations {
tmpConfigWithLookupReplace := tmpCfgStr
for i, key := range lookupDimensions {
tmpConfigWithLookupReplace = strings.ReplaceAll(tmpConfigWithLookupReplace, fmt.Sprintf("${lookup:%v}", key), combo[i])
if len(combo) == len(lookupDimensions) {
for i, key := range lookupDimensions {
tmpConfigWithLookupReplace = strings.ReplaceAll(tmpConfigWithLookupReplace, fmt.Sprintf("${lookup:%v}", key), combo[i])
}
newAPIs = append(newAPIs, tmpConfigWithLookupReplace)
} else {
load.Logrus.WithFields(logrus.Fields{
"name": cfg.Name,
}).Debug("fetch: invalid lookup, missing a replace")
}
newAPIs = append(newAPIs, tmpConfigWithLookupReplace)
}

lookupConfig := load.Config{
Expand Down
1 change: 1 addition & 0 deletions internal/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type API struct {
RemoveKeys []string `yaml:"remove_keys"`
KeepKeys []string `yaml:"keep_keys"` // inverse of removing keys
SampleFilter []map[string]string `yaml:"sample_filter"` // sample filter key pair values with regex
IgnoreOutput bool `yaml:"ignore_output"` // ignore the output completely, useful when creating lookups

// Debug Options
Debug bool `yaml:"debug"` // logs out additional data, should not be enabled for production use!
Expand Down
10 changes: 8 additions & 2 deletions internal/processor/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ func CreateMetricSets(samples []interface{}, config *load.Config, i int) {
RunSampleRenamer(api.RenameSamples, &currentSample, key, &eventType)
}

// check if this contains any key pair values to filter out
createSample := true
RunSampleFilter(currentSample, api.SampleFilter, &createSample)
// check if we should ignore this output completely
// useful when requests are made to generate a lookup, but the data is not needed
if api.IgnoreOutput {
createSample = false
} else {
// check if this contains any key pair values to filter out
RunSampleFilter(currentSample, api.SampleFilter, &createSample)
}

if createSample {
// remove keys from sample
Expand Down

0 comments on commit 37b7e5a

Please sign in to comment.