Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #230

Merged
merged 3 commits into from
Sep 3, 2023
Merged

Dev #230

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions config/logs/fluent-bit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[SERVICE]
Parsers_File parsers.conf
Daemon Off
Log_Level info
HTTP_Server off
HTTP_Listen 0.0.0.0
HTTP_Port 24224
[INPUT]
Name tail
Tag gugotik.*
Path /var/log/gugotik/*.log
Mem_Buf_Limit 10MB
DB /var/log/flt_logs.db
Refresh_Interval 5
Ignore_Older 10s
Rotate_Wait 5
[FILTER]
Name record_modifier
Match *
Key_name message
Record hostname ${HOSTNAME}
Record namespace gugotik
Record environment prod
[OUTPUT]
Name es
Match *
Host [YOUR HOST]
Port 9200
Logstash_Format On
Retry_Limit False
Time_Key @timestamp
Logstash_Prefix gugotik
6 changes: 6 additions & 0 deletions config/logs/parsers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[PARSER]
Name docker
Format json
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%SZ
Time_Keep On
7 changes: 7 additions & 0 deletions config/logs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Log Solution

GuGoTik 支持以 Fluent-bit 以 Sidecar 模式收集日志,目录中为推荐配置方案,开箱即用。

# Use

请根据需要自行更改 ES 的用户账号和密码等
78 changes: 51 additions & 27 deletions manifests-endymx/deployment-auth-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,56 @@ spec:
dream-unit: gugotik-auth-service
spec:
imagePullSecrets:
- name: regcred
- name: regcred
containers:
- image: ${IMAGE}
imagePullPolicy: IfNotPresent
name: gugotik-auth-service
command:
- ./services/auth/AuthService
envFrom:
- configMapRef:
name: env-config
- configMapRef:
name: gugotik-env
- secretRef:
name: gugotik-secret
ports:
- name: grpc-37001
containerPort: 37001
protocol: TCP
- name: metrics-37099
containerPort: 37099
protocol: TCP
resources:
limits:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 100m
memory: 128Mi
- image: ${IMAGE}
imagePullPolicy: IfNotPresent
name: gugotik-auth-service
command:
- ./services/auth/AuthService
envFrom:
- configMapRef:
name: env-config
- configMapRef:
name: gugotik-env
- secretRef:
name: gugotik-secret
ports:
- name: grpc-37001
containerPort: 37001
protocol: TCP
- name: metrics-37099
containerPort: 37099
protocol: TCP
volumeMounts:
- mountPath: /var/log/gugotik
name: log-volume
resources:
limits:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 100m
memory: 128Mi
- name: logger
image: fluent/fluent-bit:1.8.4
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 20m
memory: 100Mi
limits:
cpu: 100m
memory: 200Mi
volumeMounts:
- mountPath: /fluent-bit/etc
name: gugotik-log-config
- mountPath: /var/log/gugotik
name: log-volume
volumes:
- name: config
configMap:
name: fluentbit-config
- name: log-volume
emptyDir: { }
terminationGracePeriodSeconds: 30
17 changes: 16 additions & 1 deletion src/utils/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"io"
"os"
"path"
)

var hostname string
Expand All @@ -29,9 +31,22 @@ func init() {
case "TRACE":
log.SetLevel(log.TraceLevel)
}
log.SetOutput(os.Stdout)

filePath := path.Join("var", "log", "gugotik", "gugotik.log")
dir := path.Dir(filePath)
if err := os.MkdirAll(dir, os.FileMode(0755)); err != nil {
panic(err)
}

f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
panic(err)
}

log.SetFormatter(&log.JSONFormatter{})
log.AddHook(logTraceHook{})
log.SetOutput(io.MultiWriter(f, os.Stdout))

Logger = log.WithFields(log.Fields{
"Tied": config.EnvCfg.TiedLogging,
"Hostname": hostname,
Expand Down