Chore/fix lint issues (#27704)
* Chore: Fix linting issues Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ type kqlMacroEngine struct {
|
||||
// - $__contains(col, 'val1','val2') -> col in ('val1', 'val2')
|
||||
// - $__escapeMulti('\\vm\eth0\Total','\\vm\eth2\Total') -> @'\\vm\eth0\Total',@'\\vm\eth2\Total'
|
||||
|
||||
//KqlInterpolate interpolates macros for Kusto Query Language (KQL) queries
|
||||
// KqlInterpolate interpolates macros for Kusto Query Language (KQL) queries
|
||||
func KqlInterpolate(query *tsdb.Query, timeRange *tsdb.TimeRange, kql string, defaultTimeField ...string) (string, error) {
|
||||
engine := kqlMacroEngine{}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (m *kqlMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.TimeRang
|
||||
|
||||
var macroError error
|
||||
|
||||
//First pass for the escapeMulti macro
|
||||
// First pass for the escapeMulti macro
|
||||
kql = m.ReplaceAllStringSubmatchFunc(escapeMultiRegex, kql, func(groups []string) string {
|
||||
args := []string{}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (m *kqlMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.TimeRang
|
||||
return fmt.Sprintf("@%s", expr)
|
||||
})
|
||||
|
||||
//second pass for all the other macros
|
||||
// second pass for all the other macros
|
||||
kql = m.ReplaceAllStringSubmatchFunc(rExp, kql, func(groups []string) string {
|
||||
args := []string{}
|
||||
if len(groups) > 2 {
|
||||
|
||||
@@ -54,7 +54,7 @@ type AzureMonitorResponse struct {
|
||||
Resourceregion string `json:"resourceregion"`
|
||||
}
|
||||
|
||||
//ApplicationInsightsQueryResponse is the json response from the Application Insights API
|
||||
// ApplicationInsightsQueryResponse is the json response from the Application Insights API
|
||||
type ApplicationInsightsQueryResponse struct {
|
||||
Tables []struct {
|
||||
Name string `json:"name"`
|
||||
@@ -71,7 +71,7 @@ type AzureLogAnalyticsResponse struct {
|
||||
Tables []AzureLogAnalyticsTable `json:"tables"`
|
||||
}
|
||||
|
||||
//AzureLogAnalyticsTable is the table format for Log Analytics responses
|
||||
// AzureLogAnalyticsTable is the table format for Log Analytics responses
|
||||
type AzureLogAnalyticsTable struct {
|
||||
Name string `json:"name"`
|
||||
Columns []struct {
|
||||
|
||||
@@ -320,7 +320,7 @@ func interpolateFilterWildcards(value string) string {
|
||||
matches := strings.Count(value, "*")
|
||||
switch {
|
||||
case matches == 2 && strings.HasSuffix(value, "*") && strings.HasPrefix(value, "*"):
|
||||
value = strings.Replace(value, "*", "", -1)
|
||||
value = strings.ReplaceAll(value, "*", "")
|
||||
value = fmt.Sprintf(`has_substring("%s")`, value)
|
||||
case matches == 1 && strings.HasPrefix(value, "*"):
|
||||
value = strings.Replace(value, "*", "", 1)
|
||||
@@ -332,8 +332,8 @@ func interpolateFilterWildcards(value string) string {
|
||||
value = string(wildcardRegexRe.ReplaceAllFunc([]byte(value), func(in []byte) []byte {
|
||||
return []byte(strings.Replace(string(in), string(in), `\\`+string(in), 1))
|
||||
}))
|
||||
value = strings.Replace(value, "*", ".*", -1)
|
||||
value = strings.Replace(value, `"`, `\\"`, -1)
|
||||
value = strings.ReplaceAll(value, "*", ".*")
|
||||
value = strings.ReplaceAll(value, `"`, `\\"`)
|
||||
value = fmt.Sprintf(`monitoring.regex.full_match("^%s$")`, value)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
//***
|
||||
// ***
|
||||
// LogQuery tests
|
||||
//***
|
||||
// ***
|
||||
|
||||
func TestLogsResultsToDataframes(t *testing.T) {
|
||||
fakeCloudwatchResponse := &cloudwatchlogs.GetQueryResultsOutput{
|
||||
|
||||
@@ -141,8 +141,8 @@ func (c *baseClientImpl) encodeBatchRequests(requests []*multiRequest) ([]byte,
|
||||
}
|
||||
|
||||
body := string(reqBody)
|
||||
body = strings.Replace(body, "$__interval_ms", strconv.FormatInt(r.interval.Milliseconds(), 10), -1)
|
||||
body = strings.Replace(body, "$__interval", r.interval.Text, -1)
|
||||
body = strings.ReplaceAll(body, "$__interval_ms", strconv.FormatInt(r.interval.Milliseconds(), 10))
|
||||
body = strings.ReplaceAll(body, "$__interval", r.interval.Text)
|
||||
|
||||
payload.WriteString(body + "\n")
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ var datePatternReplacements = map[string]string{
|
||||
"YYYY": "2006", // stdLongYear 1970 1971 ... 2029 2030
|
||||
"gg": "<stdIsoYearShort>", // ISO-8601 year number 70 71 ... 29 30
|
||||
"gggg": "<stdIsoYear>", // ***1970 1971 ... 2029 2030
|
||||
"GG": "<stdIsoYearShort>", //70 71 ... 29 30
|
||||
"GG": "<stdIsoYearShort>", // 70 71 ... 29 30
|
||||
"GGGG": "<stdIsoYear>", // ***1970 1971 ... 2029 2030
|
||||
"Q": "<stdQuarter>", // 1, 2, 3, 4
|
||||
"A": "PM", // stdPM AM PM
|
||||
@@ -233,17 +233,17 @@ var datePatternReplacements = map[string]string{
|
||||
"mm": "04", // stdZeroMinute 00 01 ... 58 59
|
||||
"s": "5", // stdSecond 0 1 ... 58 59
|
||||
"ss": "05", // stdZeroSecond ***00 01 ... 58 59
|
||||
"z": "MST", //EST CST ... MST PST
|
||||
"zz": "MST", //EST CST ... MST PST
|
||||
"z": "MST", // EST CST ... MST PST
|
||||
"zz": "MST", // EST CST ... MST PST
|
||||
"Z": "Z07:00", // stdNumColonTZ -07:00 -06:00 ... +06:00 +07:00
|
||||
"ZZ": "-0700", // stdNumTZ -0700 -0600 ... +0600 +0700
|
||||
"X": "<stdUnix>", // Seconds since unix epoch 1360013296
|
||||
"LT": "3:04 PM", // 8:30 PM
|
||||
"L": "01/02/2006", //09/04/1986
|
||||
"l": "1/2/2006", //9/4/1986
|
||||
"ll": "Jan 2 2006", //Sep 4 1986
|
||||
"lll": "Jan 2 2006 3:04 PM", //Sep 4 1986 8:30 PM
|
||||
"llll": "Mon, Jan 2 2006 3:04 PM", //Thu, Sep 4 1986 8:30 PM
|
||||
"L": "01/02/2006", // 09/04/1986
|
||||
"l": "1/2/2006", // 9/4/1986
|
||||
"ll": "Jan 2 2006", // Sep 4 1986
|
||||
"lll": "Jan 2 2006 3:04 PM", // Sep 4 1986 8:30 PM
|
||||
"llll": "Mon, Jan 2 2006 3:04 PM", // Thu, Sep 4 1986 8:30 PM
|
||||
}
|
||||
|
||||
func formatDate(t time.Time, pattern string) string {
|
||||
@@ -277,11 +277,11 @@ func formatDate(t time.Time, pattern string) string {
|
||||
if strings.Contains(formatted, "<std") {
|
||||
isoYear, isoWeek := t.ISOWeek()
|
||||
isoYearShort := fmt.Sprintf("%d", isoYear)[2:4]
|
||||
formatted = strings.Replace(formatted, "<stdIsoYear>", fmt.Sprintf("%d", isoYear), -1)
|
||||
formatted = strings.Replace(formatted, "<stdIsoYearShort>", isoYearShort, -1)
|
||||
formatted = strings.Replace(formatted, "<stdWeekOfYear>", fmt.Sprintf("%02d", isoWeek), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdIsoYear>", fmt.Sprintf("%d", isoYear))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdIsoYearShort>", isoYearShort)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdWeekOfYear>", fmt.Sprintf("%02d", isoWeek))
|
||||
|
||||
formatted = strings.Replace(formatted, "<stdUnix>", fmt.Sprintf("%d", t.Unix()), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdUnix>", fmt.Sprintf("%d", t.Unix()))
|
||||
|
||||
day := t.Weekday()
|
||||
dayOfWeekIso := int(day)
|
||||
@@ -289,9 +289,9 @@ func formatDate(t time.Time, pattern string) string {
|
||||
dayOfWeekIso = 7
|
||||
}
|
||||
|
||||
formatted = strings.Replace(formatted, "<stdDayOfWeek>", fmt.Sprintf("%d", day), -1)
|
||||
formatted = strings.Replace(formatted, "<stdDayOfWeekISO>", fmt.Sprintf("%d", dayOfWeekIso), -1)
|
||||
formatted = strings.Replace(formatted, "<stdDayOfYear>", fmt.Sprintf("%d", t.YearDay()), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdDayOfWeek>", fmt.Sprintf("%d", day))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdDayOfWeekISO>", fmt.Sprintf("%d", dayOfWeekIso))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdDayOfYear>", fmt.Sprintf("%d", t.YearDay()))
|
||||
|
||||
quarter := 4
|
||||
|
||||
@@ -304,8 +304,8 @@ func formatDate(t time.Time, pattern string) string {
|
||||
quarter = 3
|
||||
}
|
||||
|
||||
formatted = strings.Replace(formatted, "<stdQuarter>", fmt.Sprintf("%d", quarter), -1)
|
||||
formatted = strings.Replace(formatted, "<stdHourNoZero>", fmt.Sprintf("%d", t.Hour()), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdQuarter>", fmt.Sprintf("%d", quarter))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdHourNoZero>", fmt.Sprintf("%d", t.Hour()))
|
||||
}
|
||||
|
||||
if ltr {
|
||||
|
||||
@@ -375,7 +375,7 @@ func (rp *responseParser) processAggregationDocs(esAgg *simplejson.Json, aggDef
|
||||
if len(otherMetrics) > 1 {
|
||||
metricName += " " + metric.Field
|
||||
if metric.Type == "bucket_script" {
|
||||
//Use the formula in the column name
|
||||
// Use the formula in the column name
|
||||
metricName = metric.Settings.Get("script").MustString("")
|
||||
}
|
||||
}
|
||||
@@ -484,7 +484,7 @@ func (rp *responseParser) getSeriesName(series *tsdb.TimeSeries, target *Query,
|
||||
for name, pipelineAgg := range metric.PipelineVariables {
|
||||
for _, m := range target.Metrics {
|
||||
if m.ID == pipelineAgg {
|
||||
metricName = strings.Replace(metricName, "params."+name, describeMetric(m.Type, m.Field), -1)
|
||||
metricName = strings.ReplaceAll(metricName, "params."+name, describeMetric(m.Type, m.Field))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,17 +178,17 @@ func formatTimeRange(input string) string {
|
||||
if input == "now" {
|
||||
return input
|
||||
}
|
||||
return strings.Replace(strings.Replace(strings.Replace(input, "now", "", -1), "m", "min", -1), "M", "mon", -1)
|
||||
return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(input, "now", ""), "m", "min"), "M", "mon")
|
||||
}
|
||||
|
||||
func fixIntervalFormat(target string) string {
|
||||
rMinute := regexp.MustCompile(`'(\d+)m'`)
|
||||
target = rMinute.ReplaceAllStringFunc(target, func(m string) string {
|
||||
return strings.Replace(m, "m", "min", -1)
|
||||
return strings.ReplaceAll(m, "m", "min")
|
||||
})
|
||||
rMonth := regexp.MustCompile(`'(\d+)M'`)
|
||||
target = rMonth.ReplaceAllStringFunc(target, func(M string) string {
|
||||
return strings.Replace(M, "M", "mon", -1)
|
||||
return strings.ReplaceAll(M, "M", "mon")
|
||||
})
|
||||
return target
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
type InfluxDBExecutor struct {
|
||||
//*models.DataSource
|
||||
// *models.DataSource
|
||||
QueryParser *InfluxdbQueryParser
|
||||
ResponseParser *ResponseParser
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ func (query *Query) Build(queryContext *tsdb.TsdbQuery) (string, error) {
|
||||
calculator := tsdb.NewIntervalCalculator(&tsdb.IntervalOptions{})
|
||||
interval := calculator.Calculate(queryContext.TimeRange, query.Interval)
|
||||
|
||||
res = strings.Replace(res, "$timeFilter", query.renderTimeFilter(queryContext), -1)
|
||||
res = strings.Replace(res, "$interval", interval.Text, -1)
|
||||
res = strings.Replace(res, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10), -1)
|
||||
res = strings.Replace(res, "$__interval", interval.Text, -1)
|
||||
res = strings.ReplaceAll(res, "$timeFilter", query.renderTimeFilter(queryContext))
|
||||
res = strings.ReplaceAll(res, "$interval", interval.Text)
|
||||
res = strings.ReplaceAll(res, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10))
|
||||
res = strings.ReplaceAll(res, "$__interval", interval.Text)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (query *Query) renderTags() []string {
|
||||
str += " "
|
||||
}
|
||||
|
||||
//If the operator is missing we fall back to sensible defaults
|
||||
// If the operator is missing we fall back to sensible defaults
|
||||
if tag.Operator == "" {
|
||||
if regexpOperatorPattern.Match([]byte(tag.Value)) {
|
||||
tag.Operator = "=~"
|
||||
@@ -68,7 +68,7 @@ func (query *Query) renderTags() []string {
|
||||
case "<", ">":
|
||||
textValue = tag.Value
|
||||
default:
|
||||
textValue = fmt.Sprintf("'%s'", strings.Replace(tag.Value, `\`, `\\`, -1))
|
||||
textValue = fmt.Sprintf("'%s'", strings.ReplaceAll(tag.Value, `\`, `\\`))
|
||||
}
|
||||
|
||||
res = append(res, fmt.Sprintf(`%s"%s" %s %s`, str, tag.Key, tag.Operator, textValue))
|
||||
@@ -143,7 +143,7 @@ func (query *Query) renderGroupBy(queryContext *tsdb.TsdbQuery) string {
|
||||
}
|
||||
|
||||
if i > 0 && group.Type != "fill" {
|
||||
groupBy += ", " //fill is so very special. fill is a creep, fill is a weirdo
|
||||
groupBy += ", " // fill is so very special. fill is a creep, fill is a weirdo
|
||||
} else {
|
||||
groupBy += " "
|
||||
}
|
||||
|
||||
@@ -983,7 +983,7 @@ func TestMSSQL(t *testing.T) {
|
||||
So(len(queryResult.Tables[0].Rows), ShouldEqual, 1)
|
||||
columns := queryResult.Tables[0].Rows[0]
|
||||
|
||||
//Should be in milliseconds
|
||||
// Should be in milliseconds
|
||||
So(columns[0].(float64), ShouldEqual, float64(dt.UnixNano()/1e6))
|
||||
})
|
||||
|
||||
@@ -1013,7 +1013,7 @@ func TestMSSQL(t *testing.T) {
|
||||
So(len(queryResult.Tables[0].Rows), ShouldEqual, 1)
|
||||
columns := queryResult.Tables[0].Rows[0]
|
||||
|
||||
//Should be in milliseconds
|
||||
// Should be in milliseconds
|
||||
So(columns[0].(int64), ShouldEqual, dt.Unix()*1000)
|
||||
})
|
||||
|
||||
@@ -1043,7 +1043,7 @@ func TestMSSQL(t *testing.T) {
|
||||
So(len(queryResult.Tables[0].Rows), ShouldEqual, 1)
|
||||
columns := queryResult.Tables[0].Rows[0]
|
||||
|
||||
//Should be in milliseconds
|
||||
// Should be in milliseconds
|
||||
So(columns[0].(int64), ShouldEqual, dt.Unix()*1000)
|
||||
})
|
||||
|
||||
@@ -1073,7 +1073,7 @@ func TestMSSQL(t *testing.T) {
|
||||
So(len(queryResult.Tables[0].Rows), ShouldEqual, 1)
|
||||
columns := queryResult.Tables[0].Rows[0]
|
||||
|
||||
//Should be in milliseconds
|
||||
// Should be in milliseconds
|
||||
So(columns[0].(float64), ShouldEqual, float64(dt.Unix()*1000))
|
||||
})
|
||||
|
||||
@@ -1101,7 +1101,7 @@ func TestMSSQL(t *testing.T) {
|
||||
So(len(queryResult.Tables[0].Rows), ShouldEqual, 1)
|
||||
columns := queryResult.Tables[0].Rows[0]
|
||||
|
||||
//Should be in milliseconds
|
||||
// Should be in milliseconds
|
||||
So(columns[0], ShouldBeNil)
|
||||
})
|
||||
|
||||
@@ -1129,7 +1129,7 @@ func TestMSSQL(t *testing.T) {
|
||||
So(len(queryResult.Tables[0].Rows), ShouldEqual, 1)
|
||||
columns := queryResult.Tables[0].Rows[0]
|
||||
|
||||
//Should be in milliseconds
|
||||
// Should be in milliseconds
|
||||
So(columns[0], ShouldBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ func init() {
|
||||
}
|
||||
|
||||
func characterEscape(s string, escapeChar string) string {
|
||||
return strings.Replace(s, escapeChar, url.QueryEscape(escapeChar), -1)
|
||||
return strings.ReplaceAll(s, escapeChar, url.QueryEscape(escapeChar))
|
||||
}
|
||||
|
||||
func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
||||
|
||||
@@ -160,7 +160,7 @@ func (e *OpenTsdbExecutor) buildMetric(query *tsdb.Query) map[string]interface{}
|
||||
if !disableDownsampling {
|
||||
downsampleInterval := query.Model.Get("downsampleInterval").MustString()
|
||||
if downsampleInterval == "" {
|
||||
downsampleInterval = "1m" //default value for blank
|
||||
downsampleInterval = "1m" // default value for blank
|
||||
}
|
||||
downsample := downsampleInterval + "-" + query.Model.Get("downsampleAggregator").MustString()
|
||||
if query.Model.Get("downsampleFillPolicy").MustString() != "none" {
|
||||
|
||||
@@ -58,7 +58,7 @@ func newPostgresQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndp
|
||||
|
||||
// escape single quotes and backslashes in Postgres connection string parameters.
|
||||
func escape(input string) string {
|
||||
return strings.Replace(strings.Replace(input, `\`, `\\`, -1), "'", `\'`, -1)
|
||||
return strings.ReplaceAll(strings.ReplaceAll(input, `\`, `\\`), "'", `\'`)
|
||||
}
|
||||
|
||||
func generateConnectionString(datasource *models.DataSource, logger log.Logger) (string, error) {
|
||||
|
||||
@@ -207,10 +207,10 @@ var Interpolate = func(query *tsdb.Query, timeRange *tsdb.TimeRange, sql string)
|
||||
}
|
||||
interval := sqlIntervalCalculator.Calculate(timeRange, minInterval)
|
||||
|
||||
sql = strings.Replace(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10), -1)
|
||||
sql = strings.Replace(sql, "$__interval", interval.Text, -1)
|
||||
sql = strings.Replace(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.GetFromAsSecondsEpoch()), -1)
|
||||
sql = strings.Replace(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.GetToAsSecondsEpoch()), -1)
|
||||
sql = strings.ReplaceAll(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10))
|
||||
sql = strings.ReplaceAll(sql, "$__interval", interval.Text)
|
||||
sql = strings.ReplaceAll(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.GetFromAsSecondsEpoch()))
|
||||
sql = strings.ReplaceAll(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.GetToAsSecondsEpoch()))
|
||||
|
||||
return sql, nil
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func init() {
|
||||
queryRes := tsdb.NewQueryResult()
|
||||
|
||||
stringInput := query.Model.Get("stringInput").MustString()
|
||||
stringInput = strings.Replace(stringInput, " ", "", -1)
|
||||
stringInput = strings.ReplaceAll(stringInput, " ", "")
|
||||
|
||||
values := []null.Float{}
|
||||
for _, strVal := range strings.Split(stringInput, ",") {
|
||||
|
||||
Reference in New Issue
Block a user