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

Enh/advanced logging #1247

Merged
merged 35 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f294246
Minor changes in user-settings, still some errors in removing parts
SebiWrn Oct 27, 2023
1be7096
Added custom setting to add custom speeds for playback and implemente…
SebiWrn Oct 27, 2023
55a8a66
Full rewrite of the logging in the api folder
SebiWrn Nov 7, 2023
8f37cbc
Fixed a bug in statistics.go
SebiWrn Nov 7, 2023
2e7ee42
Changed logging in dao and tumlive
SebiWrn Nov 7, 2023
9e8ac85
Finished rewriting logs everywhere but in the worker
SebiWrn Nov 7, 2023
f7bd7ee
Minor changes in user-settings, still some errors in removing parts
SebiWrn Oct 27, 2023
f1469ca
Added custom setting to add custom speeds for playback and implemente…
SebiWrn Oct 27, 2023
c1aa427
Full rewrite of the logging in the api folder
SebiWrn Nov 7, 2023
b2b9f66
Fixed a bug in statistics.go
SebiWrn Nov 7, 2023
569e981
Changed logging in dao and tumlive
SebiWrn Nov 7, 2023
a769b47
Finished rewriting logs everywhere but in the worker
SebiWrn Nov 7, 2023
ff5ff2e
Added json logging to dao and in email.go, go upgraded to 1.21, added…
SebiWrn Nov 14, 2023
8ea5b36
Merge remote-tracking branch 'origin/enh/advanced-logging' into enh/a…
SebiWrn Nov 14, 2023
cdfe857
Merged locally
SebiWrn Nov 14, 2023
900c34a
Changed Dockerfile to work with multiple files in cmd/tumlive
SebiWrn Nov 19, 2023
b7174b0
Fixed a bug
SebiWrn Dec 7, 2023
e7523a0
Fixed a bug
SebiWrn Dec 7, 2023
c5a855d
Fixed some version things
SebiWrn Dec 13, 2023
0490691
Fixed build errors
SebiWrn Dec 13, 2023
ca9fb82
Fixed bug in worker
SebiWrn Dec 13, 2023
916cb8c
Fixed another bug
SebiWrn Dec 13, 2023
a9fc89d
Testing another change in go.work
SebiWrn Dec 13, 2023
9cbeedf
Updated go.sum
SebiWrn Dec 13, 2023
18ca21a
Fixed go.work
SebiWrn Dec 13, 2023
ee9fe8d
Updated to go 1.21.5
SebiWrn Dec 13, 2023
75c1d13
Removed autobuild
SebiWrn Dec 13, 2023
637968d
Added correct make targets to build
SebiWrn Dec 13, 2023
4377ed2
Fixed some more bugs
SebiWrn Dec 13, 2023
30995bd
Changed everything to 1.21 instead of 1.21.5
SebiWrn Dec 13, 2023
261bba3
Removed toolchain directive
SebiWrn Dec 13, 2023
3e29fa6
Added toolchain directive with new version
SebiWrn Dec 13, 2023
c7961af
Last try with toolchain directive
SebiWrn Dec 13, 2023
d7d3dd4
Fixed pipeline
SebiWrn Dec 13, 2023
fc3bda7
Reverted Dockerfile
SebiWrn Dec 18, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
# uses a compiled language

#- run: |
# make bootstrap
# make all
# make release

