Skip to content

Commit

Permalink
🔧 Add endTime field to access logs
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx committed Jan 25, 2021
1 parent 34e5a97 commit fc1e535
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/net/grpc/interceptor/server/logging/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
type AccessLogEntity struct {
GRPC *AccessLogGRPCEntity `json:"grpc,omitempty" yaml:"grpc"`
StartTime int64 `json:"startTime,omitempty" yaml:"startTime"`
EndTime int64 `json:"endTime,omitempty" yaml:"endTime"`
Latency int64 `json:"latency,omitempty" yaml:"latency"`
TraceID string `json:"traceID,omitempty" yaml:"traceID"`
Error error `json:"error,omitempty" yaml:"error"`
Expand Down Expand Up @@ -66,8 +67,7 @@ func AccessLogInterceptor() grpc.UnaryServerInterceptor {

resp, err = handler(ctx, req)

latency := time.Since(start).Nanoseconds()
startTime := start.UnixNano()
end := time.Now()

service, method := parseMethod(info.FullMethod)

Expand All @@ -77,8 +77,9 @@ func AccessLogInterceptor() grpc.UnaryServerInterceptor {
Service: service,
Method: method,
},
StartTime: startTime,
Latency: latency,
StartTime: start.UnixNano(),
EndTime: end.UnixNano(),
Latency: end.Sub(start).Nanoseconds(),
}

if traceID != "" {
Expand Down Expand Up @@ -114,8 +115,7 @@ func AccessLogStreamInterceptor() grpc.StreamServerInterceptor {

err := handler(srv, ss)

latency := time.Since(start).Nanoseconds()
startTime := start.UnixNano()
end := time.Now()

service, method := parseMethod(info.FullMethod)

Expand All @@ -125,8 +125,9 @@ func AccessLogStreamInterceptor() grpc.StreamServerInterceptor {
Service: service,
Method: method,
},
StartTime: startTime,
Latency: latency,
StartTime: start.UnixNano(),
EndTime: end.UnixNano(),
Latency: end.Sub(start).Nanoseconds(),
}

if traceID != "" {
Expand Down
2 changes: 2 additions & 0 deletions k8s/metrics/loki/promtail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ data:
grpcKind: details.grpc.kind
grpcService: details.grpc.service
grpcMethod: details.grpc.method
startTime: details.startTime
EndTime: details.endTime
latency: details.latency
traceID: details.traceID
- labels:
Expand Down

0 comments on commit fc1e535

Please sign in to comment.