Skip to content

Commit

Permalink
Merge pull request #228 from GuGoOrg/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
liaosunny123 authored Sep 2, 2023
2 parents 695e5e9 + ed176ec commit 7b1fa31
Show file tree
Hide file tree
Showing 39 changed files with 743 additions and 391 deletions.
11 changes: 8 additions & 3 deletions .env.docker.compose
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CONSUL_ADDR=consul:8500
CONSUL_ANONYMITY_NAME=paraparty.
# Configure logger level, support: DEBUG, INFO, WARN (WARNING), ERROR, FATAL
LOGGER_LEVEL=DEBUG
LOGGER_LEVEL=INFO
# Cofigure logger integrated with otel, support: enable, disable
# If this setting is enable, you will see log in the OTEL Export with possible runtime waste
LOGGER_OUT_TRACING=enable
Expand Down Expand Up @@ -41,13 +41,17 @@ REDIS_PASSWORD=
REDIS_DB=
REDIS_MASTER=
# Config Tracing EndPoint, support Jaeger
# Config state, if use `disable` the sampler will be closed. use `enable` to enable
TRACING_STATE=enable
# Config tracing sampler, suggest 0.01
TRACING_SAMPLER=0.01
TRACING_ENDPOINT=jaeger:4318
# Optional: Config Pyroscope
# Decide whether to enable the service, support : enable, disable.
# If you enable this service, you must provide Pyroscope server environment
# This profiling is ONLY designed for DEBUGGING
# SO, PLEASE DO NOT ENABLE THIS SERVICE IN YOUR PRODUCTION ENVIRONMENT, OR IT MAY TAKE MUCH RUNTIME COST.
PYROSCOPE_STATE=enable
PYROSCOPE_STATE=disbale
PYROSCOPE_ADDR=http://pyroscope:4040/
# Configure RabbitMQ
# Optional: `RABBITMQ_VHOST_PREFIX`: If you provide this config, the service will use value as the rabbit mq vhost prefix.
Expand All @@ -62,4 +66,5 @@ RABBITMQ_VHOST_PREFIX=
CHATGPT_API_KEYS=
# Gorse provides recommend service for GuGoTik.
GORSE_ADDR=http://gorse-server:8087
GORSE_APIKEY=5105502fc46a411c896aa5b50c31e951
GORSE_APIKEY=5105502fc46a411c896aa5b50c31e951
ANONYMITY_USER=50
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-auth-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-comment-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-event-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-favorite-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-feed-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-http-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-message-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-msg-consumer-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-publish-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
volumeMounts:
- mountPath: /data/apps/gugotik-service-bundle/data
name: volume
Expand Down
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-recommend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-relation-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
4 changes: 2 additions & 2 deletions manifests-endymx/deployment-user-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
cpu: 100m
memory: 128Mi
terminationGracePeriodSeconds: 30
6 changes: 3 additions & 3 deletions manifests-endymx/deployment-video-processor-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ spec:
protocol: TCP
resources:
limits:
cpu: 8000m
cpu: 4000m
memory: 8Gi
requests:
cpu: 4000m
memory: 4Gi
cpu: 100m
memory: 128Mi
volumeMounts:
- mountPath: /data/apps/gugotik-service-bundle/data
name: volume
Expand Down
8 changes: 7 additions & 1 deletion src/constant/config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ REDIS_PASSWORD=
REDIS_DB=
REDIS_MASTER=
# Config Tracing EndPoint, support Jaeger
# Config state, if use `disable` the sampler will be closed. use `enable` to enable
TRACING_STATE=
# Config tracing sampler, suggest 0.01
TRACING_SAMPLER=
TRACING_ENDPOINT=http://localhost:14268/api/traces
# Optional: Config Pyroscope
# Decide whether to enable the service, support : enable, disable.
Expand Down Expand Up @@ -77,4 +81,6 @@ GORSE_APIKEY=
# MagicUserId, please use output value
MAGIC_USER_ID=
# Configure your clash proxy
CHATGPT_PROXY=
CHATGPT_PROXY=
# Default anonymity user
ANONYMITY_USER=
79 changes: 41 additions & 38 deletions src/constant/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,47 @@ import (
var EnvCfg envConfig

type envConfig struct {
ConsulAddr string `env:"CONSUL_ADDR" envDefault:"localhost:8500"`
LoggerLevel string `env:"LOGGER_LEVEL" envDefault:"INFO"`
LoggerWithTraceState string `env:"LOGGER_OUT_TRACING" envDefault:"disable"`
TiedLogging string `env:"TIED" envDefault:"NONE"`
PostgreSQLHost string `env:"POSTGRESQL_HOST"`
PostgreSQLPort string `env:"POSTGRESQL_PORT"`
PostgreSQLUser string `env:"POSTGRESQL_USER"`
PostgreSQLPassword string `env:"POSTGRESQL_PASSWORD"`
PostgreSQLDataBase string `env:"POSTGRESQL_DATABASE"`
StorageType string `env:"STORAGE_TYPE" envDefault:"fs"`
FileSystemStartPath string `env:"FS_PATH" envDefault:"/tmp"`
FileSystemBaseUrl string `env:"FS_BASEURL" envDefault:"http://localhost/"`
RedisAddr string `env:"REDIS_ADDR"`
RedisPassword string `env:"REDIS_PASSWORD" envDefault:""`
RedisDB int `env:"REDIS_DB" envDefault:"0"`
TracingEndPoint string `env:"TRACING_ENDPOINT"`
PyroscopeState string `env:"PYROSCOPE_STATE" envDefault:"false"`
PyroscopeAddr string `env:"PYROSCOPE_ADDR"`
RedisPrefix string `env:"REDIS_PREFIX" envDefault:"GUGUTIK"`
PostgreSQLSchema string `env:"POSTGRESQL_SCHEMA"`
RedisMaster string `env:"REDIS_MASTER"`
ConsulAnonymityPrefix string `env:"CONSUL_ANONYMITY_NAME" envDefault:""`
RabbitMQUsername string `env:"RABBITMQ_USERNAME" envDefault:"guest"`
RabbitMQPassword string `env:"RABBITMQ_PASSWORD" envDefault:"guest"`
RabbitMQAddr string `env:"RABBITMQ_ADDRESS" envDefault:"localhost"`
RabbitMQPort string `env:"RABBITMQ_PORT" envDefault:"5672"`
RabbitMQVhostPrefix string `env:"RABBITMQ_VHOST_PREFIX" envDefault:""`
ChatGPTAPIKEYS string `env:"CHATGPT_API_KEYS"`
PodIpAddr string `env:"POD_IP" envDefault:"localhost"`
GorseAddr string `env:"GORSE_ADDR"`
GorseApiKey string `env:"GORSE_APIKEY"`
MagicUserId uint32 `env:"MAGIC_USER_ID" envDefault:"1"`
ChatGptProxy string `env:"CHATGPT_PROXY"`
PostgreSQLPrefix string `env:"POSTGRESQL_PREFIX" envDefault:""`
PostgreSQLReplicaState string `env:"POSTGRESQL_REPLICA"`
PostgreSQLReplicaAddress string `env:"POSTGRESQL_REPLICA_ADDR"`
PostgreSQLReplicaUsername string `env:"POSTGRESQL_REPLICA_USER"`
PostgreSQLReplicaPassword string `env:"POSTGRESQL_REPLICA_PASSWORD"`
ConsulAddr string `env:"CONSUL_ADDR" envDefault:"localhost:8500"`
LoggerLevel string `env:"LOGGER_LEVEL" envDefault:"INFO"`
LoggerWithTraceState string `env:"LOGGER_OUT_TRACING" envDefault:"disable"`
TiedLogging string `env:"TIED" envDefault:"NONE"`
PostgreSQLHost string `env:"POSTGRESQL_HOST"`
PostgreSQLPort string `env:"POSTGRESQL_PORT"`
PostgreSQLUser string `env:"POSTGRESQL_USER"`
PostgreSQLPassword string `env:"POSTGRESQL_PASSWORD"`
PostgreSQLDataBase string `env:"POSTGRESQL_DATABASE"`
StorageType string `env:"STORAGE_TYPE" envDefault:"fs"`
FileSystemStartPath string `env:"FS_PATH" envDefault:"/tmp"`
FileSystemBaseUrl string `env:"FS_BASEURL" envDefault:"http://localhost/"`
RedisAddr string `env:"REDIS_ADDR"`
RedisPassword string `env:"REDIS_PASSWORD" envDefault:""`
RedisDB int `env:"REDIS_DB" envDefault:"0"`
TracingEndPoint string `env:"TRACING_ENDPOINT"`
PyroscopeState string `env:"PYROSCOPE_STATE" envDefault:"false"`
PyroscopeAddr string `env:"PYROSCOPE_ADDR"`
RedisPrefix string `env:"REDIS_PREFIX" envDefault:"GUGUTIK"`
PostgreSQLSchema string `env:"POSTGRESQL_SCHEMA" envDefault:""`
RedisMaster string `env:"REDIS_MASTER"`
ConsulAnonymityPrefix string `env:"CONSUL_ANONYMITY_NAME" envDefault:""`
RabbitMQUsername string `env:"RABBITMQ_USERNAME" envDefault:"guest"`
RabbitMQPassword string `env:"RABBITMQ_PASSWORD" envDefault:"guest"`
RabbitMQAddr string `env:"RABBITMQ_ADDRESS" envDefault:"localhost"`
RabbitMQPort string `env:"RABBITMQ_PORT" envDefault:"5672"`
RabbitMQVhostPrefix string `env:"RABBITMQ_VHOST_PREFIX" envDefault:""`
ChatGPTAPIKEYS string `env:"CHATGPT_API_KEYS"`
PodIpAddr string `env:"POD_IP" envDefault:"localhost"`
GorseAddr string `env:"GORSE_ADDR"`
GorseApiKey string `env:"GORSE_APIKEY"`
MagicUserId uint32 `env:"MAGIC_USER_ID" envDefault:"1"`
ChatGptProxy string `env:"CHATGPT_PROXY"`
PostgreSQLPrefix string `env:"POSTGRESQL_PREFIX" envDefault:""`
PostgreSQLReplicaState string `env:"POSTGRESQL_REPLICA"`
PostgreSQLReplicaAddress string `env:"POSTGRESQL_REPLICA_ADDR"`
PostgreSQLReplicaUsername string `env:"POSTGRESQL_REPLICA_USER"`
PostgreSQLReplicaPassword string `env:"POSTGRESQL_REPLICA_PASSWORD"`
OtelState string `env:"TRACING_STATE" envDefault:"enable"`
OtelSampler float64 `env:"TRACING_SAMPLER" envDefault:"0.01"`
AnonymityUser string `env:"ANONYMITY_USER" envDefault:"114514"`
}

func init() {
Expand Down
2 changes: 2 additions & 0 deletions src/constant/strings/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ const (
ChatActionLimitedError = "发送消息频繁,请稍后再试!"
FollowLimitedCode = 10012
FollowLimited = "关注频繁,请稍后再试!"
UserDoNotExistedCode = 10013
UserDoNotExisted = "查询用户不存在!"
)
13 changes: 9 additions & 4 deletions src/constant/strings/service.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package strings

const (
// Exchange name
VideoExchange = "video_exchange"
EventExchange = "event"
MessageExchange = "message_exchange"

VideoPicker = "video_picker"
VideoSummary = "video_summary"
// Queue name
VideoPicker = "video_picker"
VideoSummary = "video_summary"
MessageCommon = "message_common"
MessageGPT = "message_gpt"

// Routing key
FavoriteActionEvent = "video.favorite.action"
VideoGetEvent = "video.get.action"
VideoCommentEvent = "video.comment.action"
VideoPublishEvent = "video.publish.action"

MessageActionEvent = "message.send"
MessageGptActionEvent = "message.gpt.send"
MessageActionEvent = "message.common"
MessageGptActionEvent = "message.gpt"
)
9 changes: 8 additions & 1 deletion src/extra/tracing/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func SetTraceProvider(name string) (*trace.TracerProvider, error) {
return nil, err
}

var sampler trace.Sampler
if config.EnvCfg.OtelState == "disable" {
sampler = trace.NeverSample()
} else {
sampler = trace.TraceIDRatioBased(config.EnvCfg.OtelSampler)
}

tp := trace.NewTracerProvider(
trace.WithBatcher(exporter),
trace.WithResource(
Expand All @@ -38,7 +45,7 @@ func SetTraceProvider(name string) (*trace.TracerProvider, error) {
semconv.ServiceNameKey.String(name),
),
),
trace.WithSampler(trace.AlwaysSample()),
trace.WithSampler(sampler),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
Expand Down
6 changes: 3 additions & 3 deletions src/services/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (a AuthServiceImpl) Login(ctx context.Context, request *auth.LoginRequest)
logger := logging.LogService("AuthService.Login").WithContext(ctx)
logger.WithFields(logrus.Fields{
"username": request.Username,
}).Infof("User try to log in.")
}).Debugf("User try to log in.")

// Check if a username might be in the filter
if !BloomFilter.TestString(request.Username) {
Expand Down Expand Up @@ -379,7 +379,7 @@ func (a AuthServiceImpl) Login(ctx context.Context, request *auth.LoginRequest)
logger.WithFields(logrus.Fields{
"token": token,
"userId": user.ID,
}).Infof("User log in sucess !")
}).Debugf("User log in sucess !")
resp = &auth.LoginResponse{
StatusCode: strings.ServiceOKCode,
StatusMsg: strings.ServiceOK,
Expand Down Expand Up @@ -411,7 +411,7 @@ func getToken(ctx context.Context, userId uint32) (string, error) {
logger := logging.LogService("AuthService.Login").WithContext(ctx)
logger.WithFields(logrus.Fields{
"userId": userId,
}).Infof("Select for user token")
}).Debugf("Select for user token")
return cached.GetWithFunc(ctx, "U2T"+strconv.FormatUint(uint64(userId), 10),
func(ctx context.Context, key string) (string, error) {
span := trace.SpanFromContext(ctx)
Expand Down
Loading

0 comments on commit 7b1fa31

Please sign in to comment.