Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
logtransfer
Project
Project
Details
Activity
Releases
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
谢宇轩
logtransfer
Commits
646c44af
Commit
646c44af
authored
Dec 27, 2021
by
谢宇轩
😅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化ES Sender逻辑
parent
fc26f103
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
6 deletions
+18
-6
format.go
entity/format.go
+1
-1
matedata.go
entity/matedata.go
+16
-4
customer.go
source/customer.go
+1
-1
No files found.
entity/format.go
View file @
646c44af
...
...
@@ -43,7 +43,7 @@ func FormatServiceWfLog(sourceKey string, message string) (Matedata, error) {
}
}
mateItem
.
Data
[
"timestamp"
]
=
mateItem
.
create
mateItem
.
Data
[
"timestamp"
]
=
mateItem
.
create
.
Format
(
"2006-01-02 15:04:05"
)
result
:=
*
mateItem
mateItem
.
reset
()
MatePool
.
Put
(
mateItem
)
...
...
entity/matedata.go
View file @
646c44af
...
...
@@ -44,6 +44,7 @@ func CloseMessageChan() {
func
MatedateSender
(
ctx
context
.
Context
,
esClient
*
elastic
.
Client
)
{
tick
:=
time
.
NewTicker
(
3
*
time
.
Second
)
var
(
SenderMu
sync
.
Mutex
)
...
...
@@ -52,21 +53,32 @@ func MatedateSender(ctx context.Context, esClient *elastic.Client) {
for
{
select
{
case
m
:=
<-
messages
:
indexRequest
:=
elastic
.
NewBulkIndexRequest
()
.
Index
(
m
.
Index
)
.
Doc
(
m
.
Data
)
SenderMu
.
Lock
()
bulkRequest
.
Add
(
indexRequest
)
SenderMu
.
Unlock
()
case
<-
tick
.
C
:
// Do sends the bulk requests to Elasticsearch
SenderMu
.
Lock
()
count
:=
bulkRequest
.
NumberOfActions
()
if
count
>
0
{
log
.
Printf
(
"Send message to Es: %d :
\n
"
,
bulkRequest
.
NumberOfActions
())
_
,
err
:=
bulkRequest
.
Do
(
ctx
)
log
.
Printf
(
"Send messages to Index: %d :
\n
"
,
bulkRequest
.
NumberOfActions
())
response
,
err
:=
bulkRequest
.
Do
(
ctx
)
if
err
!=
nil
{
log
.
Println
(
"Save Es Error:"
,
err
)
}
for
_
,
v
:=
range
response
.
Items
{
for
_
,
item
:=
range
v
{
if
item
.
Error
!=
nil
{
log
.
Printf
(
"Find Error in ES Result in (%s): %s"
,
item
.
Index
,
item
.
Error
.
Reason
)
}
}
}
bulkRequest
.
Reset
()
}
SenderMu
.
Unlock
()
...
...
source/customer.go
View file @
646c44af
...
...
@@ -79,7 +79,7 @@ func ReadingMessage(ctx context.Context, c *Customer) {
// var trycount int
// var cstSh, _ = time.LoadLocation("Asia/Shanghai") //上海时区
var
errMessage
strings
.
Builder
// log.Println(c.HandlePipeline.pipe)
var
matedata
entity
.
Matedata
for
{
...
...
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