github.com/thanos-io/thanos@v0.32.5/pkg/query/testdata/promql/thanos/aggregators.test (about) 1 store {} 0 30m 2 3 load 5m 4 http_requests{job="api-server", instance="0", group="production"} 0+10x10 5 http_requests{job="api-server", instance="1", group="production"} 0+20x10 6 http_requests{job="api-server", instance="0", group="canary"} 0+30x10 7 http_requests{job="api-server", instance="1", group="canary"} 0+40x10 8 9 store {} 30m 10d 10 11 load 5m 12 http_requests{job="api-server", instance="0", group="production"} 0+10x10 13 http_requests{job="api-server", instance="1", group="production"} 0+20x10 14 http_requests{job="api-server", instance="0", group="canary"} 0+30x10 15 http_requests{job="api-server", instance="1", group="canary"} 0+40x10 16 17 store {} 0 30m 18 19 load 5m 20 http_requests{job="app-server", instance="0", group="production"} 0+50x10 21 http_requests{job="app-server", instance="1", group="production"} 0+60x10 22 http_requests{job="app-server", instance="0", group="canary"} 0+70x10 23 http_requests{job="app-server", instance="1", group="canary"} 0+80x10 24 25 store {} 30m 10d 26 27 load 5m 28 http_requests{job="app-server", instance="0", group="production"} 0+50x10 29 http_requests{job="app-server", instance="1", group="production"} 0+60x10 30 http_requests{job="app-server", instance="0", group="canary"} 0+70x10 31 http_requests{job="app-server", instance="1", group="canary"} 0+80x10 32 33 store {} 0 10d 34 35 load 5m 36 foo{job="api-server", instance="0", region="europe"} 0+90x10 37 foo{job="api-server"} 0+100x10 38 39 # Simple sum. 40 eval instant at 50m SUM BY (group) (http_requests{job="api-server"}) 41 {group="canary"} 700 42 {group="production"} 300 43 44 eval instant at 50m SUM BY (group) (((http_requests{job="api-server"}))) 45 {group="canary"} 700 46 {group="production"} 300 47 48 # Test alternative "by"-clause order. 49 eval instant at 50m sum by (group) (http_requests{job="api-server"}) 50 {group="canary"} 700 51 {group="production"} 300 52 53 # Simple average. 54 eval instant at 50m avg by (group) (http_requests{job="api-server"}) 55 {group="canary"} 350 56 {group="production"} 150 57 58 # Simple count. 59 eval instant at 50m count by (group) (http_requests{job="api-server"}) 60 {group="canary"} 2 61 {group="production"} 2 62 63 # Simple without. 64 eval instant at 50m sum without (instance) (http_requests{job="api-server"}) 65 {group="canary",job="api-server"} 700 66 {group="production",job="api-server"} 300 67 68 # Empty by. 69 eval instant at 50m sum by () (http_requests{job="api-server"}) 70 {} 1000 71 72 # No by/without. 73 eval instant at 50m sum(http_requests{job="api-server"}) 74 {} 1000 75 76 # Empty without. 77 eval instant at 50m sum without () (http_requests{job="api-server",group="production"}) 78 {group="production",job="api-server",instance="0"} 100 79 {group="production",job="api-server",instance="1"} 200 80 81 # Without with mismatched and missing labels. Do not do this. 82 eval instant at 50m sum without (instance) (http_requests{job="api-server"} or foo) 83 {group="canary",job="api-server"} 700 84 {group="production",job="api-server"} 300 85 {region="europe",job="api-server"} 900 86 {job="api-server"} 1000 87 88 # Lower-cased aggregation operators should work too. 89 eval instant at 50m sum(http_requests) by (job) + min(http_requests) by (job) + max(http_requests) by (job) + avg(http_requests) by (job) 90 {job="app-server"} 4550 91 {job="api-server"} 1750 92 93 # Test alternative "by"-clause order. 94 eval instant at 50m sum by (group) (http_requests{job="api-server"}) 95 {group="canary"} 700 96 {group="production"} 300 97 98 # Test both alternative "by"-clause orders in one expression. 99 # Public health warning: stick to one form within an expression (or even 100 # in an organization), or risk serious user confusion. 101 eval instant at 50m sum(sum by (group) (http_requests{job="api-server"})) by (job) 102 {} 1000 103 104 eval instant at 50m SUM(http_requests) 105 {} 3600 106 107 eval instant at 50m SUM(http_requests{instance="0"}) BY(job) 108 {job="api-server"} 400 109 {job="app-server"} 1200 110 111 eval instant at 50m SUM(http_requests) BY (job) 112 {job="api-server"} 1000 113 {job="app-server"} 2600 114 115 # Non-existent labels mentioned in BY-clauses shouldn't propagate to output. 116 eval instant at 50m SUM(http_requests) BY (job, nonexistent) 117 {job="api-server"} 1000 118 {job="app-server"} 2600 119 120 eval instant at 50m COUNT(http_requests) BY (job) 121 {job="api-server"} 4 122 {job="app-server"} 4 123 124 eval instant at 50m SUM(http_requests) BY (job, group) 125 {group="canary", job="api-server"} 700 126 {group="canary", job="app-server"} 1500 127 {group="production", job="api-server"} 300 128 {group="production", job="app-server"} 1100 129 130 eval instant at 50m AVG(http_requests) BY (job) 131 {job="api-server"} 250 132 {job="app-server"} 650 133 134 eval instant at 50m MIN(http_requests) BY (job) 135 {job="api-server"} 100 136 {job="app-server"} 500 137 138 eval instant at 50m MAX(http_requests) BY (job) 139 {job="api-server"} 400 140 {job="app-server"} 800 141 142 eval instant at 50m abs(-1 * http_requests{group="production",job="api-server"}) 143 {group="production", instance="0", job="api-server"} 100 144 {group="production", instance="1", job="api-server"} 200 145 146 eval instant at 50m floor(0.004 * http_requests{group="production",job="api-server"}) 147 {group="production", instance="0", job="api-server"} 0 148 {group="production", instance="1", job="api-server"} 0 149 150 eval instant at 50m ceil(0.004 * http_requests{group="production",job="api-server"}) 151 {group="production", instance="0", job="api-server"} 1 152 {group="production", instance="1", job="api-server"} 1 153 154 eval instant at 50m round(0.004 * http_requests{group="production",job="api-server"}) 155 {group="production", instance="0", job="api-server"} 0 156 {group="production", instance="1", job="api-server"} 1 157 158 # Round should correctly handle negative numbers. 159 eval instant at 50m round(-1 * (0.004 * http_requests{group="production",job="api-server"})) 160 {group="production", instance="0", job="api-server"} 0 161 {group="production", instance="1", job="api-server"} -1 162 163 # Round should round half up. 164 eval instant at 50m round(0.005 * http_requests{group="production",job="api-server"}) 165 {group="production", instance="0", job="api-server"} 1 166 {group="production", instance="1", job="api-server"} 1 167 168 eval instant at 50m round(-1 * (0.005 * http_requests{group="production",job="api-server"})) 169 {group="production", instance="0", job="api-server"} 0 170 {group="production", instance="1", job="api-server"} -1 171 172 eval instant at 50m round(1 + 0.005 * http_requests{group="production",job="api-server"}) 173 {group="production", instance="0", job="api-server"} 2 174 {group="production", instance="1", job="api-server"} 2 175 176 eval instant at 50m round(-1 * (1 + 0.005 * http_requests{group="production",job="api-server"})) 177 {group="production", instance="0", job="api-server"} -1 178 {group="production", instance="1", job="api-server"} -2 179 180 # Round should accept the number to round nearest to. 181 eval instant at 50m round(0.0005 * http_requests{group="production",job="api-server"}, 0.1) 182 {group="production", instance="0", job="api-server"} 0.1 183 {group="production", instance="1", job="api-server"} 0.1 184 185 eval instant at 50m round(2.1 + 0.0005 * http_requests{group="production",job="api-server"}, 0.1) 186 {group="production", instance="0", job="api-server"} 2.2 187 {group="production", instance="1", job="api-server"} 2.2 188 189 eval instant at 50m round(5.2 + 0.0005 * http_requests{group="production",job="api-server"}, 0.1) 190 {group="production", instance="0", job="api-server"} 5.3 191 {group="production", instance="1", job="api-server"} 5.3 192 193 # Round should work correctly with negative numbers and multiple decimal places. 194 eval instant at 50m round(-1 * (5.2 + 0.0005 * http_requests{group="production",job="api-server"}), 0.1) 195 {group="production", instance="0", job="api-server"} -5.2 196 {group="production", instance="1", job="api-server"} -5.3 197 198 # Round should work correctly with big toNearests. 199 eval instant at 50m round(0.025 * http_requests{group="production",job="api-server"}, 5) 200 {group="production", instance="0", job="api-server"} 5 201 {group="production", instance="1", job="api-server"} 5 202 203 eval instant at 50m round(0.045 * http_requests{group="production",job="api-server"}, 5) 204 {group="production", instance="0", job="api-server"} 5 205 {group="production", instance="1", job="api-server"} 10 206 207 # Standard deviation and variance. 208 eval instant at 50m stddev(http_requests) 209 {} 229.12878474779 210 211 eval instant at 50m stddev by (instance)(http_requests) 212 {instance="0"} 223.60679774998 213 {instance="1"} 223.60679774998 214 215 eval instant at 50m stdvar(http_requests) 216 {} 52500 217 218 eval instant at 50m stdvar by (instance)(http_requests) 219 {instance="0"} 50000 220 {instance="1"} 50000