Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated methods #129

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Login to quay.io Docker Image Registry
uses: docker/login-action@v1
with:
registry: quay.io
username: "${{ secrets.QUAY_USER }}"
password: "${{ secrets.QUAY_PASS }}"
- run: make docker docker-publish
env:
DOCKER_IMAGE_TAG: ${{ github.event.release.tag_name }}
- run: make docker docker-publish
env:
DOCKER_IMAGE_TAG: latest
- uses: actions/setup-go@v2
with:
go-version: 1.19.x
- uses: actions/checkout@v2
- name: Login to quay.io Docker Image Registry
uses: docker/login-action@v1
with:
registry: quay.io
username: "${{ secrets.QUAY_USER }}"
password: "${{ secrets.QUAY_PASS }}"
- run: make docker docker-publish
env:
DOCKER_IMAGE_TAG: ${{ github.event.release.tag_name }}
- run: make docker docker-publish
env:
DOCKER_IMAGE_TAG: latest
7 changes: 4 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v2
with:
go-version-file: 'go.mod'
go-version: 1.19.x
- uses: actions/checkout@v2
- run: make
env:
GO111MODULE: "on"
GOBIN: "/tmp/bin"
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ run:

linters:
enable:
- golint
- revive

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
Expand Down
3 changes: 1 addition & 2 deletions cmd/jiralert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {

flag.Parse()

var logger = setupLogger(*logLevel, *logFormat)
logger := setupLogger(*logLevel, *logFormat)
level.Info(logger).Log("msg", "starting JIRAlert", "version", Version)

if !*hashJiraLabel {
Expand Down Expand Up @@ -133,7 +133,6 @@ func main() {
return
}
requestTotal.WithLabelValues(conf.Name, "200").Inc()

})

http.HandleFunc("/", HomeHandlerFunc())
Expand Down
14 changes: 6 additions & 8 deletions cmd/jiralert/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ package main

import "github.com/prometheus/client_golang/prometheus"

var (
requestTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "jiralert_requests_total",
Help: "Requests processed, by receiver and status code.",
},
[]string{"receiver", "code"},
)
var requestTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "jiralert_requests_total",
Help: "Requests processed, by receiver and status code.",
},
[]string{"receiver", "code"},
)

