Skip to content

Commit 0860dfe

Browse files
authored
CloudWatch: Fix variable naming (grafana#24650)
* CloudWatch: Fix variable naming
1 parent 792e999 commit 0860dfe

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

pkg/tsdb/cloudwatch/cloudwatch.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ type DatasourceInfo struct {
3838
SecretKey string
3939
}
4040

41-
const CLOUDWATCH_TS_FORMAT = "2006-01-02 15:04:05.000"
41+
const cloudWatchTSFormat = "2006-01-02 15:04:05.000"
4242

4343
// Constants also defined in datasource/cloudwatch/datasource.ts
44-
const LOG_IDENTIFIER_INTERNAL = "__log__grafana_internal__"
45-
const LOGSTREAM_IDENTIFIER_INTERNAL = "__logstream__grafana_internal__"
44+
const logIdentifierInternal = "__log__grafana_internal__"
45+
const logStreamIdentifierInternal = "__logstream__grafana_internal__"
4646

4747
func (e *CloudWatchExecutor) getLogsClient(region string) (*cloudwatchlogs.CloudWatchLogs, error) {
4848
e.mux.Lock()
@@ -226,7 +226,7 @@ func queryResultsToDataframe(results *cloudwatchlogs.GetQueryResultsOutput) (*da
226226
}
227227

228228
if _, exists := fieldValues[*resultField.Field]; !exists {
229-
if _, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value); err == nil {
229+
if _, err := time.Parse(cloudWatchTSFormat, *resultField.Value); err == nil {
230230
fieldValues[*resultField.Field] = make([]*time.Time, rowCount)
231231
} else if _, err := strconv.ParseFloat(*resultField.Value, 64); err == nil {
232232
fieldValues[*resultField.Field] = make([]*float64, rowCount)
@@ -236,7 +236,7 @@ func queryResultsToDataframe(results *cloudwatchlogs.GetQueryResultsOutput) (*da
236236
}
237237

238238
if timeField, ok := fieldValues[*resultField.Field].([]*time.Time); ok {
239-
parsedTime, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value)
239+
parsedTime, err := time.Parse(cloudWatchTSFormat, *resultField.Value)
240240
if err != nil {
241241
return nil, err
242242
}

pkg/tsdb/cloudwatch/log_actions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (e *CloudWatchExecutor) executeStartQuery(ctx context.Context, logsClient c
242242
EndTime: aws.Int64(endTime.Unix()),
243243
Limit: aws.Int64(parameters.Get("limit").MustInt64(1000)),
244244
LogGroupNames: aws.StringSlice(parameters.Get("logGroupNames").MustStringArray()),
245-
QueryString: aws.String("fields @timestamp,ltrim(@log) as " + LOG_IDENTIFIER_INTERNAL + ",ltrim(@logStream) as " + LOGSTREAM_IDENTIFIER_INTERNAL + "|" + parameters.Get("queryString").MustString("")),
245+
QueryString: aws.String("fields @timestamp,ltrim(@log) as " + logIdentifierInternal + ",ltrim(@logStream) as " + logStreamIdentifierInternal + "|" + parameters.Get("queryString").MustString("")),
246246
}
247247
return logsClient.StartQueryWithContext(ctx, startQueryInput)
248248
}

pkg/tsdb/cloudwatch/log_query.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
2626
fieldNames = append(fieldNames, resultField.Field)
2727

2828
// Check if field is time field
29-
if _, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value); err == nil {
29+
if _, err := time.Parse(cloudWatchTSFormat, *resultField.Value); err == nil {
3030
fieldValues[*resultField.Field] = make([]*time.Time, rowCount)
3131
} else {
3232
fieldValues[*resultField.Field] = make([]*string, rowCount)
3333
}
3434
}
3535

3636
if timeField, ok := fieldValues[*resultField.Field].([]*time.Time); ok {
37-
parsedTime, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value)
37+
parsedTime, err := time.Parse(cloudWatchTSFormat, *resultField.Value)
3838
if err != nil {
3939
return nil, err
4040
}
@@ -52,7 +52,7 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
5252

5353
if *fieldName == "@timestamp" {
5454
newFields[len(newFields)-1].SetConfig(&data.FieldConfig{Title: "Time"})
55-
} else if *fieldName == LOGSTREAM_IDENTIFIER_INTERNAL || *fieldName == LOG_IDENTIFIER_INTERNAL {
55+
} else if *fieldName == logStreamIdentifierInternal || *fieldName == logIdentifierInternal {
5656
newFields[len(newFields)-1].SetConfig(
5757
&data.FieldConfig{
5858
Custom: map[string]interface{}{

pkg/tsdb/cloudwatch/log_query_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func TestLogsResultsToDataframes(t *testing.T) {
4040
Value: aws.String("fakelog"),
4141
},
4242
&cloudwatchlogs.ResultField{
43-
Field: aws.String(LOGSTREAM_IDENTIFIER_INTERNAL),
43+
Field: aws.String(logStreamIdentifierInternal),
4444
Value: aws.String("fakelogstream"),
4545
},
4646
&cloudwatchlogs.ResultField{
47-
Field: aws.String(LOG_IDENTIFIER_INTERNAL),
47+
Field: aws.String(logIdentifierInternal),
4848
Value: aws.String("fakelog"),
4949
},
5050
},
@@ -70,11 +70,11 @@ func TestLogsResultsToDataframes(t *testing.T) {
7070
Value: aws.String("fakelog"),
7171
},
7272
&cloudwatchlogs.ResultField{
73-
Field: aws.String(LOGSTREAM_IDENTIFIER_INTERNAL),
73+
Field: aws.String(logStreamIdentifierInternal),
7474
Value: aws.String("fakelogstream"),
7575
},
7676
&cloudwatchlogs.ResultField{
77-
Field: aws.String(LOG_IDENTIFIER_INTERNAL),
77+
Field: aws.String(logIdentifierInternal),
7878
Value: aws.String("fakelog"),
7979
},
8080
},
@@ -100,11 +100,11 @@ func TestLogsResultsToDataframes(t *testing.T) {
100100
Value: aws.String("fakelog"),
101101
},
102102
&cloudwatchlogs.ResultField{
103-
Field: aws.String(LOGSTREAM_IDENTIFIER_INTERNAL),
103+
Field: aws.String(logStreamIdentifierInternal),
104104
Value: aws.String("fakelogstream"),
105105
},
106106
&cloudwatchlogs.ResultField{
107-
Field: aws.String(LOG_IDENTIFIER_INTERNAL),
107+
Field: aws.String(logIdentifierInternal),
108108
Value: aws.String("fakelog"),
109109
},
110110
},
@@ -145,7 +145,7 @@ func TestLogsResultsToDataframes(t *testing.T) {
145145
aws.String("fakelog"),
146146
})
147147

148-
hiddenLogStreamField := data.NewField(LOGSTREAM_IDENTIFIER_INTERNAL, nil, []*string{
148+
hiddenLogStreamField := data.NewField(logStreamIdentifierInternal, nil, []*string{
149149
aws.String("fakelogstream"),
150150
aws.String("fakelogstream"),
151151
aws.String("fakelogstream"),
@@ -156,7 +156,7 @@ func TestLogsResultsToDataframes(t *testing.T) {
156156
},
157157
})
158158

159-
hiddenLogField := data.NewField(LOG_IDENTIFIER_INTERNAL, nil, []*string{
159+
hiddenLogField := data.NewField(logIdentifierInternal, nil, []*string{
160160
aws.String("fakelog"),
161161
aws.String("fakelog"),
162162
aws.String("fakelog"),

0 commit comments

Comments
 (0)