Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
9f0012d0
Commit
9f0012d0
authored
5 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
added encoder/decoder for store.Log
parent
3c52279f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
store/logs.go
+33
-2
33 additions, 2 deletions
store/logs.go
store/logs_test.go
+38
-0
38 additions, 0 deletions
store/logs_test.go
with
71 additions
and
2 deletions
store/logs.go
+
33
−
2
View file @
9f0012d0
...
...
@@ -25,11 +25,12 @@
package
store
import
(
"bytes"
"compress/gzip"
"encoding/json"
"io"
"sync"
"time"
"encoding/json"
)
type
Log
struct
{
...
...
@@ -51,6 +52,36 @@ func (l *Log) MarshalJSON() ([]byte, error) {
return
json
.
Marshal
(
l
.
lines
)
}
func
(
l
*
Log
)
encode
()
([]
byte
,
error
)
{
l
.
m
.
RLock
()
defer
l
.
m
.
RUnlock
()
var
buf
bytes
.
Buffer
comp
:=
gzip
.
NewWriter
(
&
buf
)
enc
:=
json
.
NewEncoder
(
comp
)
if
err
:=
enc
.
Encode
(
l
.
lines
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
comp
.
Close
();
err
!=
nil
{
return
nil
,
err
}
return
buf
.
Bytes
(),
nil
}
func
(
l
*
Log
)
decode
(
data
[]
byte
)
error
{
l
.
m
.
RLock
()
defer
l
.
m
.
RUnlock
()
l
.
lines
=
nil
buf
:=
bytes
.
NewBuffer
(
data
)
decomp
,
err
:=
gzip
.
NewReader
(
buf
)
if
err
!=
nil
{
return
err
}
dec
:=
json
.
NewDecoder
(
decomp
)
return
dec
.
Decode
(
&
l
.
lines
)
}
func
(
l
*
Log
)
NewReader
(
stream
string
)
*
LogReader
{
return
&
LogReader
{
l
,
-
1
,
stream
}
}
...
...
This diff is collapsed.
Click to expand it.
store/logs_test.go
+
38
−
0
View file @
9f0012d0
...
...
@@ -29,6 +29,44 @@ import (
"testing"
)
func
TestLogEncodeDecode
(
t
*
testing
.
T
)
{
var
log1
Log
log1
.
Append
(
"stdout"
,
"this is a test"
)
log1
.
Append
(
"stdout"
,
"this is another test"
)
log1
.
Append
(
"stderr"
,
"oh no something went wrong!"
)
out
,
err
:=
log1
.
encode
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
var
log2
Log
if
err
=
log2
.
decode
(
out
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
// reflect.DeepEqual does not use time.Equal... so we have to do this by hand...
equal
:=
false
if
len
(
log1
.
lines
)
==
len
(
log2
.
lines
)
{
for
i
:=
range
log1
.
lines
{
if
log1
.
lines
[
i
]
.
Stream
!=
log2
.
lines
[
i
]
.
Stream
{
break
}
if
log1
.
lines
[
i
]
.
Line
!=
log2
.
lines
[
i
]
.
Line
{
break
}
if
!
log1
.
lines
[
i
]
.
Timestamp
.
Equal
(
log2
.
lines
[
i
]
.
Timestamp
)
{
break
}
}
equal
=
true
}
if
!
equal
{
t
.
Fatalf
(
"logs are not equal: expected %+v, got %+v"
,
log1
.
lines
,
log2
.
lines
)
}
}
func
TestLogReader
(
t
*
testing
.
T
)
{
var
log
Log
var
buf
[
1024
]
byte
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment