Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing rollups to keep undefined terms if needed #749

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/ktranslate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ func applyFlags(cfg *ktranslate.Config) error {
cfg.Rollup.TopK = v
case "rollups":
cfg.Rollup.Formats = strings.Split(val, filter.AndToken)
case "rollup_keep_undefined":
v, err := strconv.ParseBool(val)
if err != nil {
errCh <- err
return
}
cfg.Rollup.KeepUndefined = v
// pkg/eggs/kmux
case "dir":
cfg.KMux.Dir = val
Expand Down
14 changes: 8 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ type DDogSinkConfig struct {

// RollupConfig is the config for rollups
type RollupConfig struct {
JoinKey string
TopK int
Formats []string
JoinKey string
TopK int
Formats []string
KeepUndefined bool
}

// KMuxConfig is the config for the mux server
Expand Down Expand Up @@ -451,9 +452,10 @@ func DefaultConfig() *Config {
RelayURL: "",
},
Rollup: &RollupConfig{
JoinKey: "^",
TopK: 10,
Formats: []string{},
JoinKey: "^",
TopK: 10,
Formats: []string{},
KeepUndefined: false,
},
KMux: &KMuxConfig{
Dir: ".",
Expand Down
18 changes: 15 additions & 3 deletions pkg/rollup/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ const (
Percentile = "entropy"

KENTIK_EVENT_TYPE = "KFlow:%s:%s"
UndefinedKey = "undefined"
)

var (
rollups RollupFlag
keyJoin string
topK int
rollups RollupFlag
keyJoin string
topK int
keepUndefined bool
)

type RollupFlag []string
Expand All @@ -48,6 +50,7 @@ func init() {
flag.Var(&rollups, "rollups", "Any rollups to use. Format: type, name, metric, dimension 1, dimension 2, ..., dimension n: sum,bytes,in_bytes,dst_addr")
flag.StringVar(&keyJoin, "rollup_key_join", "^", "Token to use to join dimension keys together")
flag.IntVar(&topK, "rollup_top_k", 10, "Export only these top values")
flag.BoolVar(&keepUndefined, "rollup_keep_undefined", false, "If set, mark undefined values with the string undefined.")
}

type Roller interface {
Expand Down Expand Up @@ -146,6 +149,9 @@ func GetRollups(log logger.Underlying, cfg *ktranslate.RollupConfig) ([]Roller,
}
}

// If true, don't drop the rollups which don't get matched.
keepUndefined = cfg.KeepUndefined

return rolls, nil
}

Expand Down Expand Up @@ -230,6 +236,9 @@ func (r *rollupBase) getKey(mapr map[string]interface{}) string {
// Skip?
}
}
if keepUndefined && keyPts[i] == "" {
keyPts[i] = UndefinedKey
}
}
next := len(r.dims)
for _, d := range r.multiDims { // Now handle the 2 level deep maps
Expand All @@ -250,6 +259,9 @@ func (r *rollupBase) getKey(mapr map[string]interface{}) string {
keyPts[next] = strconv.Itoa(int(dd[d[1]]))
}
}
if keepUndefined && keyPts[next] == "" {
keyPts[next] = UndefinedKey
}
next++
}

Expand Down
Loading