Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Scope
Commits
70240fc8
Commit
70240fc8
authored
5 years ago
by
Bryan Boreham
Browse files
Options
Download
Email Patches
Plain Diff
billing: cope with spy-interval set longer than publish-interval
parent
f16f321c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/multitenant/billing_emitter.go
+22
-6
app/multitenant/billing_emitter.go
app/multitenant/billing_emitter_test.go
+1
-0
app/multitenant/billing_emitter_test.go
with
23 additions
and
6 deletions
+23
-6
app/multitenant/billing_emitter.go
+
22
-
6
View file @
70240fc8
...
...
@@ -119,15 +119,31 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
return
e
.
Collector
.
Add
(
ctx
,
rep
,
buf
)
}
func
intervalFromCommand
(
cmd
string
)
string
{
if
strings
.
Contains
(
cmd
,
"scope"
)
&&
strings
.
Contains
(
cmd
,
"probe.publish.interval"
)
{
cmds
:=
strings
.
SplitAfter
(
cmd
,
"probe.publish.interval"
)
func
commandParameter
(
cmd
,
flag
string
)
(
string
,
bool
)
{
if
strings
.
Contains
(
cmd
,
flag
)
{
cmds
:=
strings
.
SplitAfter
(
cmd
,
flag
)
aft
:=
strings
.
Split
(
cmds
[
1
],
" "
)
if
aft
[
0
]
==
""
{
return
aft
[
1
]
return
aft
[
1
],
true
}
return
aft
[
0
][
1
:
],
true
}
return
""
,
false
}
func
intervalFromCommand
(
cmd
string
)
string
{
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
""
}
...
...
This diff is collapsed.
Click to expand it.
app/multitenant/billing_emitter_test.go
+
1
-
0
View file @
70240fc8
...
...
@@ -12,6 +12,7 @@ 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"
},
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment