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
2bfd6d7e
Commit
2bfd6d7e
authored
8 years ago
by
Jonathan Lange
Browse files
Options
Download
Email Patches
Plain Diff
Parametrize compression level
parent
e4c75e62
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/multitenant/aws_collector.go
+2
-1
app/multitenant/aws_collector.go
probe/appclient/report_publisher.go
+2
-1
probe/appclient/report_publisher.go
report/marshal.go
+2
-2
report/marshal.go
report/marshal_test.go
+28
-1
report/marshal_test.go
with
34 additions
and
5 deletions
+34
-5
app/multitenant/aws_collector.go
+
2
-
1
View file @
2bfd6d7e
...
...
@@ -2,6 +2,7 @@ package multitenant
import
(
"bytes"
"compress/gzip"
"crypto/md5"
"fmt"
"io"
...
...
@@ -346,7 +347,7 @@ func (c *awsCollector) Add(ctx context.Context, rep report.Report) error {
// first, encode the report into a buffer and record its size
var
buf
bytes
.
Buffer
rep
.
WriteBinary
(
&
buf
)
rep
.
WriteBinary
(
&
buf
,
gzip
.
BestCompression
)
reportSizeHistogram
.
Observe
(
float64
(
buf
.
Len
()))
// second, put the report on s3
...
...
This diff is collapsed.
Click to expand it.
probe/appclient/report_publisher.go
+
2
-
1
View file @
2bfd6d7e
...
...
@@ -2,6 +2,7 @@ package appclient
import
(
"bytes"
"compress/gzip"
"github.com/weaveworks/scope/report"
)
...
...
@@ -28,6 +29,6 @@ func (p *ReportPublisher) Publish(r report.Report) error {
})
}
buf
:=
&
bytes
.
Buffer
{}
r
.
WriteBinary
(
buf
)
r
.
WriteBinary
(
buf
,
gzip
.
BestCompression
)
return
p
.
publisher
.
Publish
(
buf
)
}
This diff is collapsed.
Click to expand it.
report/marshal.go
+
2
-
2
View file @
2bfd6d7e
...
...
@@ -9,8 +9,8 @@ import (
)
// WriteBinary writes a Report as a gzipped msgpack.
func
(
rep
Report
)
WriteBinary
(
w
io
.
Writer
)
error
{
gzwriter
,
err
:=
gzip
.
NewWriterLevel
(
w
,
gzip
.
BestC
ompression
)
func
(
rep
Report
)
WriteBinary
(
w
io
.
Writer
,
compressionLevel
int
)
error
{
gzwriter
,
err
:=
gzip
.
NewWriterLevel
(
w
,
c
ompression
Level
)
if
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
report/marshal_test.go
+
28
-
1
View file @
2bfd6d7e
...
...
@@ -2,6 +2,7 @@ package report_test
import
(
"bytes"
"compress/gzip"
"reflect"
"testing"
...
...
@@ -11,7 +12,7 @@ import (
func
TestRoundtrip
(
t
*
testing
.
T
)
{
var
buf
bytes
.
Buffer
r1
:=
report
.
MakeReport
()
r1
.
WriteBinary
(
&
buf
)
r1
.
WriteBinary
(
&
buf
,
gzip
.
BestCompression
)
r2
,
err
:=
report
.
MakeFromBinary
(
&
buf
)
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -20,3 +21,29 @@ func TestRoundtrip(t *testing.T) {
t
.
Errorf
(
"%v != %v"
,
r1
,
*
r2
)
}
}
func
TestRoundtripNoCompression
(
t
*
testing
.
T
)
{
// Make sure that we can use our standard routines for decompressing
// something with '0' level compression.
var
buf
bytes
.
Buffer
r1
:=
report
.
MakeReport
()
r1
.
WriteBinary
(
&
buf
,
0
)
r2
,
err
:=
report
.
MakeFromBinary
(
&
buf
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
!
reflect
.
DeepEqual
(
r1
,
*
r2
)
{
t
.
Errorf
(
"%v != %v"
,
r1
,
*
r2
)
}
}
func
TestMoreCompressionMeansSmaller
(
t
*
testing
.
T
)
{
// Make sure that 0 level compression actually does compress less.
var
buf1
,
buf2
bytes
.
Buffer
r
:=
report
.
MakeReport
()
r
.
WriteBinary
(
&
buf1
,
gzip
.
BestCompression
)
r
.
WriteBinary
(
&
buf2
,
0
)
if
buf1
.
Len
()
>=
buf2
.
Len
()
{
t
.
Errorf
(
"Compression doesn't change size: %v >= %v"
,
buf1
.
Len
(),
buf2
.
Len
())
}
}
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