Chore: Upgrade Go to 1.19.1 (#54902)

* WIP

* Set public_suffix to a pre Ruby 2.6 version

* we don't need to install python

* Stretch->Buster

* Bump versions in lib.star

* Manually update linter

Sort of messy, but the .mod-file need to contain all dependencies that
use 1.16+ features, otherwise they're assumed to be compiled with
-lang=go1.16 and cannot access generics et al.

Bingo doesn't seem to understand that, but it's possible to manually
update things to get Bingo happy.

* undo reformatting

* Various lint improvements

* More from the linter

* goimports -w ./pkg/

* Disable gocritic

* Add/modify linter exceptions

* lint + flatten nested list

Go 1.19 doesn't support nested lists, and there wasn't an obvious workaround.
https://go.dev/doc/comment#lists
This commit is contained in:
Emil Tullstedt
2022-09-12 12:03:49 +02:00
committed by GitHub
parent 5388dc6a2f
commit b287047052
91 changed files with 1018 additions and 1055 deletions
@@ -12,8 +12,9 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/tracing"
"go.opentelemetry.io/otel/attribute"
"github.com/grafana/grafana/pkg/infra/tracing"
)
func (timeSeriesFilter *cloudMonitoringTimeSeriesFilter) run(ctx context.Context, req *backend.QueryDataRequest,
@@ -82,7 +83,7 @@ func (timeSeriesFilter *cloudMonitoringTimeSeriesFilter) run(ctx context.Context
return dr, d, r.URL.RawQuery, nil
}
//nolint: gocyclo
//nolint:gocyclo
func (timeSeriesFilter *cloudMonitoringTimeSeriesFilter) parseResponse(queryRes *backend.DataResponse,
response cloudMonitoringResponse, executedQueryString string) error {
frames := data.Frames{}
+12 -12
View File
@@ -29,18 +29,18 @@ const (
//
// we also try to detect some often used patterns in the data,
// and make the data easier to graph in the browser for such cases:
// - if there is only one timestamp-column and it's named "_time",
// we will not add the labels to this data-column, because timestamp
// columns usually do not have labels in grafana.
// we use the `columnInfo.shouldGetLabels` attribute to handle this.
// - if there is only one timestamp-column and it's named "_time",
// and there is only one non-timestamp-column and it's named "_value",
// we rename "_time" to "Time" (using `columnInfo.isTheSimpleTime`),
// and we rename "_value" too (using `columnInfo.isTheSimpleValue`):
// if there is a tag called "_field" we use it's value as the name
// (because that's the usual approach in influxdb), and if there is not,
// we name it "Value". with these new names, they are more compatible
// with the visualizations in grafana.
// - if there is only one timestamp-column and it's named "_time",
// we will not add the labels to this data-column, because timestamp
// columns usually do not have labels in grafana.
// we use the `columnInfo.shouldGetLabels` attribute to handle this.
// - if there is only one timestamp-column and it's named "_time",
// and there is only one non-timestamp-column and it's named "_value",
// we rename "_time" to "Time" (using `columnInfo.isTheSimpleTime`),
// and we rename "_value" too (using `columnInfo.isTheSimpleValue`):
// if there is a tag called "_field" we use it's value as the name
// (because that's the usual approach in influxdb), and if there is not,
// we name it "Value". with these new names, they are more compatible
// with the visualizations in grafana.
type columnInfo struct {
name string
converter *data.FieldConverter
+1 -1
View File
@@ -156,7 +156,7 @@ func FormatDuration(inter time.Duration) string {
return "1ms"
}
//nolint: gocyclo
//nolint:gocyclo
func roundInterval(interval time.Duration) time.Duration {
switch {
// 0.01s
+1 -1
View File
@@ -146,7 +146,7 @@ func FormatDuration(inter time.Duration) string {
return "1ms"
}
//nolint: gocyclo
//nolint:gocyclo
func roundInterval(interval time.Duration) time.Duration {
switch {
// 0.015s
+1 -1
View File
@@ -33,7 +33,7 @@ func ProvideService(pluginsClient plugins.Client, oAuthTokenService oauthtoken.O
}
}
//nolint: staticcheck // legacydata.DataResponse deprecated
//nolint:staticcheck // legacydata.DataResponse deprecated
func (h *Service) HandleRequest(ctx context.Context, ds *datasources.DataSource, query legacydata.DataQuery) (legacydata.DataResponse, error) {
decryptedJsonData, err := h.dataSourcesService.DecryptedValues(ctx, ds)
if err != nil {
+1 -1
View File
@@ -189,7 +189,7 @@ func formatNamePrometheusStyle(labels map[string]string) string {
return fmt.Sprintf("{%s}", strings.Join(parts, ", "))
}
//If legend (using of name or pattern instead of time series name) is used, use that name/pattern for formatting
// If legend (using of name or pattern instead of time series name) is used, use that name/pattern for formatting
func formatName(labels map[string]string, query *lokiQuery) string {
if query.LegendFormat == "" {
return formatNamePrometheusStyle(labels)
+1
View File
@@ -57,6 +57,7 @@ func TestSuccessResponse(t *testing.T) {
responseFileName := filepath.Join("testdata", test.filepath+".json")
goldenFileName := test.filepath + ".golden"
//nolint:gosec
bytes, err := os.ReadFile(responseFileName)
require.NoError(t, err)
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
"github.com/grafana/grafana/pkg/tsdb/sqleng"
)
@@ -65,7 +66,7 @@ func (m *postgresMacroEngine) Interpolate(query *backend.DataQuery, timeRange ba
return sql, nil
}
//nolint: gocyclo
//nolint:gocyclo
func (m *postgresMacroEngine) evaluateMacro(timeRange backend.TimeRange, query *backend.DataQuery, name string, args []string) (string, error) {
switch name {
case "__time":
+5 -2
View File
@@ -15,11 +15,12 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/experimental"
"github.com/prometheus/client_golang/api"
apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
"github.com/prometheus/client_golang/api"
apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
)
var update = true
@@ -44,6 +45,7 @@ func TestMatrixResponses(t *testing.T) {
query, err := loadStoredPrometheusQuery(queryFileName)
require.NoError(t, err)
//nolint:gosec
responseBytes, err := os.ReadFile(responseFileName)
require.NoError(t, err)
@@ -101,6 +103,7 @@ type storedPrometheusQuery struct {
}
func loadStoredPrometheusQuery(fileName string) (PrometheusQuery, error) {
//nolint:gosec
bytes, err := os.ReadFile(fileName)
if err != nil {
return PrometheusQuery{}, err
@@ -24,7 +24,7 @@ import (
"go.opentelemetry.io/otel/attribute"
)
//Internal interval and range variables
// Internal interval and range variables
const (
varInterval = "$__interval"
varIntervalMs = "$__interval_ms"
@@ -34,8 +34,8 @@ const (
varRateInterval = "$__rate_interval"
)
//Internal interval and range variables with {} syntax
//Repetitive code, we should have functionality to unify these
// Internal interval and range variables with {} syntax
// Repetitive code, we should have functionality to unify these
const (
varIntervalAlt = "${__interval}"
varIntervalMsAlt = "${__interval_ms}"
+3 -3
View File
@@ -11,7 +11,7 @@ import (
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
)
//Internal interval and range variables
// Internal interval and range variables
const (
varInterval = "$__interval"
varIntervalMs = "$__interval_ms"
@@ -21,8 +21,8 @@ const (
varRateInterval = "$__rate_interval"
)
//Internal interval and range variables with {} syntax
//Repetitive code, we should have functionality to unify these
// Internal interval and range variables with {} syntax
// Repetitive code, we should have functionality to unify these
const (
varIntervalAlt = "${__interval}"
varIntervalMsAlt = "${__interval_ms}"
@@ -16,6 +16,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/experimental"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/tsdb/prometheus/models"
)
@@ -50,6 +51,7 @@ func goldenScenario(name, queryFileName, responseFileName, goldenFileName string
query, err := loadStoredQuery(queryFileName)
require.NoError(t, err)
//nolint:gosec
responseBytes, err := os.ReadFile(responseFileName)
require.NoError(t, err)
@@ -78,6 +80,7 @@ type storedPrometheusQuery struct {
}
func loadStoredQuery(fileName string) (*backend.QueryDataRequest, error) {
//nolint:gosec
bytes, err := os.ReadFile(fileName)
if err != nil {
return nil, err
+6 -3
View File
@@ -16,10 +16,11 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana-plugin-sdk-go/data/sqlutil"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
"xorm.io/core"
"xorm.io/xorm"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
)
// MetaKeyExecutedQueryString is the key where the executed query should get stored
@@ -43,6 +44,7 @@ type SqlQueryResultTransformer interface {
var sqlIntervalCalculator = intervalv2.NewCalculator()
// NewXormEngine is an xorm.Engine factory, that can be stubbed by tests.
//
//nolint:gocritic
var NewXormEngine = func(driverName string, connectionString string) (*xorm.Engine, error) {
return xorm.NewEngine(driverName, connectionString)
@@ -886,7 +888,8 @@ func convertSQLTimeColumnToEpochMS(frame *data.Frame, timeIndex int) error {
}
// convertSQLValueColumnToFloat converts timeseries value column to float.
//nolint: gocyclo
//
//nolint:gocyclo
func convertSQLValueColumnToFloat(frame *data.Frame, Index int) (*data.Frame, error) {
if Index < 0 || Index >= len(frame.Fields) {
return frame, fmt.Errorf("metricIndex %d is out of range", Index)