From f8ae391a5b7b506bb2f64547b9415fc9bf068913 Mon Sep 17 00:00:00 2001 From: kegsay Date: Tue, 13 Jul 2021 11:19:21 +0100 Subject: [PATCH] Expose more data when outputting output room events (#1916) * Add more logging for content fields * Fix fields --- roomserver/internal/input/input.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go index 6bc43c9cd..de40e133d 100644 --- a/roomserver/internal/input/input.go +++ b/roomserver/internal/input/input.go @@ -30,9 +30,16 @@ import ( "github.com/matrix-org/gomatrixserverlib" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" + "github.com/tidwall/gjson" "go.uber.org/atomic" ) +var keyContentFields = map[string]string{ + "m.room.join_rules": "join_rule", + "m.room.history_visibility": "history_visibility", + "m.room.member": "membership", +} + type Inputer struct { DB storage.Database Producer sarama.SyncProducer @@ -95,15 +102,27 @@ func (r *Inputer) WriteOutputEvents(roomID string, updates []api.OutputEvent) er "type": updates[i].Type, }) if updates[i].NewRoomEvent != nil { + eventType := updates[i].NewRoomEvent.Event.Type() logger = logger.WithFields(log.Fields{ - "event_type": updates[i].NewRoomEvent.Event.Type(), + "event_type": eventType, "event_id": updates[i].NewRoomEvent.Event.EventID(), "adds_state": len(updates[i].NewRoomEvent.AddsStateEventIDs), "removes_state": len(updates[i].NewRoomEvent.RemovesStateEventIDs), "send_as_server": updates[i].NewRoomEvent.SendAsServer, "sender": updates[i].NewRoomEvent.Event.Sender(), }) - if updates[i].NewRoomEvent.Event.Type() == "m.room.server_acl" && updates[i].NewRoomEvent.Event.StateKeyEquals("") { + if updates[i].NewRoomEvent.Event.StateKey() != nil { + logger = logger.WithField("state_key", *updates[i].NewRoomEvent.Event.StateKey()) + } + contentKey := keyContentFields[eventType] + if contentKey != "" { + value := gjson.GetBytes(updates[i].NewRoomEvent.Event.Content(), contentKey) + if value.Exists() { + logger = logger.WithField("content_value", value.String()) + } + } + + if eventType == "m.room.server_acl" && updates[i].NewRoomEvent.Event.StateKeyEquals("") { ev := updates[i].NewRoomEvent.Event.Unwrap() defer r.ACLs.OnServerACLUpdate(ev) }