models.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package elasticsearch
  2. import (
  3. "github.com/grafana/grafana/pkg/components/simplejson"
  4. )
  5. // Query represents the time series query model of the datasource
  6. type Query struct {
  7. TimeField string `json:"timeField"`
  8. RawQuery string `json:"query"`
  9. BucketAggs []*BucketAgg `json:"bucketAggs"`
  10. Metrics []*MetricAgg `json:"metrics"`
  11. Alias string `json:"alias"`
  12. Interval string
  13. RefID string
  14. }
  15. // BucketAgg represents a bucket aggregation of the time series query model of the datasource
  16. type BucketAgg struct {
  17. Field string `json:"field"`
  18. ID string `json:"id"`
  19. Settings *simplejson.Json `json:"settings"`
  20. Type string `jsons:"type"`
  21. }
  22. // MetricAgg represents a metric aggregation of the time series query model of the datasource
  23. type MetricAgg struct {
  24. Field string `json:"field"`
  25. Hide bool `json:"hide"`
  26. ID string `json:"id"`
  27. PipelineAggregate string `json:"pipelineAgg"`
  28. PipelineVariables map[string]string `json:"pipelineVariables"`
  29. Settings *simplejson.Json `json:"settings"`
  30. Meta *simplejson.Json `json:"meta"`
  31. Type string `json:"type"`
  32. }
  33. var metricAggType = map[string]string{
  34. "count": "Count",
  35. "avg": "Average",
  36. "sum": "Sum",
  37. "max": "Max",
  38. "min": "Min",
  39. "extended_stats": "Extended Stats",
  40. "percentiles": "Percentiles",
  41. "cardinality": "Unique Count",
  42. "moving_avg": "Moving Average",
  43. "derivative": "Derivative",
  44. "bucket_script": "Bucket Script",
  45. "raw_document": "Raw Document",
  46. }
  47. var extendedStats = map[string]string{
  48. "avg": "Avg",
  49. "min": "Min",
  50. "max": "Max",
  51. "sum": "Sum",
  52. "count": "Count",
  53. "std_deviation": "Std Dev",
  54. "std_deviation_bounds_upper": "Std Dev Upper",
  55. "std_deviation_bounds_lower": "Std Dev Lower",
  56. }
  57. var pipelineAggType = map[string]string{
  58. "moving_avg": "moving_avg",
  59. "derivative": "derivative",
  60. "bucket_script": "bucket_script",
  61. }
  62. var pipelineAggWithMultipleBucketPathsType = map[string]string{
  63. "bucket_script": "bucket_script",
  64. }
  65. func isPipelineAgg(metricType string) bool {
  66. if _, ok := pipelineAggType[metricType]; ok {
  67. return true
  68. }
  69. return false
  70. }
  71. func isPipelineAggWithMultipleBucketPaths(metricType string) bool {
  72. if _, ok := pipelineAggWithMultipleBucketPathsType[metricType]; ok {
  73. return true
  74. }
  75. return false
  76. }
  77. func describeMetric(metricType, field string) string {
  78. text := metricAggType[metricType]
  79. if metricType == countType {
  80. return text
  81. }
  82. return text + " " + field
  83. }