mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: Fix variable naming (#24650)
* CloudWatch: Fix variable naming
This commit is contained in:
parent
792e99918c
commit
0860dfe45d
@ -38,11 +38,11 @@ type DatasourceInfo struct {
|
|||||||
SecretKey string
|
SecretKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
const CLOUDWATCH_TS_FORMAT = "2006-01-02 15:04:05.000"
|
const cloudWatchTSFormat = "2006-01-02 15:04:05.000"
|
||||||
|
|
||||||
// Constants also defined in datasource/cloudwatch/datasource.ts
|
// Constants also defined in datasource/cloudwatch/datasource.ts
|
||||||
const LOG_IDENTIFIER_INTERNAL = "__log__grafana_internal__"
|
const logIdentifierInternal = "__log__grafana_internal__"
|
||||||
const LOGSTREAM_IDENTIFIER_INTERNAL = "__logstream__grafana_internal__"
|
const logStreamIdentifierInternal = "__logstream__grafana_internal__"
|
||||||
|
|
||||||
func (e *CloudWatchExecutor) getLogsClient(region string) (*cloudwatchlogs.CloudWatchLogs, error) {
|
func (e *CloudWatchExecutor) getLogsClient(region string) (*cloudwatchlogs.CloudWatchLogs, error) {
|
||||||
e.mux.Lock()
|
e.mux.Lock()
|
||||||
@ -226,7 +226,7 @@ func queryResultsToDataframe(results *cloudwatchlogs.GetQueryResultsOutput) (*da
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, exists := fieldValues[*resultField.Field]; !exists {
|
if _, exists := fieldValues[*resultField.Field]; !exists {
|
||||||
if _, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value); err == nil {
|
if _, err := time.Parse(cloudWatchTSFormat, *resultField.Value); err == nil {
|
||||||
fieldValues[*resultField.Field] = make([]*time.Time, rowCount)
|
fieldValues[*resultField.Field] = make([]*time.Time, rowCount)
|
||||||
} else if _, err := strconv.ParseFloat(*resultField.Value, 64); err == nil {
|
} else if _, err := strconv.ParseFloat(*resultField.Value, 64); err == nil {
|
||||||
fieldValues[*resultField.Field] = make([]*float64, rowCount)
|
fieldValues[*resultField.Field] = make([]*float64, rowCount)
|
||||||
@ -236,7 +236,7 @@ func queryResultsToDataframe(results *cloudwatchlogs.GetQueryResultsOutput) (*da
|
|||||||
}
|
}
|
||||||
|
|
||||||
if timeField, ok := fieldValues[*resultField.Field].([]*time.Time); ok {
|
if timeField, ok := fieldValues[*resultField.Field].([]*time.Time); ok {
|
||||||
parsedTime, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value)
|
parsedTime, err := time.Parse(cloudWatchTSFormat, *resultField.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (e *CloudWatchExecutor) executeStartQuery(ctx context.Context, logsClient c
|
|||||||
EndTime: aws.Int64(endTime.Unix()),
|
EndTime: aws.Int64(endTime.Unix()),
|
||||||
Limit: aws.Int64(parameters.Get("limit").MustInt64(1000)),
|
Limit: aws.Int64(parameters.Get("limit").MustInt64(1000)),
|
||||||
LogGroupNames: aws.StringSlice(parameters.Get("logGroupNames").MustStringArray()),
|
LogGroupNames: aws.StringSlice(parameters.Get("logGroupNames").MustStringArray()),
|
||||||
QueryString: aws.String("fields @timestamp,ltrim(@log) as " + LOG_IDENTIFIER_INTERNAL + ",ltrim(@logStream) as " + LOGSTREAM_IDENTIFIER_INTERNAL + "|" + parameters.Get("queryString").MustString("")),
|
QueryString: aws.String("fields @timestamp,ltrim(@log) as " + logIdentifierInternal + ",ltrim(@logStream) as " + logStreamIdentifierInternal + "|" + parameters.Get("queryString").MustString("")),
|
||||||
}
|
}
|
||||||
return logsClient.StartQueryWithContext(ctx, startQueryInput)
|
return logsClient.StartQueryWithContext(ctx, startQueryInput)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
|
|||||||
fieldNames = append(fieldNames, resultField.Field)
|
fieldNames = append(fieldNames, resultField.Field)
|
||||||
|
|
||||||
// Check if field is time field
|
// Check if field is time field
|
||||||
if _, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value); err == nil {
|
if _, err := time.Parse(cloudWatchTSFormat, *resultField.Value); err == nil {
|
||||||
fieldValues[*resultField.Field] = make([]*time.Time, rowCount)
|
fieldValues[*resultField.Field] = make([]*time.Time, rowCount)
|
||||||
} else {
|
} else {
|
||||||
fieldValues[*resultField.Field] = make([]*string, rowCount)
|
fieldValues[*resultField.Field] = make([]*string, rowCount)
|
||||||
@ -34,7 +34,7 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if timeField, ok := fieldValues[*resultField.Field].([]*time.Time); ok {
|
if timeField, ok := fieldValues[*resultField.Field].([]*time.Time); ok {
|
||||||
parsedTime, err := time.Parse(CLOUDWATCH_TS_FORMAT, *resultField.Value)
|
parsedTime, err := time.Parse(cloudWatchTSFormat, *resultField.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
|
|||||||
|
|
||||||
if *fieldName == "@timestamp" {
|
if *fieldName == "@timestamp" {
|
||||||
newFields[len(newFields)-1].SetConfig(&data.FieldConfig{Title: "Time"})
|
newFields[len(newFields)-1].SetConfig(&data.FieldConfig{Title: "Time"})
|
||||||
} else if *fieldName == LOGSTREAM_IDENTIFIER_INTERNAL || *fieldName == LOG_IDENTIFIER_INTERNAL {
|
} else if *fieldName == logStreamIdentifierInternal || *fieldName == logIdentifierInternal {
|
||||||
newFields[len(newFields)-1].SetConfig(
|
newFields[len(newFields)-1].SetConfig(
|
||||||
&data.FieldConfig{
|
&data.FieldConfig{
|
||||||
Custom: map[string]interface{}{
|
Custom: map[string]interface{}{
|
||||||
|
@ -40,11 +40,11 @@ func TestLogsResultsToDataframes(t *testing.T) {
|
|||||||
Value: aws.String("fakelog"),
|
Value: aws.String("fakelog"),
|
||||||
},
|
},
|
||||||
&cloudwatchlogs.ResultField{
|
&cloudwatchlogs.ResultField{
|
||||||
Field: aws.String(LOGSTREAM_IDENTIFIER_INTERNAL),
|
Field: aws.String(logStreamIdentifierInternal),
|
||||||
Value: aws.String("fakelogstream"),
|
Value: aws.String("fakelogstream"),
|
||||||
},
|
},
|
||||||
&cloudwatchlogs.ResultField{
|
&cloudwatchlogs.ResultField{
|
||||||
Field: aws.String(LOG_IDENTIFIER_INTERNAL),
|
Field: aws.String(logIdentifierInternal),
|
||||||
Value: aws.String("fakelog"),
|
Value: aws.String("fakelog"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -70,11 +70,11 @@ func TestLogsResultsToDataframes(t *testing.T) {
|
|||||||
Value: aws.String("fakelog"),
|
Value: aws.String("fakelog"),
|
||||||
},
|
},
|
||||||
&cloudwatchlogs.ResultField{
|
&cloudwatchlogs.ResultField{
|
||||||
Field: aws.String(LOGSTREAM_IDENTIFIER_INTERNAL),
|
Field: aws.String(logStreamIdentifierInternal),
|
||||||
Value: aws.String("fakelogstream"),
|
Value: aws.String("fakelogstream"),
|
||||||
},
|
},
|
||||||
&cloudwatchlogs.ResultField{
|
&cloudwatchlogs.ResultField{
|
||||||
Field: aws.String(LOG_IDENTIFIER_INTERNAL),
|
Field: aws.String(logIdentifierInternal),
|
||||||
Value: aws.String("fakelog"),
|
Value: aws.String("fakelog"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -100,11 +100,11 @@ func TestLogsResultsToDataframes(t *testing.T) {
|
|||||||
Value: aws.String("fakelog"),
|
Value: aws.String("fakelog"),
|
||||||
},
|
},
|
||||||
&cloudwatchlogs.ResultField{
|
&cloudwatchlogs.ResultField{
|
||||||
Field: aws.String(LOGSTREAM_IDENTIFIER_INTERNAL),
|
Field: aws.String(logStreamIdentifierInternal),
|
||||||
Value: aws.String("fakelogstream"),
|
Value: aws.String("fakelogstream"),
|
||||||
},
|
},
|
||||||
&cloudwatchlogs.ResultField{
|
&cloudwatchlogs.ResultField{
|
||||||
Field: aws.String(LOG_IDENTIFIER_INTERNAL),
|
Field: aws.String(logIdentifierInternal),
|
||||||
Value: aws.String("fakelog"),
|
Value: aws.String("fakelog"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -145,7 +145,7 @@ func TestLogsResultsToDataframes(t *testing.T) {
|
|||||||
aws.String("fakelog"),
|
aws.String("fakelog"),
|
||||||
})
|
})
|
||||||
|
|
||||||
hiddenLogStreamField := data.NewField(LOGSTREAM_IDENTIFIER_INTERNAL, nil, []*string{
|
hiddenLogStreamField := data.NewField(logStreamIdentifierInternal, nil, []*string{
|
||||||
aws.String("fakelogstream"),
|
aws.String("fakelogstream"),
|
||||||
aws.String("fakelogstream"),
|
aws.String("fakelogstream"),
|
||||||
aws.String("fakelogstream"),
|
aws.String("fakelogstream"),
|
||||||
@ -156,7 +156,7 @@ func TestLogsResultsToDataframes(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
hiddenLogField := data.NewField(LOG_IDENTIFIER_INTERNAL, nil, []*string{
|
hiddenLogField := data.NewField(logIdentifierInternal, nil, []*string{
|
||||||
aws.String("fakelog"),
|
aws.String("fakelog"),
|
||||||
aws.String("fakelog"),
|
aws.String("fakelog"),
|
||||||
aws.String("fakelog"),
|
aws.String("fakelog"),
|
||||||
|
Loading…
Reference in New Issue
Block a user