From 333a5c74c87111f44c5d2068d6ed651462d2d2b0 Mon Sep 17 00:00:00 2001 From: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:49:05 -0700 Subject: [PATCH 1/2] Temporary fix for appservice txnid (Dendrite issue #2718) (#29) * temporary fix for dendrite regression #2718 * Change comment to match with dendrite main pr * renamed zion-registration.yaml to zion-appservice.yaml. Change gitignore to ignore this file. Co-authored-by: Tak Wai Wong --- .gitignore | 1 + appservice/consumers/roomserver.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 820120c95..cbbf5981a 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ _testmain.go # Default configuration file dendrite.yaml +zion-appservice.yaml # Database files *.db diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go index a4bcfa7d9..381440f0f 100644 --- a/appservice/consumers/roomserver.go +++ b/appservice/consumers/roomserver.go @@ -173,13 +173,14 @@ func (s *OutputRoomEventConsumer) sendEvents( return err } - // TODO: We should probably be more intelligent and pick something not - // in the control of the event. A NATS timestamp header or something maybe. - txnID := events[0].Event.OriginServerTS() + // 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)) // Send the transaction to the appservice. // https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-app-v1-transactions-txnid - address := fmt.Sprintf("%s/transactions/%d?access_token=%s", state.URL, txnID, url.QueryEscape(state.HSToken)) + address := fmt.Sprintf("%s/transactions/%s?access_token=%s", state.URL, txnID, url.QueryEscape(state.HSToken)) req, err := http.NewRequestWithContext(ctx, "PUT", address, bytes.NewBuffer(transaction)) if err != nil { return err From f681e54bef745cb6d769615d56e2c36cca552955 Mon Sep 17 00:00:00 2001 From: Brian Meek Date: Thu, 15 Sep 2022 15:00:36 -0700 Subject: [PATCH 2/2] Add commit hash to routing version API Signed-off-by: Brian Meek --- build/docker/Dockerfile.monolith | 4 ++-- clientapi/routing/routing.go | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/build/docker/Dockerfile.monolith b/build/docker/Dockerfile.monolith index bb02934cd..0745f696e 100644 --- a/build/docker/Dockerfile.monolith +++ b/build/docker/Dockerfile.monolith @@ -1,4 +1,4 @@ -FROM docker.io/golang:1.18-alpine AS base +FROM docker.io/golang:1.19-alpine AS base RUN apk --update --no-cache add bash build-base @@ -7,7 +7,7 @@ WORKDIR /build COPY . /build RUN mkdir -p bin -RUN go build -trimpath -o bin/ ./cmd/dendrite-monolith-server +RUN go build -ldflags="-X 'routing.CommitHash=`git rev-list -1 HEAD`'" -trimpath -o bin/ ./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 b5c18fbd2..fa4793417 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -19,8 +19,6 @@ import ( "net/http" "strings" - "runtime/debug" - "github.com/gorilla/mux" appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/clientapi/api" @@ -43,16 +41,8 @@ import ( "github.com/sirupsen/logrus" ) -var commitHash = func() string { - if info, ok := debug.ReadBuildInfo(); ok { - for _, setting := range info.Settings { - if setting.Key == "vcs.revision" { - return setting.Value - } - } - } - return "" -}() +// Added in build script Cokerfile.monolith +var CommitHash string // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // to clients which need to make outbound HTTP requests. @@ -126,7 +116,7 @@ func Setup( "v1.0", "v1.1", "v1.2", - }, UnstableFeatures: unstableFeatures, CommitHash: commitHash}, + }, UnstableFeatures: unstableFeatures, CommitHash: CommitHash}, } }), ).Methods(http.MethodGet, http.MethodOptions)