mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* CloudWatch: Datasource improvements * Add statistic as template variale * Add wildcard to list of values * Template variable intercept dimension key * Return row specific errors when transformation error occured * Add meta feedback * Make it possible to retrieve values without known metrics * Add curated dashboard for EC2 * Fix broken tests * Use correct dashboard name * Display alert in case multi template var is being used for some certain props in the cloudwatch query * Minor fixes after feedback * Update dashboard json * Update snapshot test * Make sure region default is intercepted in cloudwatch link * Update dashboards * Include ec2 dashboard in ds * Do not include ec2 dashboard in beta1 * Display actual region
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package cloudwatch
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type cloudWatchQuery struct {
|
|
RefId string
|
|
Region string
|
|
Id string
|
|
Namespace string
|
|
MetricName string
|
|
Stats string
|
|
Expression string
|
|
ReturnData bool
|
|
Dimensions map[string][]string
|
|
Period int
|
|
Alias string
|
|
Identifier string
|
|
HighResolution bool
|
|
MatchExact bool
|
|
UsedExpression string
|
|
RequestExceededMaxLimit bool
|
|
}
|
|
|
|
func (q *cloudWatchQuery) isMathExpression() bool {
|
|
return q.Expression != "" && !q.isUserDefinedSearchExpression()
|
|
}
|
|
|
|
func (q *cloudWatchQuery) isSearchExpression() bool {
|
|
return q.isUserDefinedSearchExpression() || q.isInferredSearchExpression()
|
|
}
|
|
|
|
func (q *cloudWatchQuery) isUserDefinedSearchExpression() bool {
|
|
return strings.Contains(q.Expression, "SEARCH(")
|
|
}
|
|
|
|
func (q *cloudWatchQuery) isInferredSearchExpression() bool {
|
|
if len(q.Dimensions) == 0 {
|
|
return !q.MatchExact
|
|
}
|
|
|
|
if !q.MatchExact {
|
|
return true
|
|
}
|
|
|
|
for _, values := range q.Dimensions {
|
|
if len(values) > 1 {
|
|
return true
|
|
}
|
|
for _, v := range values {
|
|
if v == "*" {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (q *cloudWatchQuery) isMetricStat() bool {
|
|
return !q.isSearchExpression() && !q.isMathExpression()
|
|
}
|