Chore: Disable default golangci-lint filter (#29751)
* Disable default golangci-lint filter Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: Fix linter warnings Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -172,7 +172,11 @@ func (e *ApplicationInsightsDatasource) executeQuery(ctx context.Context, query
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
azlog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -156,8 +156,7 @@ func TestInsightsMetricsResultToFrame(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
res, err := loadInsightsMetricsResponse(tt.testFile)
|
||||
require.NoError(t, err)
|
||||
res := loadInsightsMetricsResponse(t, tt.testFile)
|
||||
|
||||
frame, err := InsightsMetricsResultToFrame(res, tt.metric, tt.agg, tt.dimensions)
|
||||
require.NoError(t, err)
|
||||
@@ -171,16 +170,23 @@ func TestInsightsMetricsResultToFrame(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadInsightsMetricsResponse(name string) (MetricsResult, error) {
|
||||
var mr MetricsResult
|
||||
func loadInsightsMetricsResponse(t *testing.T, name string) MetricsResult {
|
||||
t.Helper()
|
||||
|
||||
path := filepath.Join("testdata", name)
|
||||
// Ignore gosec warning G304 since it's a test
|
||||
// nolint:gosec
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return mr, err
|
||||
}
|
||||
defer f.Close()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
err := f.Close()
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
d := json.NewDecoder(f)
|
||||
var mr MetricsResult
|
||||
err = d.Decode(&mr)
|
||||
return mr, err
|
||||
require.NoError(t, err)
|
||||
|
||||
return mr
|
||||
}
|
||||
|
||||
@@ -264,11 +264,14 @@ func (ar *AzureLogAnalyticsResponse) GetPrimaryResultTable() (*AzureLogAnalytics
|
||||
|
||||
func (e *AzureLogAnalyticsDatasource) unmarshalResponse(res *http.Response) (AzureLogAnalyticsResponse, error) {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
|
||||
if err != nil {
|
||||
return AzureLogAnalyticsResponse{}, err
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
azlog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/xorcare/pointer"
|
||||
)
|
||||
@@ -140,8 +141,7 @@ func TestLogTableToFrame(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
res, err := loadLogAnalyticsTestFileWithNumber(tt.testFile)
|
||||
require.NoError(t, err)
|
||||
res := loadLogAnalyticsTestFileWithNumber(t, tt.testFile)
|
||||
frame, err := LogTableToFrame(&res.Tables[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -152,17 +152,22 @@ func TestLogTableToFrame(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadLogAnalyticsTestFileWithNumber(name string) (AzureLogAnalyticsResponse, error) {
|
||||
var data AzureLogAnalyticsResponse
|
||||
|
||||
func loadLogAnalyticsTestFileWithNumber(t *testing.T, name string) AzureLogAnalyticsResponse {
|
||||
t.Helper()
|
||||
path := filepath.Join("testdata", name)
|
||||
// Ignore gosec warning G304 since it's a test
|
||||
// nolint:gosec
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
defer f.Close()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
err := f.Close()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
d := json.NewDecoder(f)
|
||||
d.UseNumber()
|
||||
var data AzureLogAnalyticsResponse
|
||||
err = d.Decode(&data)
|
||||
return data, err
|
||||
require.NoError(t, err)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -206,6 +206,11 @@ func (e *AzureMonitorDatasource) executeQuery(ctx context.Context, query *AzureM
|
||||
queryResult.Error = err
|
||||
return queryResult, AzureMonitorResponse{}, nil
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
azlog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
data, err := e.unmarshalResponse(res)
|
||||
if err != nil {
|
||||
@@ -256,7 +261,6 @@ func (e *AzureMonitorDatasource) createRequest(ctx context.Context, dsInfo *mode
|
||||
|
||||
func (e *AzureMonitorDatasource) unmarshalResponse(res *http.Response) (AzureMonitorResponse, error) {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
if err != nil {
|
||||
return AzureMonitorResponse{}, err
|
||||
}
|
||||
|
||||
@@ -433,10 +433,9 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
azData, err := loadTestFile("azuremonitor/" + tt.responseFile)
|
||||
require.NoError(t, err)
|
||||
azData := loadTestFile(t, "azuremonitor/"+tt.responseFile)
|
||||
res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "A"}
|
||||
err = datasource.parseResponse(res, azData, tt.mockQuery)
|
||||
err := datasource.parseResponse(res, azData, tt.mockQuery)
|
||||
require.NoError(t, err)
|
||||
|
||||
frames, err := res.Dataframes.Decoded()
|
||||
@@ -496,14 +495,17 @@ func TestFindClosestAllowIntervalMS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadTestFile(name string) (AzureMonitorResponse, error) {
|
||||
var azData AzureMonitorResponse
|
||||
func loadTestFile(t *testing.T, name string) AzureMonitorResponse {
|
||||
t.Helper()
|
||||
|
||||
path := filepath.Join("testdata", name)
|
||||
// Ignore gosec warning G304 since it's a test
|
||||
// nolint:gosec
|
||||
jsonBody, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return azData, err
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
var azData AzureMonitorResponse
|
||||
err = json.Unmarshal(jsonBody, &azData)
|
||||
return azData, err
|
||||
require.NoError(t, err)
|
||||
return azData
|
||||
}
|
||||
|
||||
@@ -132,10 +132,14 @@ func (e *InsightsAnalyticsDatasource) executeQuery(ctx context.Context, query *I
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
if err != nil {
|
||||
return queryResultError(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
azlog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||
|
||||
@@ -482,10 +482,14 @@ func (e *CloudMonitoringExecutor) executeQuery(ctx context.Context, query *cloud
|
||||
|
||||
func (e *CloudMonitoringExecutor) unmarshalResponse(res *http.Response) (cloudMonitoringResponse, error) {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
if err != nil {
|
||||
return cloudMonitoringResponse{}, err
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
slog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
slog.Error("Request failed", "status", res.Status, "body", string(body))
|
||||
|
||||
@@ -989,6 +989,8 @@ func TestCloudMonitoring(t *testing.T) {
|
||||
func loadTestFile(path string) (cloudMonitoringResponse, error) {
|
||||
var data cloudMonitoringResponse
|
||||
|
||||
// Can ignore gosec warning G304 here since it's a test path
|
||||
// nolint:gosec
|
||||
jsonBody, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return data, err
|
||||
|
||||
@@ -226,7 +226,11 @@ func (c *baseClientImpl) ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearch
|
||||
return nil, err
|
||||
}
|
||||
res := clientRes.httpResponse
|
||||
defer res.Body.Close()
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
clientLog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
clientLog.Debug("Received multisearch response", "code", res.StatusCode, "status", res.Status, "content-length", res.ContentLength)
|
||||
|
||||
|
||||
@@ -133,10 +133,14 @@ func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
|
||||
|
||||
func (e *GraphiteExecutor) parseResponse(res *http.Response) ([]TargetResponseDTO, error) {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
glog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
glog.Info("Request failed", "status", res.Status, "body", string(body))
|
||||
|
||||
@@ -82,10 +82,13 @@ func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
if err := resp.Body.Close(); err != nil {
|
||||
glog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
if resp.StatusCode/100 != 2 {
|
||||
return nil, fmt.Errorf("InfluxDB returned statuscode invalid status code: %s", resp.Status)
|
||||
return nil, fmt.Errorf("InfluxDB returned error status: %s", resp.Status)
|
||||
}
|
||||
|
||||
var response Response
|
||||
|
||||
@@ -110,10 +110,14 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
|
||||
queryRes := tsdb.NewQueryResult()
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
plog.Warn("Failed to close response body", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if res.StatusCode/100 != 2 {
|
||||
plog.Info("Request failed", "status", res.Status, "body", string(body))
|
||||
|
||||
@@ -173,8 +173,11 @@ func (e *sqlQueryEndpoint) Query(ctx context.Context, dsInfo *models.DataSource,
|
||||
queryResult.Error = e.queryResultTransformer.TransformQueryError(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
defer func() {
|
||||
if err := rows.Close(); err != nil {
|
||||
e.log.Warn("Failed to close rows", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
format := query.Model.Get("format").MustString("time_series")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user