Skip to content

Commit

Permalink
Merge pull request #55 from dongxuny/master
Browse files Browse the repository at this point in the history
Bump up rk-entry version to v1.0.8 which enable Loki Syncer
  • Loading branch information
dongxuny authored Jan 29, 2022
2 parents f1d45a4 + 590e676 commit d9e6084
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 53 deletions.
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ User can start multiple [gRPC](https://grpc.io/docs/languages/go/) and [grpc-gat
| grpc.enableRkGwOption | Enable RK style [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) server options. [detail](boot/gw_server_options.go) | false |
| grpc.noRecvMsgSizeLimit | Disable [gRPC](https://grpc.io/docs/languages/go/) server side receive message size limit | false |
| grpc.gwMappingFilePaths | The grpc [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) mapping file path. [example](boot/api/v1/gw_mapping.yaml) | string array | [] |
| grpc.cert.ref | Reference of cert entry declared in [cert entry](https://github.com/rookie-ninja/rk-entry#certentry) | string | "" |
| grpc.logger.zapLogger.ref | Reference of zapLoggerEntry declared in [zapLoggerEntry](https://github.com/rookie-ninja/rk-entry#zaploggerentry) | string | "" |
| grpc.logger.eventLogger.ref | Reference of eventLoggerEntry declared in [eventLoggerEntry](https://github.com/rookie-ninja/rk-entry#eventloggerentry) | string | "" |
| grpc.certEntry | Reference of cert entry declared in [cert entry](https://github.com/rookie-ninja/rk-entry#certentry) | string | "" |
| grpc.logger.zapLogger | Reference of zapLoggerEntry declared in [zapLoggerEntry](https://github.com/rookie-ninja/rk-entry#zaploggerentry) | string | "" |
| grpc.logger.eventLogger | Reference of eventLoggerEntry declared in [eventLoggerEntry](https://github.com/rookie-ninja/rk-entry#eventloggerentry) | string | "" |
### gRPC gateway options
Please refer to bellow repository for detailed explanations.
Expand Down Expand Up @@ -810,6 +810,17 @@ Middleware for [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway).
# maxbackups: 3 # Optional, default: 3 (days)
# localtime: true # Optional, default: true
# compress: true # Optional, default: true
# loki:
# enabled: true # Optional, default: false
# addr: localhost:3100 # Optional, default: localhost:3100
# path: /loki/api/v1/push # Optional, default: /loki/api/v1/push
# username: "" # Optional, default: ""
# password: "" # Optional, default: ""
# maxBatchWaitMs: 3000 # Optional, default: 3000
# maxBatchSize: 1000 # Optional, default: 1000
# insecureSkipVerify: false # Optional, default: false
# labels: # Optional, default: empty map
# my_label_key: my_label_value
#eventLogger:
# - name: event-logger # Required
# encoding: "json" # Optional, default: console, options: [json, console]
Expand All @@ -821,6 +832,17 @@ Middleware for [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway).
# maxbackups: 3 # Optional, default: 3 (days)
# localtime: true # Optional, default: true
# compress: true # Optional, default: true
# loki:
# enabled: true # Optional, default: false
# addr: localhost:3100 # Optional, default: localhost:3100
# path: /loki/api/v1/push # Optional, default: /loki/api/v1/push
# username: "" # Optional, default: ""
# password: "" # Optional, default: ""
# maxBatchWaitMs: 3000 # Optional, default: 3000
# maxBatchSize: 1000 # Optional, default: 1000
# insecureSkipVerify: false # Optional, default: false
# labels: # Optional, default: empty map
# my_label_key: my_label_value
#cred:
# - name: "local-cred" # Required
# description: "Description of entry" # Optional
Expand Down Expand Up @@ -861,8 +883,7 @@ grpc:
# discardUnknown: false # Optional, default: false
# noRecvMsgSizeLimit: true # Optional, default: false
# gwMappingFilePaths: [] # Optional
# cert:
# ref: "local-cert" # Optional, default: "", reference of cert entry declared above
# certEntry: "local-cert" # Optional, default: "", reference of cert entry declared above
# sw:
# enabled: true # Optional, default: false
# path: "sw" # Optional, default: "sw"
Expand All @@ -889,10 +910,8 @@ grpc:
# cert: # Optional
# ref: "local-test" # Optional, default: "", reference of cert entry declared above
# logger:
# zapLogger:
# ref: zap-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# eventLogger:
# ref: event-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# zapLogger: zap-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# eventLogger: event-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# interceptors:
# loggingZap:
# enabled: true # Optional, default: false
Expand Down
34 changes: 16 additions & 18 deletions boot/grpc_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ const (
// BootConfig Boot config which is for grpc entry.
type BootConfig struct {
Grpc []struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
Port uint64 `yaml:"port" json:"port"`
Enabled bool `yaml:"enabled" json:"enabled"`
EnableReflection bool `yaml:"enableReflection" json:"enableReflection"`
NoRecvMsgSizeLimit bool `yaml:"noRecvMsgSizeLimit" json:"noRecvMsgSizeLimit"`
Cert struct {
Ref string `yaml:"ref" json:"ref"`
} `yaml:"cert" json:"cert"`
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
Port uint64 `yaml:"port" json:"port"`
Enabled bool `yaml:"enabled" json:"enabled"`
EnableReflection bool `yaml:"enableReflection" json:"enableReflection"`
NoRecvMsgSizeLimit bool `yaml:"noRecvMsgSizeLimit" json:"noRecvMsgSizeLimit"`
CertEntry string `yaml:"certEntry" json:"certEntry"`
CommonService rkentry.BootConfigCommonService `yaml:"commonService" json:"commonService"`
Sw rkentry.BootConfigSw `yaml:"sw" json:"sw"`
Tv rkentry.BootConfigTv `yaml:"tv" json:"tv"`
Expand All @@ -113,12 +111,8 @@ type BootConfig struct {
TracingTelemetry rkmidtrace.BootConfig `yaml:"tracingTelemetry" json:"tracingTelemetry"`
} `yaml:"interceptors" json:"interceptors"`
Logger struct {
ZapLogger struct {
Ref string `yaml:"ref" json:"ref"`
} `yaml:"zapLogger" json:"zapLogger"`
EventLogger struct {
Ref string `yaml:"ref" json:"ref"`
} `yaml:"eventLogger" json:"eventLogger"`
ZapLogger string `yaml:"zapLogger" json:"zapLogger"`
EventLogger string `yaml:"eventLogger" json:"eventLogger"`
} `yaml:"logger" json:"logger"`
} `yaml:"grpc" json:"grpc"`
}
Expand Down Expand Up @@ -193,12 +187,12 @@ func RegisterGrpcEntriesWithConfig(configFilePath string) map[string]rkentry.Ent
continue
}

zapLoggerEntry := rkentry.GlobalAppCtx.GetZapLoggerEntry(element.Logger.ZapLogger.Ref)
zapLoggerEntry := rkentry.GlobalAppCtx.GetZapLoggerEntry(element.Logger.ZapLogger)
if zapLoggerEntry == nil {
zapLoggerEntry = rkentry.GlobalAppCtx.GetZapLoggerEntryDefault()
}

eventLoggerEntry := rkentry.GlobalAppCtx.GetEventLoggerEntry(element.Logger.EventLogger.Ref)
eventLoggerEntry := rkentry.GlobalAppCtx.GetEventLoggerEntry(element.Logger.EventLogger)
if eventLoggerEntry == nil {
eventLoggerEntry = rkentry.GlobalAppCtx.GetEventLoggerEntryDefault()
}
Expand Down Expand Up @@ -296,7 +290,7 @@ func RegisterGrpcEntriesWithConfig(configFilePath string) map[string]rkentry.Ent
WithStaticFileHandlerEntry(staticEntry),
WithEnableReflection(element.EnableReflection),
WithGwMappingFilePaths(element.GwMappingFilePaths...),
WithCertEntry(rkentry.GlobalAppCtx.GetCertEntry(element.Cert.Ref)))
WithCertEntry(rkentry.GlobalAppCtx.GetCertEntry(element.CertEntry)))

// Did we disabled message size for receiving?
if element.NoRecvMsgSizeLimit {
Expand Down Expand Up @@ -462,6 +456,10 @@ func RegisterGrpcEntry(opts ...GrpcEntryOption) *GrpcEntry {
}
}

// add entry name and entry type into loki syncer if enabled
entry.ZapLoggerEntry.AddEntryLabelToLokiSyncer(entry)
entry.EventLoggerEntry.AddEntryLabelToLokiSyncer(entry)

rkentry.GlobalAppCtx.AddEntry(entry)

return entry
Expand Down
9 changes: 3 additions & 6 deletions boot/grpc_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ grpc:
enabled: true
commonService:
enabled: true # Optional, default: false
cert:
ref: "local-cert" # Optional, default: "", reference of cert entry declared above
certEntry: "local-cert" # Optional, default: "", reference of cert entry declared above
noRecvMsgSizeLimit: true
enableRkGwOption: true
gwOption:
Expand Down Expand Up @@ -152,10 +151,8 @@ grpc:
cert:
ref: "local-cert" # Optional, default: "", reference of cert entry declared above
logger:
zapLogger:
ref: zap-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
eventLogger:
ref: event-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
zapLogger: zap-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
eventLogger: event-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
interceptors:
loggingZap:
enabled: true # Optional, default: false
Expand Down
31 changes: 25 additions & 6 deletions example/boot/full/boot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
# maxbackups: 3 # Optional, default: 3 (days)
# localtime: true # Optional, default: true
# compress: true # Optional, default: true
# loki:
# enabled: true # Optional, default: false
# addr: localhost:3100 # Optional, default: localhost:3100
# path: /loki/api/v1/push # Optional, default: /loki/api/v1/push
# username: "" # Optional, default: ""
# password: "" # Optional, default: ""
# maxBatchWaitMs: 3000 # Optional, default: 3000
# maxBatchSize: 1000 # Optional, default: 1000
# insecureSkipVerify: false # Optional, default: false
# labels: # Optional, default: empty map
# my_label_key: my_label_value
#eventLogger:
# - name: event-logger # Required
# encoding: "json" # Optional, default: console, options: [json, console]
Expand All @@ -55,6 +66,17 @@
# maxbackups: 3 # Optional, default: 3 (days)
# localtime: true # Optional, default: true
# compress: true # Optional, default: true
# loki:
# enabled: true # Optional, default: false
# addr: localhost:3100 # Optional, default: localhost:3100
# path: /loki/api/v1/push # Optional, default: /loki/api/v1/push
# username: "" # Optional, default: ""
# password: "" # Optional, default: ""
# maxBatchWaitMs: 3000 # Optional, default: 3000
# maxBatchSize: 1000 # Optional, default: 1000
# insecureSkipVerify: false # Optional, default: false
# labels: # Optional, default: empty map
# my_label_key: my_label_value
#cred:
# - name: "local-cred" # Required
# description: "Description of entry" # Optional
Expand Down Expand Up @@ -95,8 +117,7 @@ grpc:
# discardUnknown: false # Optional, default: false
# noRecvMsgSizeLimit: true # Optional, default: false
# gwMappingFilePaths: [] # Optional
# cert:
# ref: "local-cert" # Optional, default: "", reference of cert entry declared above
# certEntry: "local-cert" # Optional, default: "", reference of cert entry declared above
# sw:
# enabled: true # Optional, default: false
# path: "sw" # Optional, default: "sw"
Expand All @@ -123,10 +144,8 @@ grpc:
# cert: # Optional
# ref: "local-test" # Optional, default: "", reference of cert entry declared above
# logger:
# zapLogger:
# ref: zap-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# eventLogger:
# ref: event-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# zapLogger: zap-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# eventLogger: event-logger # Optional, default: logger of STDOUT, reference of logger entry declared above
# interceptors:
# loggingZap:
# enabled: true # Optional, default: false
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.1
github.com/prometheus/client_golang v1.10.0
github.com/rookie-ninja/rk-common v1.2.3
github.com/rookie-ninja/rk-entry v1.0.7
github.com/rookie-ninja/rk-logger v1.2.3
github.com/rookie-ninja/rk-query v1.2.4
github.com/rookie-ninja/rk-entry v1.0.8
github.com/rookie-ninja/rk-logger v1.2.7
github.com/rookie-ninja/rk-query v1.2.7
github.com/soheilhy/cmux v0.1.5
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v1.3.0
go.opentelemetry.io/otel/trace v1.3.0
go.uber.org/zap v1.16.0
go.uber.org/zap v1.20.0
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12
google.golang.org/grpc v1.42.0
Expand Down
Loading

0 comments on commit d9e6084

Please sign in to comment.