diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3352f4110..d9e3e7f90 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -22,14 +22,14 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: go - run: make build - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/docker-feature.yml b/.github/workflows/docker-feature.yml index addc281f5..2f81186cb 100644 --- a/.github/workflows/docker-feature.yml +++ b/.github/workflows/docker-feature.yml @@ -16,7 +16,7 @@ jobs: if: ${{github.event.issue.pull_request != null && startsWith(github.event.comment.body, '/build') && github.event.comment.author_association == 'MEMBER'}} steps: - name: Get PR branch - uses: xt0rted/pull-request-comment-branch@v1 + uses: xt0rted/pull-request-comment-branch@v2 id: comment-branch - uses: actions/github-script@v6 @@ -38,7 +38,7 @@ jobs: - name: Checkout PR branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }} ref: ${{ fromJSON(steps.get-pr.outputs.result).head.sha }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7c60ca843..8ce1afaa0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,14 +7,14 @@ jobs: name: lint runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: version: v1.56.2 diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml index f64dfcb8c..c369b72b4 100644 --- a/.github/workflows/publish-packages.yml +++ b/.github/workflows/publish-packages.yml @@ -10,7 +10,7 @@ jobs: name: Create Release runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby 3.3 uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/swagger-delete.yml b/.github/workflows/swagger-delete.yml index 63f4e5c44..cb816dfa0 100644 --- a/.github/workflows/swagger-delete.yml +++ b/.github/workflows/swagger-delete.yml @@ -13,10 +13,10 @@ jobs: name: Delete api from SwaggerHub runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: '16.16.0' + node-version: '20.17.0' - run: npm i --location=global swaggerhub-cli - run: | VERSION=`echo ${GITHUB_REF_NAME}| sed 's#[^a-zA-Z0-9_\.\-]#_#g'` diff --git a/.github/workflows/swagger-publish.yml b/.github/workflows/swagger-publish.yml index 03e623c36..306bca3b9 100644 --- a/.github/workflows/swagger-publish.yml +++ b/.github/workflows/swagger-publish.yml @@ -15,7 +15,7 @@ jobs: working-directory: . steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: @@ -23,9 +23,9 @@ jobs: cache-dependency-path: go.sum - run: make install-swag - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: - node-version: '16.16.0' + node-version: '20.17.0' - run: npm install --location=global @openapitools/openapi-generator-cli - run: make spec - run: make validate-spec @@ -45,10 +45,10 @@ jobs: working-directory: . steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download spec file artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4.1.7 with: name: specfile path: docs diff --git a/.github/workflows/swagger-validate.yml b/.github/workflows/swagger-validate.yml index e4cb03f0c..ac392ad7f 100644 --- a/.github/workflows/swagger-validate.yml +++ b/.github/workflows/swagger-validate.yml @@ -12,7 +12,7 @@ jobs: working-directory: . steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: @@ -20,9 +20,9 @@ jobs: cache-dependency-path: go.sum - run: make install-swag - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: - node-version: '20.11.0' + node-version: '20.17.0' - run: npm install --location=global @openapitools/openapi-generator-cli - run: make spec - run: make validate-spec diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6bfc03317..7fe8c6f09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: ports: - 6379:6379 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: diff --git a/Makefile b/Makefile index a8a46d544..a21c97a18 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ mock: .PHONY: install-swag install-swag: - go install github.com/swaggo/swag/cmd/swag@v1.8.12 + go install github.com/swaggo/swag/cmd/swag@v1.16.3 .PHONY: spec spec: diff --git a/cmd/config.go b/cmd/config.go index bb83ea439..0d033cf76 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -60,18 +60,20 @@ type RedisConfig struct { // GetSettings returns redis config parsed from moira config files. func (config *RedisConfig) GetSettings() redis.DatabaseConfig { return redis.DatabaseConfig{ - MasterName: config.MasterName, - Addrs: strings.Split(config.Addrs, ","), - Username: config.Username, - Password: config.Password, - MaxRetries: config.MaxRetries, - MetricsTTL: to.Duration(config.MetricsTTL), - DialTimeout: to.Duration(config.DialTimeout), - ReadTimeout: to.Duration(config.ReadTimeout), - WriteTimeout: to.Duration(config.WriteTimeout), - ReadOnly: config.ReadOnly, - RouteByLatency: config.RouteByLatency, - RouteRandomly: config.RouteRandomly, + MasterName: config.MasterName, + Addrs: strings.Split(config.Addrs, ","), + Username: config.Username, + Password: config.Password, + SentinelUsername: config.SentinelUsername, + SentinelPassword: config.SentinelPassword, + MaxRetries: config.MaxRetries, + MetricsTTL: to.Duration(config.MetricsTTL), + DialTimeout: to.Duration(config.DialTimeout), + ReadTimeout: to.Duration(config.ReadTimeout), + WriteTimeout: to.Duration(config.WriteTimeout), + ReadOnly: config.ReadOnly, + RouteByLatency: config.RouteByLatency, + RouteRandomly: config.RouteRandomly, } } diff --git a/cmd/config_test.go b/cmd/config_test.go new file mode 100644 index 000000000..f41583d00 --- /dev/null +++ b/cmd/config_test.go @@ -0,0 +1,61 @@ +package cmd + +import ( + "testing" + "time" + + "github.com/moira-alert/moira/database/redis" + . "github.com/smartystreets/goconvey/convey" +) + +func TestRedisConfig(t *testing.T) { + Convey("Test RedisConfig.GetSettings", t, func() { + Convey("With empty config", func() { + redisCfg := RedisConfig{} + + expected := redis.DatabaseConfig{ + Addrs: []string{""}, + } + databaseCfg := redisCfg.GetSettings() + So(databaseCfg, ShouldResemble, expected) + }) + + Convey("With filled config", func() { + redisCfg := RedisConfig{ + MasterName: "test-master", + Addrs: "redis1:6379", + SentinelUsername: "sentinel-user", + SentinelPassword: "sentinel-pass", + Username: "user", + Password: "pass", + MetricsTTL: "1m", + DialTimeout: "1m", + ReadTimeout: "1m", + WriteTimeout: "1m", + MaxRetries: 3, + ReadOnly: true, + RouteByLatency: true, + RouteRandomly: true, + } + + expected := redis.DatabaseConfig{ + MasterName: "test-master", + Addrs: []string{"redis1:6379"}, + SentinelUsername: "sentinel-user", + SentinelPassword: "sentinel-pass", + Username: "user", + Password: "pass", + MetricsTTL: time.Minute, + DialTimeout: time.Minute, + ReadTimeout: time.Minute, + WriteTimeout: time.Minute, + MaxRetries: 3, + ReadOnly: true, + RouteByLatency: true, + RouteRandomly: true, + } + databaseCfg := redisCfg.GetSettings() + So(databaseCfg, ShouldResemble, expected) + }) + }) +} diff --git a/go.mod b/go.mod index 91857a6eb..c92f76c3e 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/prometheus/client_golang v1.14.0 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 - github.com/rs/cors v1.9.0 + github.com/rs/cors v1.11.0 github.com/rs/zerolog v1.29.0 github.com/russross/blackfriday/v2 v2.1.0 github.com/slack-go/slack v0.12.1 @@ -46,7 +46,6 @@ require ( require github.com/prometheus/common v0.37.0 require ( - github.com/golang/mock v1.6.0 github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/mattermost/mattermost/server/public v0.1.1 github.com/mitchellh/mapstructure v1.5.0 @@ -159,7 +158,7 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect - golang.org/x/image v0.13.0 // indirect + golang.org/x/image v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.17.0 // indirect golang.org/x/sys v0.21.0 // indirect diff --git a/go.sum b/go.sum index d95d23b39..089f98d54 100644 --- a/go.sum +++ b/go.sum @@ -680,7 +680,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -1081,8 +1080,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE= -github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po= +github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= @@ -1280,8 +1279,8 @@ golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXy golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.13.0 h1:3cge/F/QTkNLauhf2QoE9zp+7sr+ZcL4HnoZmdwg9sg= -golang.org/x/image v0.13.0/go.mod h1:6mmbMOeV28HuMTgA6OSRkdXKYw/t5W9Uwn2Yv1r3Yxk= +golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= +golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=