Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
9c4ae4e8
Commit
9c4ae4e8
authored
5 years ago
by
Ming Deng
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue for review
parent
c5082fd3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
filter/impl/access_log_filter.go
+32
-29
32 additions, 29 deletions
filter/impl/access_log_filter.go
filter/impl/access_log_filter_test.go
+21
-5
21 additions, 5 deletions
filter/impl/access_log_filter_test.go
with
53 additions
and
34 deletions
filter/impl/access_log_filter.go
+
32
−
29
View file @
9c4ae4e8
...
...
@@ -17,20 +17,23 @@
package
impl
import
(
"os"
"reflect"
"strings"
"time"
)
import
(
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/filter"
"github.com/apache/dubbo-go/protocol"
"os"
"reflect"
"strings"
"time"
)
const
(
//usd in URL.
//us
e
d in URL.
AccessLogKey
=
"accesslog"
FileDateFormat
=
"2006-01-02"
MessageDateLayout
=
"2006-01-02 15:04:05"
...
...
@@ -72,7 +75,7 @@ func (ef *AccessLogFilter) logIntoChannel(accessLogData AccessLogData) {
}
func
(
ef
*
AccessLogFilter
)
buildAccessLogData
(
invoker
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
map
[
string
]
string
{
dataMap
:=
make
(
map
[
string
]
string
)
dataMap
:=
make
(
map
[
string
]
string
,
16
)
attachments
:=
invocation
.
Attachments
()
dataMap
[
constant
.
INTERFACE_KEY
]
=
attachments
[
constant
.
INTERFACE_KEY
]
dataMap
[
constant
.
METHOD_KEY
]
=
invocation
.
MethodName
()
...
...
@@ -86,15 +89,15 @@ func (ef *AccessLogFilter) buildAccessLogData(invoker protocol.Invoker, invocati
builder
:=
strings
.
Builder
{}
// todo(after the paramTypes were set to the invocation. we should change this implementation)
typeBuilder
:=
strings
.
Builder
{}
first
:=
true
for
_
,
arg
:=
range
invocation
.
Arguments
()
{
if
first
{
first
=
false
}
else
{
builder
.
WriteString
(
","
)
typeBuilder
.
WriteString
(
","
)
}
builder
.
WriteString
(
reflect
.
ValueOf
(
invocation
.
Arguments
()[
0
])
.
String
())
typeBuilder
.
WriteString
(
reflect
.
TypeOf
(
invocation
.
Arguments
()[
0
])
.
Name
())
for
idx
:=
1
;
idx
<
len
(
invocation
.
Arguments
());
idx
++
{
arg
:=
invocation
.
Arguments
()[
idx
]
builder
.
WriteString
(
","
)
builder
.
WriteString
(
reflect
.
ValueOf
(
arg
)
.
String
())
typeBuilder
.
WriteString
(
","
)
typeBuilder
.
WriteString
(
reflect
.
TypeOf
(
arg
)
.
Name
())
}
dataMap
[
Arguments
]
=
builder
.
String
()
...
...
@@ -112,19 +115,20 @@ func (ef *AccessLogFilter) writeLogToFile(data AccessLogData) {
accessLog
:=
data
.
accessLog
if
isDefault
(
accessLog
)
{
logger
.
Info
(
data
.
toLogMessage
())
}
else
{
logFile
,
err
:=
ef
.
openLogFile
(
accessLog
)
if
err
!=
nil
{
logger
.
Warnf
(
"Can not open the access log file: %s, %v"
,
accessLog
,
err
)
return
}
logger
.
Debugf
(
"Append log to %s"
,
accessLog
)
message
:=
data
.
toLogMessage
()
message
=
message
+
"
\n
"
_
,
err
=
logFile
.
WriteString
(
message
)
if
err
!=
nil
{
logger
.
Warnf
(
"Can not write the log into access log file: %s, %v"
,
accessLog
,
err
)
}
return
}
logFile
,
err
:=
ef
.
openLogFile
(
accessLog
)
if
err
!=
nil
{
logger
.
Warnf
(
"Can not open the access log file: %s, %v"
,
accessLog
,
err
)
return
}
logger
.
Debugf
(
"Append log to %s"
,
accessLog
)
message
:=
data
.
toLogMessage
()
message
=
message
+
"
\n
"
_
,
err
=
logFile
.
WriteString
(
message
)
if
err
!=
nil
{
logger
.
Warnf
(
"Can not write the log into access log file: %s, %v"
,
accessLog
,
err
)
}
}
...
...
@@ -146,9 +150,8 @@ func (ef *AccessLogFilter) openLogFile(accessLog string) (*os.File, error) {
if
err
!=
nil
{
logger
.
Warnf
(
"Can not rename access log file: %s, %v"
,
fileInfo
.
Name
(),
err
)
return
nil
,
err
}
else
{
logFile
,
err
=
os
.
OpenFile
(
accessLog
,
os
.
O_CREATE
|
os
.
O_APPEND
|
os
.
O_RDWR
,
LogFileMode
)
}
logFile
,
err
=
os
.
OpenFile
(
accessLog
,
os
.
O_CREATE
|
os
.
O_APPEND
|
os
.
O_RDWR
,
LogFileMode
)
}
return
logFile
,
err
}
...
...
This diff is collapsed.
Click to expand it.
filter/impl/access_log_filter_test.go
+
21
−
5
View file @
9c4ae4e8
...
...
@@ -19,12 +19,19 @@ package impl
import
(
"context"
"testing"
)
import
(
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"testing"
)
func
TestAccessLogFilter_Invoke_Not_Config
(
t
*
testing
.
T
)
{
...
...
@@ -39,7 +46,7 @@ func TestAccessLogFilter_Invoke_Not_Config(t *testing.T) {
invoker
:=
protocol
.
NewBaseInvoker
(
url
)
attach
:=
make
(
map
[
string
]
string
,
10
)
inv
:=
invocation
.
NewRPCInvocation
(
"MethodName"
,
[]
interface
{}{
"OK"
},
attach
)
inv
:=
invocation
.
NewRPCInvocation
(
"MethodName"
,
[]
interface
{}{
"OK"
,
"Hello"
},
attach
)
accessLogFilter
:=
GetAccessLogFilter
()
result
:=
accessLogFilter
.
Invoke
(
invoker
,
inv
)
...
...
@@ -58,9 +65,18 @@ func TestAccessLogFilter_Invoke_Default_Config(t *testing.T) {
invoker
:=
protocol
.
NewBaseInvoker
(
url
)
attach
:=
make
(
map
[
string
]
string
,
10
)
inv
:=
invocation
.
NewRPCInvocation
(
"MethodName"
,
[]
interface
{}{
"OK"
},
attach
)
attach
[
constant
.
VERSION_KEY
]
=
"1.0"
attach
[
constant
.
GROUP_KEY
]
=
"MyGroup"
inv
:=
invocation
.
NewRPCInvocation
(
"MethodName"
,
[]
interface
{}{
"OK"
,
"Hello"
},
attach
)
accessLogFilter
:=
GetAccessLogFilter
()
result
:=
accessLogFilter
.
Invoke
(
invoker
,
inv
)
assert
.
Nil
(
t
,
result
.
Error
())
}
func
TestAccessLogFilter_OnResponse
(
t
*
testing
.
T
)
{
result
:=
&
protocol
.
RPCResult
{}
accessLogFilter
:=
GetAccessLogFilter
()
response
:=
accessLogFilter
.
OnResponse
(
result
,
nil
,
nil
)
assert
.
Equal
(
t
,
result
,
response
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
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