- name: Perform CodeQL Analysis
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.20.x ]
go-version: [ 1.21.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.21
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters:
fast: false

run:
go: '1.19'
go: '1.21'
timeout: 10m
skip-dirs:
- node_modules
Expand Down Expand Up @@ -67,7 +67,7 @@ linters-settings:
- name: modifies-value-receiver
gofumpt:
extra-rules: false
lang-version: "1.19"
lang-version: "1.21"

issues:
max-issues-per-linter: 0
Expand Down
8 changes: 0 additions & 8 deletions .idea/runConfigurations/all.xml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ docker run --detach \

### Install go

- Install **go >=1.18** by following the steps [here](https://go.dev/doc/install)
- Install **go >=1.21** by following the steps [here](https://go.dev/doc/install)
- Preferably use [JetBrains GoLand](https://youtu.be/vetAfxQxyJE) and open this project as it simplifies this entire process
- Go to File -> Settings -> Go -> Go Modules and enable go modules integration.
- Run `npm i` in the `./web` directory to install the required node modules
Expand Down
10 changes: 10 additions & 0 deletions api/api_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package api

import (
"log/slog"
"os"
)

var logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})).With("service", "api")
65 changes: 32 additions & 33 deletions api/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -65,7 +64,7 @@ func RegisterRealtimeChatChannel() {
req, err := parseChatPayload(message)

if err != nil {
log.WithError(err).Warn("could not unmarshal request")
logger.Warn("could not unmarshal request", "err", err)
return
}

Expand All @@ -89,7 +88,7 @@ func RegisterRealtimeChatChannel() {
case "react_to":
routes.handleReactTo(tumLiveContext, message.Payload)
default:
log.WithField("type", req.Type).Warn("unknown websocket request type")
logger.Warn("unknown websocket request type", "type", req.Type)
}
},
})
Expand Down Expand Up @@ -121,15 +120,15 @@ type chatRoutes struct {
func (r chatRoutes) handleSubmitPollOptionVote(ctx tools.TUMLiveContext, msg []byte) {
var req submitPollOptionVote
if err := json.Unmarshal(msg, &req); err != nil {
log.WithError(err).Warn("could not unmarshal submit poll answer request")
logger.Warn("could not unmarshal submit poll answer request", "err", err)
return
}
if ctx.User == nil {
return
}

if err := r.ChatDao.AddChatPollOptionVote(req.PollOptionId, ctx.User.ID); err != nil {
log.WithError(err).Warn("could not add poll option vote")
logger.Warn("could not add poll option vote", "err", err)
return
}

Expand All @@ -144,7 +143,7 @@ func (r chatRoutes) handleSubmitPollOptionVote(ctx tools.TUMLiveContext, msg []b
if voteUpdateJson, err := json.Marshal(voteUpdateMap); err == nil {
broadcastStreamToAdmins(ctx.Stream.ID, voteUpdateJson)
} else {
log.WithError(err).Warn("could not marshal vote update map")
logger.Warn("could not marshal vote update map", "err", err)
return
}
}
Expand All @@ -158,22 +157,22 @@ func (r chatRoutes) handleStartPoll(ctx tools.TUMLiveContext, msg []byte) {

var req startPollReq
if err := json.Unmarshal(msg, &req); err != nil {
log.WithError(err).Warn("could not unmarshal start poll request")
logger.Warn("could not unmarshal start poll request", "err", err)
return
}
if ctx.User == nil || !ctx.User.IsAdminOfCourse(*ctx.Course) {
return
}

if len(req.Question) == 0 {
log.Warn("could not create poll with empty question")
logger.Warn("could not create poll with empty question")
return
}

var pollOptions []model.PollOption
for _, answer := range req.PollAnswers {
if len(answer) == 0 {
log.Warn("could not create poll with empty answer")
logger.Warn("could not create poll with empty answer")
return
}
pollOptions = append(pollOptions, model.PollOption{
Expand Down Expand Up @@ -244,7 +243,7 @@ func (r chatRoutes) handleResolve(ctx tools.TUMLiveContext, msg []byte) {
var req wsIdReq
err := json.Unmarshal(msg, &req)
if err != nil {
log.WithError(err).Warn("could not unmarshal message delete request")
logger.Warn("could not unmarshal message delete request", "err", err)
return
}
if ctx.User == nil || !ctx.User.IsAdminOfCourse(*ctx.Course) {
Expand All @@ -253,15 +252,15 @@ func (r chatRoutes) handleResolve(ctx tools.TUMLiveContext, msg []byte) {

err = r.ChatDao.ResolveChat(req.Id)
if err != nil {
log.WithError(err).Error("could not delete chat")
logger.Error("could not delete chat", "err", err)
}

broadcast := gin.H{
"resolve": req.Id,
}
broadcastBytes, err := json.Marshal(broadcast)
if err != nil {
log.WithError(err).Error("could not marshal delete message")
logger.Error("could not marshal delete message", "err", err)
return
}
broadcastStream(ctx.Stream.ID, broadcastBytes)
Expand All @@ -271,22 +270,22 @@ func (r chatRoutes) handleDelete(ctx tools.TUMLiveContext, msg []byte) {
var req wsIdReq
err := json.Unmarshal(msg, &req)
if err != nil {
log.WithError(err).Warn("could not unmarshal message delete request")
logger.Warn("could not unmarshal message delete request", "err", err)
return
}
if ctx.User == nil || !ctx.User.IsAdminOfCourse(*ctx.Course) {
return
}
err = r.ChatDao.DeleteChat(req.Id)
if err != nil {
log.WithError(err).Error("could not delete chat")
logger.Error("could not delete chat", "err", err)
}
broadcast := gin.H{
"delete": req.Id,
}
broadcastBytes, err := json.Marshal(broadcast)
if err != nil {
log.WithError(err).Error("could not marshal delete message")
logger.Error("could not marshal delete message", "err", err)
return
}
broadcastStream(ctx.Stream.ID, broadcastBytes)
Expand All @@ -296,7 +295,7 @@ func (r chatRoutes) handleApprove(ctx tools.TUMLiveContext, msg []byte) {
var req wsIdReq
err := json.Unmarshal(msg, &req)
if err != nil {
log.WithError(err).Warn("could not unmarshal message approve request")
logger.Warn("could not unmarshal message approve request", "err", err)
return
}
if ctx.User == nil || !ctx.User.IsAdminOfCourse(*ctx.Course) {
Expand All @@ -305,7 +304,7 @@ func (r chatRoutes) handleApprove(ctx tools.TUMLiveContext, msg []byte) {

err = r.ChatDao.ApproveChat(req.Id)
if err != nil {
log.WithError(err).Error("could not approve chat")
logger.Error("could not approve chat", "err", err)
return
}

Expand All @@ -315,15 +314,15 @@ func (r chatRoutes) handleApprove(ctx tools.TUMLiveContext, msg []byte) {
*/
chat, err := r.ChatDao.GetChat(req.Id, 0)
if err != nil {
log.WithError(err).Error("could not get chat")
logger.Error("could not get chat", "err", err)
}
broadcast := gin.H{
"approve": req.Id,
"chat": chat,
}
broadcastBytes, err := json.Marshal(broadcast)
if err != nil {
log.WithError(err).Error("could not marshal approve message")
logger.Error("could not marshal approve message", "err", err)
return
}
broadcastStream(ctx.Stream.ID, broadcastBytes)
Expand All @@ -333,23 +332,23 @@ func (r chatRoutes) handleReactTo(ctx tools.TUMLiveContext, msg []byte) {
var req wsReactToReq
err := json.Unmarshal(msg, &req)
if err != nil {
log.WithError(err).Warn("could not unmarshal reactTo request")
logger.Warn("could not unmarshal reactTo request", "err", err)
return
}

if _, isAllowed := allowedReactions[req.Reaction]; !isAllowed {
log.Warn("user tried to add illegal reaction")
logger.Warn("user tried to add illegal reaction")
return
}

err = r.ChatDao.ToggleReaction(ctx.User.ID, req.wsIdReq.Id, ctx.User.Name, req.Reaction)
if err != nil {
log.WithError(err).Error("error reacting to message")
logger.Error("error reacting to message", "err", err)
return
}
reactions, err := r.ChatDao.GetReactions(req.Id)
if err != nil {
log.WithError(err).Error("error getting num of chat reactions")
logger.Error("error getting num of chat reactions", "err", err)
return
}
broadcast := gin.H{
Expand All @@ -358,7 +357,7 @@ func (r chatRoutes) handleReactTo(ctx tools.TUMLiveContext, msg []byte) {
}
broadcastBytes, err := json.Marshal(broadcast)
if err != nil {
log.WithError(err).Error("Can't marshal reactions message")
logger.Error("Can't marshal reactions message", "err", err)
return
}
broadcastStream(ctx.Stream.ID, broadcastBytes)
Expand All @@ -368,7 +367,7 @@ func (r chatRoutes) handleRetract(ctx tools.TUMLiveContext, msg []byte) {
var req wsIdReq
err := json.Unmarshal(msg, &req)
if err != nil {
log.WithError(err).Warn("could not unmarshal message retract request")
logger.Warn("could not unmarshal message retract request", "err", err)
return
}
if ctx.User == nil || !ctx.User.IsAdminOfCourse(*ctx.Course) {
Expand All @@ -377,27 +376,27 @@ func (r chatRoutes) handleRetract(ctx tools.TUMLiveContext, msg []byte) {

err = r.ChatDao.RetractChat(req.Id)
if err != nil {
log.WithError(err).Error("could not retract chat")
logger.Error("could not retract chat", "err", err)
return
}

err = r.ChatDao.RemoveReactions(req.Id)
if err != nil {
log.WithError(err).Error("could not remove reactions from chat")
logger.Error("could not remove reactions from chat", "err", err)
return
}

chat, err := r.ChatDao.GetChat(req.Id, 0)
if err != nil {
log.WithError(err).Error("could not get chat")
logger.Error("could not get chat", "err", err)
}
broadcast := gin.H{
"retract": req.Id,
"chat": chat,
}
broadcastBytes, err := json.Marshal(broadcast)
if err != nil {
log.WithError(err).Error("could not marshal retract message")
logger.Error("could not marshal retract message", "err", err)
return
}
broadcastStream(ctx.Stream.ID, broadcastBytes)
Expand All @@ -406,7 +405,7 @@ func (r chatRoutes) handleRetract(ctx tools.TUMLiveContext, msg []byte) {
func (r chatRoutes) handleMessage(ctx tools.TUMLiveContext, context *realtime.Context, msg []byte) {
var chat chatReq
if err := json.Unmarshal(msg, &chat); err != nil {
log.WithError(err).Error("error unmarshalling chat message")
logger.Error("error unmarshalling chat message", "err", err)
return
}
if !ctx.Course.ChatEnabled && !ctx.Stream.ChatEnabled {
Expand Down Expand Up @@ -578,7 +577,7 @@ func (r chatRoutes) getActivePoll(c *gin.Context) {
if isAdminOfCourse {
voteCount, err = r.ChatDao.GetPollOptionVoteCount(option.ID)
if err != nil {
log.WithError(err).Warn("could not get poll option vote count")
logger.Warn("could not get poll option vote count", "err", err)
}
}

Expand Down Expand Up @@ -681,7 +680,7 @@ func CollectStats(daoWrapper dao.DaoWrapper) func() {
if s.LiveNow { // store stats for livestreams only
s.Stats = append(s.Stats, stat)
if err := daoWrapper.AddStat(stat); err != nil {
log.WithError(err).Error("Saving stat failed")
logger.Error("Saving stat failed", "err", err)
}
}
}
Expand Down Expand Up @@ -734,7 +733,7 @@ func afterUnsubscribe(id string, joinTime time.Time, recording bool, daoWrapper
if recording && joinTime.Before(time.Now().Add(time.Minute*-5)) {
err := daoWrapper.AddVodView(id)
if err != nil {
log.WithError(err).Error("Can't save vod view")
logger.Error("Can't save vod view", "err", err)
}
}
}
Loading
Loading