Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.0.2
version: v2.6.2
skip-cache: true
args: --timeout=5m --verbose
validate:
Expand Down
44 changes: 40 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ linters:
- nilnil
- nlreturn
- noctx
- noinlineerr
# TODO(bwplotka): Remove once https://github.com/golangci/golangci-lint/issues/3228 is fixed.
- nolintlint
- nonamedreturns
Expand All @@ -61,7 +62,36 @@ linters:
- wastedassign
- wrapcheck
- wsl
- wsl_v5
settings:
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
# Such cases aren't reported by default.
# Default: false
check-type-assertions: false
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
# Such cases aren't reported by default.
# Default: false
check-blank: false
# To disable the errcheck built-in exclude list.
# See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
# Default: false
disable-default-exclusions: false
# List of functions to exclude from checking, where each entry is a single function to exclude.
# See https://github.com/kisielk/errcheck#excluding-functions for details.
exclude-functions:
- fmt.Fprint
- fmt.Fprintf
- fmt.Fprintln
- fmt.Print
- fmt.Printf
- fmt.Println
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
# Display function signature instead of selector.
# Default: false
verbose: true
importas:
alias:
- pkg: k8s.io/api/apps/v1
Expand Down Expand Up @@ -167,11 +197,17 @@ linters:
severity: warning
disabled: true
- name: unhandled-error
arguments:
- fmt.Printf
- myFunction
severity: warning
disabled: true
disabled: false
exclude: [""]
arguments:
- "fmt.Fprint"
- "fmt.Fprintf"
- "fmt.Fprintln"
- "fmt.Print"
- "fmt.Printf"
- "fmt.Println"
- "strings.Builder.WriteByte"
- name: unused-receiver
arguments:
- allowRegex: ^_
Expand Down
5 changes: 2 additions & 3 deletions cmd/datasource-syncer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ func main() {

dsSuccessfullyUpdated := []string{}
dsErrors := []string{}
datasourceUIDs := strings.Split(*datasourceUIDList, ",")
for _, datasourceUID := range datasourceUIDs {
for datasourceUID := range strings.SplitSeq(*datasourceUIDList, ",") {
datasourceUID = strings.TrimSpace(datasourceUID)
if datasourceUID == "" {
continue
Expand Down Expand Up @@ -290,7 +289,7 @@ func buildUpdateDataSourceRequest(dataSource grafana.DataSource, token string) (
}
authHeaderValue := fmt.Sprintf("%s%d", httpHeaderValue, x)
if dataSource.SecureJSONData == nil {
dataSource.SecureJSONData = map[string]interface{}{}
dataSource.SecureJSONData = map[string]any{}
}
// Add token to SecureJSONData e.g. httpHeaderValue1: Bearer 123.
dataSource.SecureJSONData[authHeaderValue] = fmt.Sprintf("Bearer %s", token)
Expand Down
32 changes: 16 additions & 16 deletions cmd/datasource-syncer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
name: "OK",
input: grafana.DataSource{
Type: "prometheus",
JSONData: map[string]interface{}{},
JSONData: map[string]any{},
},
want: grafana.DataSource{
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "Authorization",
"httpMethod": "GET",
"prometheusType": "Prometheus",
"prometheusVersion": "2.40.0",
"queryTimeout": "2m",
"timeout": "120",
},
SecureJSONData: map[string]interface{}{
SecureJSONData: map[string]any{
"httpHeaderValue1": "Bearer 12345",
},
},
Expand All @@ -59,15 +59,15 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
input: grafana.DataSource{
URL: "http://localhost:9090",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "X-Custom-Header",
"httpHeaderName2": "X-Custom-Header2",
},
},
want: grafana.DataSource{
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "X-Custom-Header",
"httpHeaderName2": "X-Custom-Header2",
"httpHeaderName3": "Authorization",
Expand All @@ -77,7 +77,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
"queryTimeout": "2m",
"timeout": "120",
},
SecureJSONData: map[string]interface{}{
SecureJSONData: map[string]any{
"httpHeaderValue3": "Bearer 12345",
},
},
Expand All @@ -87,7 +87,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
input: grafana.DataSource{
URL: "http://localhost:9090",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "X-Custom-Header",
"httpHeaderName2": "Authorization",
"httpHeaderName3": "X-Custom-Header3",
Expand All @@ -99,7 +99,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
want: grafana.DataSource{
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "X-Custom-Header",
"httpHeaderName2": "Authorization",
"httpHeaderName3": "X-Custom-Header3",
Expand All @@ -109,7 +109,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
"queryTimeout": "2m",
"timeout": "120",
},
SecureJSONData: map[string]interface{}{
SecureJSONData: map[string]any{
"httpHeaderValue2": "Bearer 12345",
},
},
Expand All @@ -119,7 +119,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
input: grafana.DataSource{
Type: "prometheus",
URL: "http://localhost:9090",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "X-Custom-Header",
"httpHeaderName2": "X-Custom-Header2",
"httpHeaderName3": "Authorization",
Expand All @@ -131,7 +131,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
want: grafana.DataSource{
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "X-Custom-Header",
"httpHeaderName2": "X-Custom-Header2",
"httpHeaderName3": "Authorization",
Expand All @@ -141,7 +141,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
"queryTimeout": "2m",
"timeout": "120",
},
SecureJSONData: map[string]interface{}{
SecureJSONData: map[string]any{
"httpHeaderValue3": "Bearer 12345",
},
},
Expand All @@ -151,7 +151,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
input: grafana.DataSource{
Type: "prometheus",
URL: "http://localhost:9090",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"prometheusType": "Prometheus",
"prometheusVersion": "2.42.0",
"queryTimeout": "3m",
Expand All @@ -161,15 +161,15 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
want: grafana.DataSource{
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
Type: "prometheus",
JSONData: map[string]interface{}{
JSONData: map[string]any{
"httpHeaderName1": "Authorization",
"httpMethod": "GET",
"prometheusType": "Prometheus",
"prometheusVersion": "2.42.0",
"queryTimeout": "3m",
"timeout": "160",
},
SecureJSONData: map[string]interface{}{
SecureJSONData: map[string]any{
"httpHeaderValue1": "Bearer 12345",
},
},
Expand All @@ -188,7 +188,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
got, err := buildUpdateDataSourceRequest(tt.input, accessToken)
if tt.fail {
if err == nil {
t.Fatalf("unexpectedly succeeded")
t.Fatal("unexpectedly succeeded")
}
return
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
targetURLStr = flag.String("query.target-url", fmt.Sprintf("https://monitoring.googleapis.com/v1/projects/%s/location/global/prometheus", projectIDVar),
fmt.Sprintf("The URL to forward authenticated requests to. (%s is replaced with the --query.project-id flag.)", projectIDVar))

//nolint:revive // Allow insecure http connection
ruleEndpointURLStrings = flag.String("rules.target-urls", "http://rule-evaluator.gmp-system.svc.cluster.local:19092", "Comma separated lists of URLs that support HTTP Prometheus Alert and Rules APIs (/api/v1/alerts, /api/v1/rules), e.g. GMP rule-evaluator. NOTE: Results are merged as-is, no sorting and deduplication is done.")

logLevel = flag.String("log.level", "info",
Expand Down Expand Up @@ -126,7 +127,7 @@ func main() {
}

var ruleEndpointURLs []url.URL
for _, ruleEndpointURLStr := range strings.Split(*ruleEndpointURLStrings, ",") {
for ruleEndpointURLStr := range strings.SplitSeq(*ruleEndpointURLStrings, ",") {
ruleEndpointURL, err := url.Parse(strings.TrimSpace(ruleEndpointURLStr))
if err != nil || ruleEndpointURL == nil {
_ = level.Error(logger).Log("msg", "parsing rule endpoint URL failed", "err", err, "url", strings.TrimSpace(ruleEndpointURLStr))
Expand Down Expand Up @@ -187,11 +188,11 @@ func main() {

http.HandleFunc("/-/healthy", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Prometheus frontend is Healthy.\n")
fmt.Fprint(w, "Prometheus frontend is Healthy.\n")
})
http.HandleFunc("/-/ready", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Prometheus frontend is Ready.\n")
fmt.Fprint(w, "Prometheus frontend is Ready.\n")
})

http.Handle("/", authenticate(ui.Handler(externalURL)))
Expand Down
14 changes: 7 additions & 7 deletions cmd/rule-evaluator/internal/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ const (
// https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview
// response is the prometheus-compatible response format.
type response struct {
Status status `json:"status"`
Data interface{} `json:"data,omitempty"`
ErrorType errorType `json:"errorType,omitempty"`
Error string `json:"error,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Infos []string `json:"infos,omitempty"`
Status status `json:"status"`
Data any `json:"data,omitempty"`
ErrorType errorType `json:"errorType,omitempty"`
Error string `json:"error,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Infos []string `json:"infos,omitempty"`
}

// RuleRetriever provides a list of active rules.
Expand Down Expand Up @@ -102,7 +102,7 @@ func (api *API) writeResponse(w http.ResponseWriter, httpResponseCode int, endpo
}
}

func (api *API) writeSuccessResponse(w http.ResponseWriter, httpResponseCode int, endpointURI string, data interface{}) {
func (api *API) writeSuccessResponse(w http.ResponseWriter, httpResponseCode int, endpointURI string, data any) {
api.writeResponse(w, httpResponseCode, endpointURI, response{
Status: statusSuccess,
Data: data,
Expand Down
2 changes: 0 additions & 2 deletions cmd/rule-evaluator/internal/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func TestAPI_HandleRulesEndpoint(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt //nolint:copyloopvar // parallel test
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -480,7 +479,6 @@ func TestAPI_groupToAPIGroup(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt //nolint:copyloopvar // parallel test
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
api := &API{logger: log.NewNopLogger()}
Expand Down
7 changes: 4 additions & 3 deletions cmd/rule-evaluator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func main() {
})
http.HandleFunc("/-/ready", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "rule-evaluator is Ready.\n")
fmt.Fprintln(w, "rule-evaluator is Ready.")
})
// https://prometheus.io/docs/prometheus/latest/querying/api/#runtime-information
// Useful for knowing whether a config reload was successful.
Expand Down Expand Up @@ -685,7 +685,7 @@ func (m *configMetrics) setFailure() {
// reloadConfig applies the configuration files.
func reloadConfig(filename string, logger log.Logger, metrics *configMetrics, rls ...reloader) (err error) {
start := time.Now()
timings := []interface{}{}
timings := []any{}
_ = level.Info(logger).Log("msg", "Loading configuration file", "filename", filename)

content, err := os.ReadFile(filename)
Expand Down Expand Up @@ -713,7 +713,7 @@ func reloadConfig(filename string, logger log.Logger, metrics *configMetrics, rl
}

metrics.setSuccess()
l := []interface{}{"msg", "Completed loading of configuration file", "filename", filename, "totalDuration", time.Since(start)}
l := []any{"msg", "Completed loading of configuration file", "filename", filename, "totalDuration", time.Since(start)}
_ = level.Info(logger).Log(append(l, timings...)...)
return nil
}
Expand Down Expand Up @@ -853,6 +853,7 @@ func (s *queryStorage) Querier(mint, maxt int64) (storage.Querier, error) {
type queryAccess struct {
// storage.LabelQuerier satisfies the interface. Calling related methods will result in panic.
storage.LabelQuerier

api v1.API
mint int64
maxt int64
Expand Down
Loading