Skip to content

Commit

Permalink
event
Browse files Browse the repository at this point in the history
  • Loading branch information
nkonev committed Jan 5, 2025
1 parent fbe81df commit b5418d3
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 182 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ services:
- ./chat/logs:/var/log/videochat/chat/logs:z
- ./storage/logs:/var/log/videochat/storage/logs:z
- ./video/logs:/var/log/videochat/video/logs:z
- ./event/logs:/var/log/videochat/event/logs:z
- ./notification/logs:/var/log/videochat/notification/logs:z
- ./public/logs:/var/log/videochat/public/logs:z
networks:
Expand Down
5 changes: 5 additions & 0 deletions docker/fluent-bit/etc/fluent-bit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
path /var/log/videochat/video/logs/*.log
Tag videochat.app.golang.video

[INPUT]
Name tail
path /var/log/videochat/event/logs/*.log
Tag videochat.app.golang.event

[INPUT]
Name tail
path /var/log/videochat/notification/logs/*.log
Expand Down
3 changes: 3 additions & 0 deletions event/app/name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package app

const APP_NAME = "event"
29 changes: 14 additions & 15 deletions event/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"encoding/json"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
"io/ioutil"
"net/http"
"nkonev.name/event/dto"
. "nkonev.name/event/logger"
"nkonev.name/event/logger"
"nkonev.name/event/utils"
"strings"
)
Expand All @@ -27,10 +26,10 @@ type RestClient struct {
requestForOnlinePath string
userExtendedPath string
tracer trace.Tracer
lgr *log.Logger
lgr *logger.Logger
}

func NewRestClient(lgr *log.Logger) *RestClient {
func NewRestClient(lgr *logger.Logger) *RestClient {
tr := &http.Transport{
MaxIdleConns: viper.GetInt("http.maxIdleConns"),
IdleConnTimeout: viper.GetDuration("http.idleConnTimeout"),
Expand Down Expand Up @@ -58,7 +57,7 @@ func (h *RestClient) CheckAccess(c context.Context, userId int64, chatId int64)

req, err := http.NewRequest("GET", url, nil)
if err != nil {
GetLogEntry(c, h.lgr).Error(err, "Error during create GET")
h.lgr.WithTracing(c).Errorw("Error during create GET", err)
return false, err
}

Expand All @@ -68,7 +67,7 @@ func (h *RestClient) CheckAccess(c context.Context, userId int64, chatId int64)

response, err := h.client.Do(req)
if err != nil {
GetLogEntry(c, h.lgr).Error(err, "Transport error during checking access")
h.lgr.WithTracing(c).Errorw("Transport error during checking access", err)
return false, err
}
defer response.Body.Close()
Expand All @@ -78,7 +77,7 @@ func (h *RestClient) CheckAccess(c context.Context, userId int64, chatId int64)
return false, nil
} else {
err := errors.New("Unexpected status on checkAccess")
GetLogEntry(c, h.lgr).Error(err, "Unexpected status on checkAccess", "httpCode", response.StatusCode)
h.lgr.WithTracing(c).Errorw("Unexpected status on checkAccess", err, "httpCode", response.StatusCode)
return false, err
}
}
Expand All @@ -95,7 +94,7 @@ func (h *RestClient) AskForUserOnline(c context.Context, userIds []int64) {

req, err := http.NewRequest("PUT", url, nil)
if err != nil {
GetLogEntry(c, h.lgr).Error(err, "Error during create GET")
h.lgr.WithTracing(c).Errorw("Error during create GET", err)
return
}

Expand All @@ -105,15 +104,15 @@ func (h *RestClient) AskForUserOnline(c context.Context, userIds []int64) {

response, err := h.client.Do(req)
if err != nil {
GetLogEntry(c, h.lgr).Error(err, "Transport error during online.Request")
h.lgr.WithTracing(c).Errorw("Transport error during online.Request", err)
return
}
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
return
} else {
err := errors.New("Unexpected status on online.Request")
GetLogEntry(c, h.lgr).Error(err, "Unexpected status on online.Request", response.StatusCode)
h.lgr.WithTracing(c).Errorw("Unexpected status on online.Request", err, response.StatusCode)
return
}
}
Expand All @@ -124,7 +123,7 @@ func (h *RestClient) GetUserExtended(c context.Context, userId int64, behalfUser

req, err := http.NewRequest("GET", url, nil)
if err != nil {
GetLogEntry(c, h.lgr).Error(err, "Error during create GET")
h.lgr.WithTracing(c).Errorw("Error during create GET", err)
return nil, err
}

Expand All @@ -134,24 +133,24 @@ func (h *RestClient) GetUserExtended(c context.Context, userId int64, behalfUser

response, err := h.client.Do(req)
if err != nil {
GetLogEntry(c, h.lgr).Error(err, "Transport error during user.Extended")
h.lgr.WithTracing(c).Errorw("Transport error during user.Extended", err)
return nil, err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
err := errors.New("Unexpected status on user.Extended")
GetLogEntry(c, h.lgr).Error(err, "Unexpected status on user.Extended", response.StatusCode)
h.lgr.WithTracing(c).Errorw("Unexpected status on user.Extended", err, response.StatusCode)
return nil, err
}
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
GetLogEntry(c, h.lgr).Errorln("Failed to decode get users response:", err)
h.lgr.WithTracing(c).Errorln("Failed to decode get users response:", err)
return nil, err
}

user := &dto.UserAccountExtended{}
if err := json.Unmarshal(bodyBytes, user); err != nil {
GetLogEntry(c, h.lgr).Errorln("Failed to parse extended user:", err)
h.lgr.WithTracing(c).Errorln("Failed to parse extended user:", err)
return nil, err
}
return user, nil
Expand Down
3 changes: 3 additions & 0 deletions event/config/config-dev/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ server:

logger:
level: INFO
dir: "logs"
filename: "file.log"
writeToFile: true

# Rest client
http:
Expand Down
14 changes: 8 additions & 6 deletions event/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"errors"
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"log"
"nkonev.name/event/app"
"strings"
)

//go:embed config-dev
Expand All @@ -22,28 +24,28 @@ func InitViper() {
viper.SetConfigType("yaml")

if applyBaseConfig {
log.Info("Applying base config")
log.Printf("Applying base config")
if embedBytes, err := configDev.ReadFile("config-dev/config.yml"); err != nil {
panic(fmt.Errorf("Fatal error during reading embedded config file: %s \n", err))
} else if err := viper.ReadConfig(bytes.NewBuffer(embedBytes)); err != nil {
panic(fmt.Errorf("Fatal error during viper reading embedded config file: %s \n", err))
}
} else {
log.Info("Not applying base config")
log.Printf("Not applying base config")
}

if err := viper.MergeInConfig(); err != nil {
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
log.Infof("Override config file is not found, overrideConfigPath=%v", overrideConfigPath)
log.Printf("Override config file is not found, overrideConfigPath=%v", overrideConfigPath)
} else {
// Handle errors reading the config file
panic(fmt.Errorf("Fatal error during reading user config file: %s \n", err))
}
} else {
log.Infof("Override config file successfully merged, overrideConfigPath=%v", overrideConfigPath)
log.Printf("Override config file successfully merged, overrideConfigPath=%v", overrideConfigPath)
}

viper.SetEnvPrefix("EVENT")
viper.SetEnvPrefix(strings.ToUpper(app.APP_NAME))
viper.AutomaticEnv()
// Find and read the config file
}
6 changes: 2 additions & 4 deletions event/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/guregu/null v4.0.0+incompatible
github.com/labstack/echo/v4 v4.12.0
github.com/montag451/go-eventbus v0.0.0-20220923162824-015489a65e6a
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.7.0
github.com/streadway/amqp v1.0.0
github.com/vektah/gqlparser/v2 v2.5.11
Expand All @@ -22,6 +21,7 @@ require (
go.opentelemetry.io/otel/sdk v1.26.0
go.opentelemetry.io/otel/trace v1.26.0
go.uber.org/fx v1.12.0
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.63.2
)

Expand Down Expand Up @@ -57,9 +57,8 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/dig v1.9.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.17.0 // indirect
Expand All @@ -75,7 +74,6 @@ require (
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
)

go 1.22
17 changes: 4 additions & 13 deletions event/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/99designs/gqlgen v0.17.46 h1:Dk/pSCMVp57z/vd6gwZ/wmqbPOL3i5iz4YQHTDfxyuw=
github.com/99designs/gqlgen v0.17.46/go.mod h1:qRtiAeVPgkBBSPzZtoZXRRl5WkNrUTpp1OeVt61TmGU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
Expand Down Expand Up @@ -213,8 +211,6 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -287,8 +283,6 @@ go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IO
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/dig v1.9.0 h1:pJTDXKEhRqBI8W7rU7kwT5EgyRZuSMVSFcZolOvKK9U=
go.uber.org/dig v1.9.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
go.uber.org/fx v1.12.0 h1:+1+3Cz9M0dFMPy9SW9XUIUHye8bnPUm7q7DroNGWYG4=
Expand All @@ -298,11 +292,12 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -374,7 +369,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
Expand Down Expand Up @@ -409,7 +403,6 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191114200427-caa0b0f7d508/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
Expand Down Expand Up @@ -465,6 +458,4 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
4 changes: 2 additions & 2 deletions event/graph/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package graph

import (
"github.com/montag451/go-eventbus"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/trace"
"nkonev.name/event/client"
"nkonev.name/event/logger"
)

// This file will not be regenerated automatically.
Expand All @@ -17,5 +17,5 @@ type Resolver struct {
Bus *eventbus.Bus
HttpClient *client.RestClient
Tr trace.Tracer
Lgr *log.Logger
Lgr *logger.Logger
}
Loading

0 comments on commit b5418d3

Please sign in to comment.