func init() {
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/prometheus-community/jiralert
go 1.19

require (
github.com/andygrunwald/go-jira v1.16.0
github.com/andygrunwald/go-jira v1.15.1
github.com/go-kit/log v0.2.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.13.0
Expand All @@ -19,14 +19,14 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
21 changes: 9 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/andygrunwald/go-jira v1.16.0 h1:PU7C7Fkk5L96JvPc6vDVIrd99vdPnYudHu4ju2c2ikQ=
github.com/andygrunwald/go-jira v1.16.0/go.mod h1:UQH4IBVxIYWbgagc0LF/k9FRs9xjIiQ8hIcC6HfLwFU=
github.com/andygrunwald/go-jira v1.15.1 h1:6J9aYKb9sW8bxv3pBLYBrs0wdsFrmGI5IeTgWSKWKc8=
github.com/andygrunwald/go-jira v1.15.1/go.mod h1:GIYN1sHOIsENWUZ7B4pDeT/nxEtrZpE8l0987O67ZR8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -78,8 +78,8 @@ github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNV
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog=
github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -120,8 +120,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -158,9 +158,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM=
github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
Expand All @@ -184,9 +183,8 @@ github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
Expand Down Expand Up @@ -342,9 +340,8 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 h1:AzgQNqF+FKwyQ5LbVrVqOcuuFB67N47F9+htZYH0wFM=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func LoadFile(filename string, logger log.Logger) (*Config, []byte, error) {
// expand env variables $(var) from the config file
// taken from https://github.dev/thanos-io/thanos/blob/296c4ab4baf2c8dd6abdf2649b0660ac77505e63/pkg/reloader/reloader.go#L445-L462 by https://github.com/fabxc
func substituteEnvVars(b []byte, logger log.Logger) (r []byte, err error) {
var envRe = regexp.MustCompile(`\$\(([a-zA-Z_0-9]+)\)`)
envRe := regexp.MustCompile(`\$\(([a-zA-Z_0-9]+)\)`)
r = envRe.ReplaceAllFunc(b, func(n []byte) []byte {
if err != nil {
return nil
Expand All @@ -92,7 +92,7 @@ func substituteEnvVars(b []byte, logger log.Logger) (r []byte, err error) {

v, ok := os.LookupEnv(string(n))
if !ok {
err = fmt.Errorf("Missing env variable: %q", n)
err = fmt.Errorf("missing env variable: %q", n)
return nil
}
return []byte(v)
Expand Down
27 changes: 12 additions & 15 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ func TestLoadFile(t *testing.T) {

require.NoError(t, err)
require.Equal(t, testConf, string(content))

}

// Checks if the env var substitution is happening correctly in the loaded file
func TestEnvSubstitution(t *testing.T) {

config := "user: $(JA_USER)"
os.Setenv("JA_USER", "user")

Expand All @@ -106,7 +104,6 @@ func TestEnvSubstitution(t *testing.T) {
config = "user: $(JA_MISSING)"
_, err = substituteEnvVars([]byte(config), log.NewNopLogger())
require.Error(t, err)

}

// A test version of the ReceiverConfig struct to create test yaml fixtures.
Expand Down Expand Up @@ -186,7 +183,6 @@ func TestRequiredReceiverConfigKeys(t *testing.T) {
}
configErrorTestRunner(t, config, test.errorMessage)
}

}

// Auth keys error scenarios.
Expand Down Expand Up @@ -352,7 +348,6 @@ func TestReceiverOverrides(t *testing.T) {
configValue := reflect.ValueOf(receiver).Elem().FieldByName(test.overrideField).Interface()
require.Equal(t, configValue, test.expectedValue)
}

}

// TODO(bwplotka, rporres). Add more tests:
Expand All @@ -366,11 +361,12 @@ func newReceiverTestConfig(mandatory []string, optional []string) *receiverTestC

for _, name := range mandatory {
var value reflect.Value
if name == "APIURL" {
switch name {
case "APIURL":
value = reflect.ValueOf("https://jiralert.atlassian.net")
} else if name == "ReopenDuration" {
case "ReopenDuration":
value = reflect.ValueOf("30d")
} else {
default:
value = reflect.ValueOf(name)
}

Expand All @@ -379,11 +375,12 @@ func newReceiverTestConfig(mandatory []string, optional []string) *receiverTestC

for _, name := range optional {
var value reflect.Value
if name == "AddGroupLabels" {
switch name {
case "AddGroupLabels":
value = reflect.ValueOf(true)
} else if name == "AutoResolve" {
case "AutoResolve":
value = reflect.ValueOf(&AutoResolve{State: "Done"})
} else {
default:
value = reflect.ValueOf(name)
}

Expand Down Expand Up @@ -418,8 +415,10 @@ func removeFromStrSlice(strSlice []string, element string) []string {
// Returns mandatory receiver fields to be used creating test config structs.
// It does not include PAT auth, those tests will be created separately.
func mandatoryReceiverFields() []string {
return []string{"Name", "APIURL", "User", "Password", "Project",
"IssueType", "Summary", "ReopenState", "ReopenDuration"}
return []string{
"Name", "APIURL", "User", "Password", "Project",
"IssueType", "Summary", "ReopenState", "ReopenDuration",
}
}

func TestAutoResolveConfigReceiver(t *testing.T) {
Expand All @@ -439,7 +438,6 @@ func TestAutoResolveConfigReceiver(t *testing.T) {
}

configErrorTestRunner(t, config, "bad config in receiver \"test\", 'auto_resolve' was defined with empty 'state' field")

}

func TestAutoResolveConfigDefault(t *testing.T) {
Expand All @@ -457,5 +455,4 @@ func TestAutoResolveConfigDefault(t *testing.T) {
}

configErrorTestRunner(t, config, "bad config in defaults section: state cannot be empty")

}
9 changes: 3 additions & 6 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package notify

import (
"bytes"
"crypto/sha512"
"fmt"
"github.com/andygrunwald/go-jira"
"io"
"reflect"
"strings"
"time"

"github.com/andygrunwald/go-jira"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
Expand Down Expand Up @@ -262,12 +261,11 @@ func toGroupTicketLabel(groupLabels alertmanager.KV, hashJiraLabel bool) string
// old default behavior
buf := bytes.NewBufferString("ALERT{")
for _, p := range groupLabels.SortedPairs() {
buf.WriteString(p.Name)
buf.WriteString(fmt.Sprintf("=%q,", p.Value))
fmt.Fprintf(buf, "%s=%q,", p.Name, p.Value)
}
buf.Truncate(buf.Len() - 1)
buf.WriteString("}")
return strings.Replace(buf.String(), " ", "", -1)
return strings.ReplaceAll(buf.String(), " ", "")
}

func (r *Receiver) search(project, issueLabel string) (*jira.Issue, bool, error) {
Expand Down Expand Up @@ -407,5 +405,4 @@ func (r *Receiver) doTransition(issueKey string, transitionState string) (bool,
}
}
return false, errors.Errorf("JIRA state %q does not exist or no transition possible for %s", r.conf.ReopenState, issueKey)

}
3 changes: 2 additions & 1 deletion pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type Template struct {
Expand All @@ -33,7 +34,7 @@ type Template struct {
var funcs = template.FuncMap{
"toUpper": strings.ToUpper,
"toLower": strings.ToLower,
"title": cases.Title,
"title": cases.Title(language.Und).String,
// join is equal to strings.Join but inverts the argument order
// for easier pipelining in templates.
"join": func(sep string, s []string) string {
Expand Down