Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
c62f77b1
Commit
c62f77b1
authored
Jun 13, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] fix remain replay file upload.
parent
e41d81df
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
8 deletions
+65
-8
task.go
pkg/koko/task.go
+62
-7
recorder.go
pkg/proxy/recorder.go
+3
-1
No files found.
pkg/koko/task.go
View file @
c62f77b1
...
...
@@ -30,23 +30,51 @@ func uploadRemainReplay(rootPath string) {
logger
.
Debugf
(
"upload failed replay err: %s"
,
err
.
Error
())
return
}
allRemainFiles
:=
make
(
map
[
string
]
string
)
_
=
filepath
.
Walk
(
replayDir
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
||
info
.
IsDir
()
{
return
nil
}
var
sid
string
filename
:=
info
.
Name
()
if
len
(
filename
)
==
36
{
sid
=
filename
}
if
strings
.
HasSuffix
(
filename
,
".replay.gz"
)
{
sid
:=
strings
.
Split
(
filename
,
"."
)[
0
]
if
len
(
sid
)
==
36
{
relayRecord
:=
proxy
.
NewReplyRecord
(
sid
)
relayRecord
.
AbsGzFilePath
=
path
relayRecord
.
Target
,
_
=
filepath
.
Rel
(
path
,
rootPath
)
go
relayRecord
.
UploadGzipFile
(
3
)
sidName
:=
strings
.
Split
(
filename
,
"."
)[
0
]
if
len
(
sidName
)
==
36
{
sid
=
sidName
}
}
if
sid
!=
""
{
data
:=
map
[
string
]
interface
{}{
"id"
:
sid
,
"date_end"
:
info
.
ModTime
()
.
UTC
()
.
Format
(
"2006-01-02 15:04:05 +0000"
)}
service
.
FinishSession
(
data
)
allRemainFiles
[
sid
]
=
path
}
return
nil
})
for
sid
,
path
:=
range
allRemainFiles
{
var
absGzPath
string
if
strings
.
HasSuffix
(
path
,
".replay.gz"
)
{
absGzPath
=
path
}
else
if
strings
.
HasSuffix
(
path
,
sid
)
{
if
err
:=
ValidateRemainReplayFile
(
path
);
err
!=
nil
{
continue
}
absGzPath
=
path
+
".replay.gz"
if
err
:=
common
.
GzipCompressFile
(
path
,
absGzPath
);
err
!=
nil
{
continue
}
_
=
os
.
Remove
(
path
)
}
relayRecord
:=
&
proxy
.
ReplyRecorder
{}
relayRecord
.
AbsGzFilePath
=
absGzPath
relayRecord
.
Target
,
_
=
filepath
.
Rel
(
path
,
rootPath
)
relayRecord
.
UploadGzipFile
(
3
)
}
logger
.
Debug
(
"Upload remain replay done"
)
}
...
...
@@ -66,3 +94,29 @@ func keepHeartbeat(interval time.Duration) {
}
}
}
func
ValidateRemainReplayFile
(
path
string
)
error
{
f
,
err
:=
os
.
OpenFile
(
path
,
os
.
O_RDWR
|
os
.
O_APPEND
,
os
.
ModePerm
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
tmp
:=
make
([]
byte
,
1
)
_
,
err
=
f
.
Seek
(
-
1
,
2
)
if
err
!=
nil
{
return
err
}
_
,
err
=
f
.
Read
(
tmp
)
if
err
!=
nil
{
return
err
}
switch
string
(
tmp
)
{
case
"}"
:
return
nil
case
","
:
_
,
err
=
f
.
Write
([]
byte
(
`"0":""}`
))
default
:
_
,
err
=
f
.
Write
([]
byte
(
`}`
))
}
return
err
}
\ No newline at end of file
pkg/proxy/recorder.go
View file @
c62f77b1
...
...
@@ -105,7 +105,6 @@ type ReplyRecorder struct {
}
func
(
r
*
ReplyRecorder
)
initial
()
{
r
.
storage
=
NewReplayStorage
()
r
.
backOffStorage
=
defaultReplayStorage
r
.
prepare
()
}
...
...
@@ -171,6 +170,9 @@ func (r *ReplyRecorder) uploadReplay() {
}
func
(
r
*
ReplyRecorder
)
UploadGzipFile
(
maxRetry
int
)
{
if
r
.
storage
==
nil
{
r
.
storage
=
NewReplayStorage
()
}
for
i
:=
0
;
i
<=
maxRetry
;
i
++
{
logger
.
Debug
(
"Upload replay file: "
,
r
.
AbsGzFilePath
)
err
:=
r
.
storage
.
Upload
(
r
.
AbsGzFilePath
,
r
.
Target
)
...
...
Write
Preview
Markdown
is supported
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