From 0ef2a3960d8aefa95f47a44a92b086912e34ccff Mon Sep 17 00:00:00 2001 From: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com> Date: Fri, 16 Sep 2022 16:30:31 -0700 Subject: [PATCH 1/2] Make the fix for #2718 the same as dendrite main (#31) Co-authored-by: Tak Wai Wong --- appservice/consumers/roomserver.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go index 381440f0f..a9e35a007 100644 --- a/appservice/consumers/roomserver.go +++ b/appservice/consumers/roomserver.go @@ -22,6 +22,7 @@ import ( "math" "net/http" "net/url" + "strconv" "time" "github.com/matrix-org/gomatrixserverlib" @@ -151,15 +152,25 @@ func (s *OutputRoomEventConsumer) onMessage( return true } + txnID := "" + // Try to get the message metadata, if we're able to, use the timestamp as the txnID + if len(msgs) > 0 { + metadata, err := msgs[0].Metadata() + if err == nil { + txnID = strconv.Itoa(int(metadata.Timestamp.UnixNano())) + } + } + // Send event to any relevant application services. If we hit // an error here, return false, so that we negatively ack. log.WithField("appservice", state.ID).Debugf("Appservice worker sending %d events(s) from roomserver", len(events)) - return s.sendEvents(ctx, state, events) == nil + return s.sendEvents(txnID, ctx, state, events) == nil } // sendEvents passes events to the appservice by using the transactions // endpoint. It will block for the backoff period if necessary. func (s *OutputRoomEventConsumer) sendEvents( + txnID string, ctx context.Context, state *appserviceState, events []*gomatrixserverlib.HeaderedEvent, ) error { @@ -173,10 +184,10 @@ func (s *OutputRoomEventConsumer) sendEvents( return err } - // If the number of items in the array is different, - // then this should be treated as a different transaction. Incorporate the length - // of events into the transaction ID. - txnID := fmt.Sprintf("%d_%d", events[0].Event.OriginServerTS(), len(transaction)) + // If txnID is not defined, generate one from the events. + if txnID == "" { + txnID = fmt.Sprintf("%d_%d", events[0].Event.OriginServerTS(), len(transaction)) + } // Send the transaction to the appservice. // https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-app-v1-transactions-txnid From 0fe5ea6c32ed4c822acd83ffafb3d8537c64f0f0 Mon Sep 17 00:00:00 2001 From: Brian Meek Date: Sat, 17 Sep 2022 14:10:36 -0700 Subject: [PATCH 2/2] After discovering the full path using the go nm tool, properly set the ReleaseVersion in the clientapi router Signed-off-by: Brian Meek --- build/docker/Dockerfile.monolith | 2 +- clientapi/routing/routing.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/build/docker/Dockerfile.monolith b/build/docker/Dockerfile.monolith index 2d75c8ac1..b3415171f 100644 --- a/build/docker/Dockerfile.monolith +++ b/build/docker/Dockerfile.monolith @@ -9,7 +9,7 @@ WORKDIR /build COPY . /build RUN mkdir -p bin -RUN go build -trimpath -o bin/ -ldflags="-X routing.ReleaseVersion=$RELEASE_VERSION" ./cmd/dendrite-monolith-server +RUN go build -trimpath -o bin/ -ldflags="-X 'github.com/matrix-org/dendrite/clientapi/routing.ReleaseVersion=$RELEASE_VERSION'" ./cmd/dendrite-monolith-server RUN go build -trimpath -o bin/ ./cmd/create-account RUN go build -trimpath -o bin/ ./cmd/generate-keys diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index de441b7d8..a06ef3c12 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -64,6 +64,11 @@ func Setup( extRoomsProvider api.ExtraPublicRoomsProvider, mscCfg *config.MSCs, natsClient *nats.Conn, ) { + + logrus.WithFields(logrus.Fields{ + "ReleaseVersion": ReleaseVersion, + }).Info("Started clientAPI router with ReleaseVersion") + prometheus.MustRegister(amtRegUsers, sendEventDuration) rateLimits := httputil.NewRateLimits(&cfg.RateLimiting)