Chore: Fix issues found by staticcheck (#28802)
* Fix linting issues Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -179,7 +179,7 @@ func (e *ApplicationInsightsDatasource) executeQuery(ctx context.Context, query
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||
return nil, fmt.Errorf("Request failed status: %v", res.Status)
|
||||
return nil, fmt.Errorf("request failed, status: %s", res.Status)
|
||||
}
|
||||
|
||||
mr := MetricsResult{}
|
||||
@@ -204,7 +204,7 @@ func (e *ApplicationInsightsDatasource) createRequest(ctx context.Context, dsInf
|
||||
// find plugin
|
||||
plugin, ok := plugins.DataSources[dsInfo.Type]
|
||||
if !ok {
|
||||
return nil, errors.New("Unable to find datasource plugin Azure Application Insights")
|
||||
return nil, errors.New("unable to find datasource plugin Azure Application Insights")
|
||||
}
|
||||
|
||||
cloudName := dsInfo.JsonData.Get("cloudName").MustString("azuremonitor")
|
||||
|
||||
@@ -207,7 +207,7 @@ func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, dsInfo
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
if err != nil {
|
||||
azlog.Debug("Failed to create request", "error", err)
|
||||
return nil, errutil.Wrap("Failed to create request", err)
|
||||
return nil, errutil.Wrap("failed to create request", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@@ -216,7 +216,7 @@ func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, dsInfo
|
||||
// find plugin
|
||||
plugin, ok := plugins.DataSources[dsInfo.Type]
|
||||
if !ok {
|
||||
return nil, errors.New("Unable to find datasource plugin Azure Monitor")
|
||||
return nil, errors.New("unable to find datasource plugin Azure Monitor")
|
||||
}
|
||||
cloudName := dsInfo.JsonData.Get("cloudName").MustString("azuremonitor")
|
||||
|
||||
@@ -272,7 +272,7 @@ func (e *AzureLogAnalyticsDatasource) unmarshalResponse(res *http.Response) (Azu
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||
return AzureLogAnalyticsResponse{}, fmt.Errorf("Request failed status: %v: %w", res.Status, fmt.Errorf(string(body)))
|
||||
return AzureLogAnalyticsResponse{}, fmt.Errorf("request failed, status: %s, body: %s", res.Status, string(body))
|
||||
}
|
||||
|
||||
var data AzureLogAnalyticsResponse
|
||||
|
||||
@@ -220,7 +220,7 @@ func (e *AzureMonitorDatasource) createRequest(ctx context.Context, dsInfo *mode
|
||||
// find plugin
|
||||
plugin, ok := plugins.DataSources[dsInfo.Type]
|
||||
if !ok {
|
||||
return nil, errors.New("Unable to find datasource plugin Azure Monitor")
|
||||
return nil, errors.New("unable to find datasource plugin Azure Monitor")
|
||||
}
|
||||
|
||||
cloudName := dsInfo.JsonData.Get("cloudName").MustString("azuremonitor")
|
||||
@@ -263,7 +263,7 @@ func (e *AzureMonitorDatasource) unmarshalResponse(res *http.Response) (AzureMon
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||
return AzureMonitorResponse{}, fmt.Errorf("Request failed status: %v", res.Status)
|
||||
return AzureMonitorResponse{}, fmt.Errorf("request failed, status: %s", res.Status)
|
||||
}
|
||||
|
||||
var data AzureMonitorResponse
|
||||
|
||||
@@ -66,7 +66,7 @@ func (e *AzureMonitorExecutor) Query(ctx context.Context, dsInfo *models.DataSou
|
||||
case "Insights Analytics":
|
||||
insightsAnalyticsQueries = append(insightsAnalyticsQueries, query)
|
||||
default:
|
||||
return nil, fmt.Errorf("Alerting not supported for %s", queryType)
|
||||
return nil, fmt.Errorf("alerting not supported for %q", queryType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ func (e *InsightsAnalyticsDatasource) executeQuery(ctx context.Context, query *I
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||
return queryResultError(fmt.Errorf("Request failed status: %v %w", res.Status, fmt.Errorf(string(body))))
|
||||
return queryResultError(fmt.Errorf("request failed, status: %s, body: %s", res.Status, body))
|
||||
}
|
||||
var logResponse AzureLogAnalyticsResponse
|
||||
d := json.NewDecoder(bytes.NewReader(body))
|
||||
@@ -180,7 +180,7 @@ func (e *InsightsAnalyticsDatasource) createRequest(ctx context.Context, dsInfo
|
||||
// find plugin
|
||||
plugin, ok := plugins.DataSources[dsInfo.Type]
|
||||
if !ok {
|
||||
return nil, errors.New("Unable to find datasource plugin Azure Application Insights")
|
||||
return nil, errors.New("unable to find datasource plugin Azure Application Insights")
|
||||
}
|
||||
|
||||
cloudName := dsInfo.JsonData.Get("cloudName").MustString("azuremonitor")
|
||||
|
||||
@@ -126,7 +126,7 @@ func (m *kqlMacroEngine) evaluateMacro(name string, defaultTimeField string, arg
|
||||
case "escapeMulti":
|
||||
return "", fmt.Errorf("escapeMulti macro not formatted correctly")
|
||||
default:
|
||||
return "", fmt.Errorf("Unknown macro %v", name)
|
||||
return "", fmt.Errorf("unknown macro %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func (tg *TimeGrain) createISO8601DurationFromIntervalMS(interval int64) (string
|
||||
timeValueString := formatted[0 : len(formatted)-1]
|
||||
timeValue, err := strconv.Atoi(timeValueString)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Could not parse interval %v to an ISO 8061 duration", interval)
|
||||
return "", fmt.Errorf("could not parse interval %q to an ISO 8061 duration: %w", interval, err)
|
||||
}
|
||||
|
||||
unit := formatted[len(formatted)-1:]
|
||||
|
||||
@@ -103,7 +103,7 @@ func (e *CloudMonitoringExecutor) getGCEDefaultProject(ctx context.Context, tsdb
|
||||
|
||||
gceDefaultProject, err := e.getDefaultProject(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to retrieve default project from GCE metadata server. error: %v", err)
|
||||
return nil, fmt.Errorf("failed to retrieve default project from GCE metadata server, error: %w", err)
|
||||
}
|
||||
|
||||
queryResult.Meta.Set("defaultProject", gceDefaultProject)
|
||||
@@ -769,7 +769,7 @@ func (e *CloudMonitoringExecutor) createRequest(ctx context.Context, dsInfo *mod
|
||||
req, err := http.NewRequest(http.MethodGet, "https://monitoring.googleapis.com/", nil)
|
||||
if err != nil {
|
||||
slog.Error("Failed to create request", "error", err)
|
||||
return nil, fmt.Errorf("Failed to create request. error: %v", err)
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@@ -778,7 +778,7 @@ func (e *CloudMonitoringExecutor) createRequest(ctx context.Context, dsInfo *mod
|
||||
// find plugin
|
||||
plugin, ok := plugins.DataSources[dsInfo.Type]
|
||||
if !ok {
|
||||
return nil, errors.New("Unable to find datasource plugin CloudMonitoring")
|
||||
return nil, errors.New("unable to find datasource plugin CloudMonitoring")
|
||||
}
|
||||
|
||||
var cloudMonitoringRoute *plugins.AppPluginRoute
|
||||
@@ -799,14 +799,14 @@ func (e *CloudMonitoringExecutor) getDefaultProject(ctx context.Context) (string
|
||||
if authenticationType == gceAuthentication {
|
||||
defaultCredentials, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/monitoring.read")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to retrieve default project from GCE metadata server. error: %v", err)
|
||||
return "", fmt.Errorf("failed to retrieve default project from GCE metadata server: %w", err)
|
||||
}
|
||||
token, err := defaultCredentials.TokenSource.Token()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to retrieve GCP credential token. error: %v", err)
|
||||
return "", fmt.Errorf("failed to retrieve GCP credential token: %w", err)
|
||||
}
|
||||
if !token.Valid() {
|
||||
return "", errors.New("Failed to validate GCP credentials")
|
||||
return "", errors.New("failed to validate GCP credentials")
|
||||
}
|
||||
|
||||
return defaultCredentials.ProjectID, nil
|
||||
|
||||
@@ -68,7 +68,7 @@ func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
|
||||
|
||||
if target == "" {
|
||||
glog.Error("No targets in query model", "models without targets", strings.Join(emptyQueries, "\n"))
|
||||
return nil, errors.New("No query target found for the alert rule")
|
||||
return nil, errors.New("no query target found for the alert rule")
|
||||
}
|
||||
|
||||
formData["target"] = []string{target}
|
||||
@@ -140,7 +140,7 @@ func (e *GraphiteExecutor) parseResponse(res *http.Response) ([]TargetResponseDT
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
glog.Info("Request failed", "status", res.Status, "body", string(body))
|
||||
return nil, fmt.Errorf("Request failed status: %v", res.Status)
|
||||
return nil, fmt.Errorf("request failed, status: %s", res.Status)
|
||||
}
|
||||
|
||||
var data []TargetResponseDTO
|
||||
@@ -163,7 +163,7 @@ func (e *GraphiteExecutor) createRequest(dsInfo *models.DataSource, data url.Val
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(data.Encode()))
|
||||
if err != nil {
|
||||
glog.Info("Failed to create request", "error", err)
|
||||
return nil, fmt.Errorf("Failed to create request. error: %v", err)
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
@@ -125,7 +125,7 @@ func (fb *frameBuilder) Init(metadata *query.FluxTableMetadata) error {
|
||||
if col != nil {
|
||||
fb.timeColumn = col.Name()
|
||||
fb.timeDisplay = "Time"
|
||||
if "_time" != fb.timeColumn {
|
||||
if fb.timeColumn != "_time" {
|
||||
fb.timeDisplay = col.Name()
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -85,7 +85,7 @@ func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode/100 != 2 {
|
||||
return nil, fmt.Errorf("Influxdb returned statuscode invalid status code: %v", resp.Status)
|
||||
return nil, fmt.Errorf("InfluxDB returned statuscode invalid status code: %s", resp.Status)
|
||||
}
|
||||
|
||||
var response Response
|
||||
|
||||
@@ -129,6 +129,6 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
}
|
||||
return "", err
|
||||
default:
|
||||
return "", fmt.Errorf("Unknown macro %v", name)
|
||||
return "", fmt.Errorf("unknown macro %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (m *mySqlMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.TimeRa
|
||||
matches := restrictedRegExp.FindAllStringSubmatch(sql, 1)
|
||||
if len(matches) > 0 {
|
||||
m.logger.Error("show grants, session_user(), current_user(), system_user() or user() not allowed in query")
|
||||
return "", errors.New("Invalid query. Inspect Grafana server log for details")
|
||||
return "", errors.New("invalid query - inspect Grafana server log for details")
|
||||
}
|
||||
|
||||
rExp, _ := regexp.Compile(sExpr)
|
||||
@@ -135,6 +135,6 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
}
|
||||
return "", err
|
||||
default:
|
||||
return "", fmt.Errorf("Unknown macro %v", name)
|
||||
return "", fmt.Errorf("unknown macro %v", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ func TestMacroEngine(t *testing.T) {
|
||||
|
||||
for _, tc := range tcs {
|
||||
_, err := engine.Interpolate(nil, nil, tc)
|
||||
So(err.Error(), ShouldEqual, "Invalid query. Inspect Grafana server log for details")
|
||||
So(err.Error(), ShouldEqual, "invalid query - inspect Grafana server log for details")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -150,4 +150,4 @@ func (t *mysqlQueryResultTransformer) TransformQueryError(err error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var errQueryFailed = errors.New("Query failed. Please inspect Grafana server log for details")
|
||||
var errQueryFailed = errors.New("query failed - please inspect Grafana server log for details")
|
||||
|
||||
@@ -88,13 +88,13 @@ func (e *OpenTsdbExecutor) createRequest(dsInfo *models.DataSource, data OpenTsd
|
||||
postData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
plog.Info("Failed marshaling data", "error", err)
|
||||
return nil, fmt.Errorf("Failed to create request. error: %v", err)
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(string(postData)))
|
||||
if err != nil {
|
||||
plog.Info("Failed to create request", "error", err)
|
||||
return nil, fmt.Errorf("Failed to create request. error: %v", err)
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@@ -117,7 +117,7 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
plog.Info("Request failed", "status", res.Status, "body", string(body))
|
||||
return nil, fmt.Errorf("Request failed status: %v", res.Status)
|
||||
return nil, fmt.Errorf("request failed, status: %s", res.Status)
|
||||
}
|
||||
|
||||
var data []OpenTsdbResponse
|
||||
|
||||
@@ -159,6 +159,6 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
|
||||
}
|
||||
return "", err
|
||||
default:
|
||||
return "", fmt.Errorf("Unknown macro %v", name)
|
||||
return "", fmt.Errorf("unknown macro %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ func parseResponse(value model.Value, query *PrometheusQuery) (*tsdb.QueryResult
|
||||
|
||||
data, ok := value.(model.Matrix)
|
||||
if !ok {
|
||||
return queryRes, fmt.Errorf("Unsupported result format: %s", value.Type().String())
|
||||
return queryRes, fmt.Errorf("unsupported result format: %q", value.Type().String())
|
||||
}
|
||||
|
||||
for _, v := range data {
|
||||
|
||||
@@ -343,7 +343,7 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.R
|
||||
}
|
||||
|
||||
if cfg.timeIndex == -1 {
|
||||
return fmt.Errorf("Found no column named %s", strings.Join(e.timeColumnNames, " or "))
|
||||
return fmt.Errorf("found no column named %q", strings.Join(e.timeColumnNames, " or "))
|
||||
}
|
||||
|
||||
if cfg.fillMissing {
|
||||
@@ -666,7 +666,10 @@ func ConvertSqlValueColumnToFloat(columnName string, columnValue interface{}) (n
|
||||
case nil:
|
||||
value.Valid = false
|
||||
default:
|
||||
return null.NewFloat(0, false), fmt.Errorf("Value column must have numeric datatype, column: %s type: %T value: %v", columnName, typedValue, typedValue)
|
||||
return null.NewFloat(0, false), fmt.Errorf(
|
||||
"value column must have numeric datatype, column: %s, type: %T, value: %v",
|
||||
columnName, typedValue, typedValue,
|
||||
)
|
||||
}
|
||||
|
||||
return value, nil
|
||||
|
||||
Reference in New Issue
Block a user