8000 billing: cope with spy-interval set longer than publish-interval by bboreham · Pull Request #3796 · weaveworks/scope · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

billing: cope with spy-interval set longer than publish-interval #3796

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

Merged
merged 2 commits into from
Jun 11, 2020
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
33 changes: 26 additions & 7 deletions app/multitenant/billing_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,34 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
return e.Collector.Add(ctx, rep, buf)
}

func commandParameter(cmd, flag string) (string, bool) {
i := strings.Index(cmd, flag)
if i != -1 {
// here we expect the command looks like `-foo=bar` or `-foo bar`
aft := strings.Fields(cmd[i+len(flag):])
if len(aft) > 0 && len(aft[0]) > 0 {
if aft[0][0] == '=' {
return aft[0][1:], true
}
return aft[0], true
}
}
return "", false
}

func intervalFromCommand(cmd string) string {
if strings.Contains(cmd, "scope") &&
strings.Contains(cmd, "probe.publish.interval") {
cmds := strings.SplitAfter(cmd, "probe.publish.interval")
aft := strings.Split(cmds[1], " ")
if aft[0] == "" {
return aft[1]
if strings.Contains(cmd, "scope") {
if publishInterval, ok := commandParameter(cmd, "probe.publish.interval"); ok {
// If spy interval is higher than publish interval, some reports will have no process data
if spyInterval, ok := commandParameter(cmd, "spy.interval"); ok {
pubDuration, err1 := time.ParseDuration(publishInterval)
spyDuration, err2 := time.ParseDuration(spyInterval)
if err1 == nil && err2 == nil && spyDuration > pubDuration {
return spyInterval
}
}
return publishInterval
}
return aft[0][1:]
}
return ""
}
Expand Down
4 changes: 4 additions & 0 deletions app/multitenant/billing_emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ func Test_intervalFromCommand(t *testing.T) {
{cmd: "/home/weave/scope --mode=probe --probe-only --probe.kubernetes=true --probe.spy.interval=3s --probe.publish.interval 5s --probe.processes=false --probe.conntrack=false --probe.ebpf.connections=false --probe.docker.bridge=docker0 --probe.docker=true https://redacted@cloud.weave.works.", want: "5s", name: "space"},
{cmd: "/home/weave/scope --mode=probe --no-app --probe.docker=true --probe.kubernetes.role=host --weave=false --probe.publish.interval=4500ms --probe.spy.interval=2s --probe.http.listen=:4041 --probe.conntrack.buffersize=4194304 https://redacted@cloud.weave.works scope.weave.svc.cluster.local:80", want: "4500ms", name: "miliseconds"},
{cmd: "/home/weave/scope --mode=probe --no-app --probe.docker=true --probe.kubernetes.role=host --weave=false --probe.spy.interval=2s --probe.http.listen=:4041 --probe.conntrack.buffersize=4194304 https://redacted@cloud.weave.works scope.weave.svc.cluster.local:80", want: "", name: "notset"},
{cmd: "/home/weave/scope --mode=probe --probe-only --probe.kubernetes.role=host --probe.publish.interval=4500ms --probe.spy.interval=10s --probe.docker.bridge=docker0 --probe.docker=true --probe.ebpf.connections=false --probe.conntrack=false https://redacted@cloud.weave.works.", want: "10s", name: "higher-spy-interval"},
{cmd: "/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:8080 --storage.tsdb.retention.time=2h --web.enable-lifecycle", want: "", name: "notscope"},
{cmd: "", want: "", name: "blank"},
{cmd: "/home/weave/scope --probe.publish.interval=3s", want: "3s", name: "at-end"},
{cmd: "/home/weave/scope --probe.publish.interval=", want: "", name: "equals-blank"},
{cmd: "/home/weave/scope --probe.publish.interval", want: "", name: "no-value"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
0