From 886499b4fb804e295c47877b7f17775cd965c99a Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 21 Sep 2021 15:27:48 -0700 Subject: [PATCH 1/3] zulip: Treat unknown errors with a 10-second backoff. An unknown error (including an unauthorized error) would fall through with no calls to time.Sleep, resulting in hammering the server as quickly as possible. Add a 10-second sleep in the default error case. The heartbeat is left with no explicit sleep, but all other codepaths now contain one. --- bridge/zulip/zulip.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bridge/zulip/zulip.go b/bridge/zulip/zulip.go index e66558a216..4becbdc46d 100644 --- a/bridge/zulip/zulip.go +++ b/bridge/zulip/zulip.go @@ -125,6 +125,7 @@ func (b *Bzulip) handleQueue() error { b.Log.Debug("heartbeat received.") default: b.Log.Debugf("receiving error: %#v", err) + time.Sleep(time.Second * 10) } if err != nil { continue From 35b8f9350280c43779d59065e2ae0e5c70d6e490 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 21 Sep 2021 15:57:24 -0700 Subject: [PATCH 2/3] version: Move version information into a separate package. This will allow it to be accessed by other sections of the code. --- .github/workflows/development.yml | 6 +++--- .goreleaser.yml | 2 +- Dockerfile | 2 +- matterbridge.go | 10 ++++------ tgs.Dockerfile | 2 +- version/version.go | 6 ++++++ 6 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 version/version.go diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index ff7313cf3d..0f62c997e8 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -35,9 +35,9 @@ jobs: run: | mkdir -p output/{win,lin,arm,mac} VERSION=$(git describe --tags) - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64 - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64 + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64 + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64 - name: Upload linux 64-bit if: startsWith(matrix.go-version,'1.17') uses: actions/upload-artifact@v2 diff --git a/.goreleaser.yml b/.goreleaser.yml index 5af21a8542..c4f9064b2d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -22,7 +22,7 @@ builds: - 6 - 7 ldflags: - - -s -w -X main.githash={{.ShortCommit}} + - -s -w -X github.com/42wim/matterbridge/version.GitHash={{.ShortCommit}} archives: - diff --git a/Dockerfile b/Dockerfile index 8e2dded66a..6a2b86590b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:edge AS builder COPY . /go/src/matterbridge RUN apk --no-cache add go git \ && cd /go/src/matterbridge \ - && CGO_ENABLED=0 go build -mod vendor -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge + && CGO_ENABLED=0 go build -mod vendor -ldflags "-X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge FROM alpine RUN apk --no-cache add ca-certificates mailcap diff --git a/matterbridge.go b/matterbridge.go index b9b7d6d310..7ab29784cc 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -10,15 +10,13 @@ import ( "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/gateway" "github.com/42wim/matterbridge/gateway/bridgemap" + "github.com/42wim/matterbridge/version" "github.com/google/gops/agent" prefixed "github.com/matterbridge/logrus-prefixed-formatter" "github.com/sirupsen/logrus" ) var ( - version = "1.23.1-dev" - githash string - flagConfig = flag.String("conf", "matterbridge.toml", "config file") flagDebug = flag.Bool("debug", false, "enable debug") flagVersion = flag.Bool("version", false, "show version") @@ -28,7 +26,7 @@ var ( func main() { flag.Parse() if *flagVersion { - fmt.Printf("version: %s %s\n", version, githash) + fmt.Printf("version: %s %s\n", version.Release, version.GitHash) return } @@ -43,8 +41,8 @@ func main() { } } - logger.Printf("Running version %s %s", version, githash) - if strings.Contains(version, "-dev") { + logger.Printf("Running version %s %s", version.Release, version.GitHash) + if strings.Contains(version.Release, "-dev") { logger.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.") } diff --git a/tgs.Dockerfile b/tgs.Dockerfile index 83a77e734e..5badc0a72e 100644 --- a/tgs.Dockerfile +++ b/tgs.Dockerfile @@ -5,7 +5,7 @@ RUN apk add \ go \ git \ && cd /go/src/matterbridge \ - && go build -mod vendor -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge + && go build -mod vendor -ldflags "-X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge FROM alpine RUN apk --no-cache add \ diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000000..19f3fa3a6e --- /dev/null +++ b/version/version.go @@ -0,0 +1,6 @@ +package version + +var ( + Release = "1.23.1-dev" + GitHash string +) From c0f9acc705c2ce00c3aba729afdafd5b4fa982db Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 21 Sep 2021 15:57:44 -0700 Subject: [PATCH 3/3] zulip: Use the matterbridge version in the user-agent. --- bridge/zulip/zulip.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bridge/zulip/zulip.go b/bridge/zulip/zulip.go index 4becbdc46d..c912b6f0d4 100644 --- a/bridge/zulip/zulip.go +++ b/bridge/zulip/zulip.go @@ -2,6 +2,7 @@ package bzulip import ( "encoding/json" + "fmt" "io/ioutil" "strconv" "strings" @@ -11,6 +12,7 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" + "github.com/42wim/matterbridge/version" gzb "github.com/matterbridge/gozulipbot" ) @@ -27,7 +29,7 @@ func New(cfg *bridge.Config) bridge.Bridger { } func (b *Bzulip) Connect() error { - bot := gzb.Bot{APIKey: b.GetString("token"), APIURL: b.GetString("server") + "/api/v1/", Email: b.GetString("login")} + bot := gzb.Bot{APIKey: b.GetString("token"), APIURL: b.GetString("server") + "/api/v1/", Email: b.GetString("login"), UserAgent: fmt.Sprintf("matterbridge/%s", version.Release)} bot.Init() q, err := bot.RegisterAll() b.q = q