record_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. package source
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestRecordMetricsQuerier_Counts(t *testing.T) {
  8. start := time.Now().UTC().Truncate(time.Hour)
  9. end := start.Add(time.Hour)
  10. r := NewRecordMetricsQuerier(NewNoOpMetricsQuerier())
  11. r.QueryLocalStorageActiveMinutes(start, end)
  12. r.QueryLocalStorageUsedAvg(start, end)
  13. r.QueryLocalStorageUsedMax(start, end)
  14. r.QueryLocalStorageBytes(start, end)
  15. r.QueryKMLocalStorageUsedAvg(start, end)
  16. r.QueryKMLocalStorageUsedMax(start, end)
  17. r.QueryKMLocalStorageBytes(start, end)
  18. r.QueryNodeInfo(start, end)
  19. r.QueryNodeUptime(start, end)
  20. r.QueryNodeActiveMinutes(start, end)
  21. r.QueryNodeCPUCoresCapacity(start, end)
  22. r.QueryNodeCPUCoresAllocatable(start, end)
  23. r.QueryNodeRAMBytesCapacity(start, end)
  24. r.QueryNodeRAMBytesAllocatable(start, end)
  25. r.QueryNodeGPUCount(start, end)
  26. r.QueryNodeCPUModeTotal(start, end)
  27. r.QueryNodeIsSpot(start, end)
  28. r.QueryNodeRAMSystemPercent(start, end)
  29. r.QueryNodeRAMUserPercent(start, end)
  30. r.QueryNodeResourceCapacities(start, end)
  31. r.QueryNodeResourcesAllocatable(start, end)
  32. r.QueryLBActiveMinutes(start, end)
  33. r.QueryLBPricePerHr(start, end)
  34. r.QueryClusterInfo(start, end)
  35. r.QueryClusterUptime(start, end)
  36. r.QueryClusterManagementDuration(start, end)
  37. r.QueryClusterManagementPricePerHr(start, end)
  38. r.QueryPods(start, end)
  39. r.QueryPodsUID(start, end)
  40. r.QueryPodInfo(start, end)
  41. r.QueryPodUptime(start, end)
  42. r.QueryPodOwners(start, end)
  43. r.QueryPodPVCVolumes(start, end)
  44. r.QueryPodNetworkEgressBytes(start, end)
  45. r.QueryPodNetworkIngressBytes(start, end)
  46. r.QueryContainerUptime(start, end)
  47. r.QueryContainerResourceRequests(start, end)
  48. r.QueryContainerResourceLimits(start, end)
  49. r.QueryRAMBytesAllocated(start, end)
  50. r.QueryRAMRequests(start, end)
  51. r.QueryRAMLimits(start, end)
  52. r.QueryRAMUsageAvg(start, end)
  53. r.QueryRAMUsageMax(start, end)
  54. r.QueryNodeRAMPricePerGiBHr(start, end)
  55. r.QueryCPUCoresAllocated(start, end)
  56. r.QueryCPURequests(start, end)
  57. r.QueryCPULimits(start, end)
  58. r.QueryCPUUsageAvg(start, end)
  59. r.QueryCPUUsageMax(start, end)
  60. r.QueryNodeCPUPricePerHr(start, end)
  61. r.QueryGPUsAllocated(start, end)
  62. r.QueryGPUsRequested(start, end)
  63. r.QueryGPUsUsageAvg(start, end)
  64. r.QueryGPUsUsageMax(start, end)
  65. r.QueryNodeGPUPricePerHr(start, end)
  66. r.QueryGPUInfo(start, end)
  67. r.QueryIsGPUShared(start, end)
  68. r.QueryDCGMDeviceInfo(start, end)
  69. r.QueryDCGMDeviceUptime(start, end)
  70. r.QueryDCGMContainerUsageAvg(start, end)
  71. r.QueryDCGMContainerUsageMax(start, end)
  72. r.QueryPodPVCAllocation(start, end)
  73. r.QueryPVCBytesRequested(start, end)
  74. r.QueryPVCInfo(start, end)
  75. r.QueryKMPVCInfo(start, end)
  76. r.QueryPVCUptime(start, end)
  77. r.QueryPVCBytesUsedAverage(start, end)
  78. r.QueryPVCBytesUsedMax(start, end)
  79. r.QueryPVBytes(start, end)
  80. r.QueryPVPricePerGiBHour(start, end)
  81. r.QueryPVInfo(start, end)
  82. r.QueryPVActiveMinutes(start, end)
  83. r.QueryPVUsedAverage(start, end)
  84. r.QueryPVUsedMax(start, end)
  85. r.QueryKMPVInfo(start, end)
  86. r.QueryPVUptime(start, end)
  87. r.QueryDeploymentInfo(start, end)
  88. r.QueryDeploymentUptime(start, end)
  89. r.QueryDeploymentLabels(start, end)
  90. r.QueryDeploymentAnnotations(start, end)
  91. r.QueryDeploymentMatchLabels(start, end)
  92. r.QueryStatefulSetInfo(start, end)
  93. r.QueryStatefulSetUptime(start, end)
  94. r.QueryStatefulSetLabels(start, end)
  95. r.QueryStatefulSetAnnotations(start, end)
  96. r.QueryStatefulSetMatchLabels(start, end)
  97. r.QueryDaemonSetInfo(start, end)
  98. r.QueryDaemonSetUptime(start, end)
  99. r.QueryDaemonSetLabels(start, end)
  100. r.QueryDaemonSetAnnotations(start, end)
  101. r.QueryJobInfo(start, end)
  102. r.QueryJobUptime(start, end)
  103. r.QueryJobLabels(start, end)
  104. r.QueryJobAnnotations(start, end)
  105. r.QueryCronJobInfo(start, end)
  106. r.QueryCronJobUptime(start, end)
  107. r.QueryCronJobLabels(start, end)
  108. r.QueryCronJobAnnotations(start, end)
  109. r.QueryReplicaSetInfo(start, end)
  110. r.QueryReplicaSetUptime(start, end)
  111. r.QueryReplicaSetLabels(start, end)
  112. r.QueryReplicaSetAnnotations(start, end)
  113. r.QueryReplicaSetOwners(start, end)
  114. r.QueryNamespaceInfo(start, end)
  115. r.QueryNamespaceUptime(start, end)
  116. r.QueryServiceInfo(start, end)
  117. r.QueryServiceUptime(start, end)
  118. r.QueryServiceSelectorLabels(start, end)
  119. r.QueryNetZoneGiB(start, end)
  120. r.QueryNetZonePricePerGiB(start, end)
  121. r.QueryNetRegionGiB(start, end)
  122. r.QueryNetRegionPricePerGiB(start, end)
  123. r.QueryNetInternetGiB(start, end)
  124. r.QueryNetInternetPricePerGiB(start, end)
  125. r.QueryNetInternetServiceGiB(start, end)
  126. r.QueryNetNatGatewayPricePerGiB(start, end)
  127. r.QueryNetNatGatewayGiB(start, end)
  128. r.QueryNetTransferBytes(start, end)
  129. r.QueryNetZoneIngressGiB(start, end)
  130. r.QueryNetRegionIngressGiB(start, end)
  131. r.QueryNetInternetIngressGiB(start, end)
  132. r.QueryNetInternetServiceIngressGiB(start, end)
  133. r.QueryNetNatGatewayIngressPricePerGiB(start, end)
  134. r.QueryNetNatGatewayIngressGiB(start, end)
  135. r.QueryNetReceiveBytes(start, end)
  136. r.QueryNamespaceAnnotations(start, end)
  137. r.QueryPodAnnotations(start, end)
  138. r.QueryNodeLabels(start, end)
  139. r.QueryNamespaceLabels(start, end)
  140. r.QueryPodLabels(start, end)
  141. r.QueryPodsWithDaemonSetOwner(start, end)
  142. r.QueryPodsWithJobOwner(start, end)
  143. r.QueryPodsWithReplicaSetOwner(start, end)
  144. r.QueryReplicaSetsWithoutOwners(start, end)
  145. r.QueryReplicaSetsWithRollout(start, end)
  146. r.QueryResourceQuotaInfo(start, end)
  147. r.QueryResourceQuotaUptime(start, end)
  148. r.QueryResourceQuotaSpecCPURequestAverage(start, end)
  149. r.QueryResourceQuotaSpecCPURequestMax(start, end)
  150. r.QueryResourceQuotaSpecRAMRequestAverage(start, end)
  151. r.QueryResourceQuotaSpecRAMRequestMax(start, end)
  152. r.QueryResourceQuotaSpecCPULimitAverage(start, end)
  153. r.QueryResourceQuotaSpecCPULimitMax(start, end)
  154. r.QueryResourceQuotaSpecRAMLimitAverage(start, end)
  155. r.QueryResourceQuotaSpecRAMLimitMax(start, end)
  156. r.QueryResourceQuotaStatusUsedCPURequestAverage(start, end)
  157. r.QueryResourceQuotaStatusUsedCPURequestMax(start, end)
  158. r.QueryResourceQuotaStatusUsedRAMRequestAverage(start, end)
  159. r.QueryResourceQuotaStatusUsedRAMRequestMax(start, end)
  160. r.QueryResourceQuotaStatusUsedCPULimitAverage(start, end)
  161. r.QueryResourceQuotaStatusUsedCPULimitMax(start, end)
  162. r.QueryResourceQuotaStatusUsedRAMLimitAverage(start, end)
  163. r.QueryResourceQuotaStatusUsedRAMLimitMax(start, end)
  164. r.QueryDataCoverage(30)
  165. expected := map[string]int{
  166. "QueryLocalStorageActiveMinutes": 1,
  167. "QueryLocalStorageUsedAvg": 1,
  168. "QueryLocalStorageUsedMax": 1,
  169. "QueryLocalStorageBytes": 1,
  170. "QueryKMLocalStorageUsedAvg": 1,
  171. "QueryKMLocalStorageUsedMax": 1,
  172. "QueryKMLocalStorageBytes": 1,
  173. "QueryNodeInfo": 1,
  174. "QueryNodeUptime": 1,
  175. "QueryNodeActiveMinutes": 1,
  176. "QueryNodeCPUCoresCapacity": 1,
  177. "QueryNodeCPUCoresAllocatable": 1,
  178. "QueryNodeRAMBytesCapacity": 1,
  179. "QueryNodeRAMBytesAllocatable": 1,
  180. "QueryNodeGPUCount": 1,
  181. "QueryNodeCPUModeTotal": 1,
  182. "QueryNodeIsSpot": 1,
  183. "QueryNodeRAMSystemPercent": 1,
  184. "QueryNodeRAMUserPercent": 1,
  185. "QueryNodeResourceCapacities": 1,
  186. "QueryNodeResourcesAllocatable": 1,
  187. "QueryLBActiveMinutes": 1,
  188. "QueryLBPricePerHr": 1,
  189. "QueryClusterInfo": 1,
  190. "QueryClusterUptime": 1,
  191. "QueryClusterManagementDuration": 1,
  192. "QueryClusterManagementPricePerHr": 1,
  193. "QueryPods": 1,
  194. "QueryPodsUID": 1,
  195. "QueryPodInfo": 1,
  196. "QueryPodUptime": 1,
  197. "QueryPodOwners": 1,
  198. "QueryPodPVCVolumes": 1,
  199. "QueryPodNetworkEgressBytes": 1,
  200. "QueryPodNetworkIngressBytes": 1,
  201. "QueryContainerUptime": 1,
  202. "QueryContainerResourceRequests": 1,
  203. "QueryContainerResourceLimits": 1,
  204. "QueryRAMBytesAllocated": 1,
  205. "QueryRAMRequests": 1,
  206. "QueryRAMLimits": 1,
  207. "QueryRAMUsageAvg": 1,
  208. "QueryRAMUsageMax": 1,
  209. "QueryNodeRAMPricePerGiBHr": 1,
  210. "QueryCPUCoresAllocated": 1,
  211. "QueryCPURequests": 1,
  212. "QueryCPULimits": 1,
  213. "QueryCPUUsageAvg": 1,
  214. "QueryCPUUsageMax": 1,
  215. "QueryNodeCPUPricePerHr": 1,
  216. "QueryGPUsAllocated": 1,
  217. "QueryGPUsRequested": 1,
  218. "QueryGPUsUsageAvg": 1,
  219. "QueryGPUsUsageMax": 1,
  220. "QueryNodeGPUPricePerHr": 1,
  221. "QueryGPUInfo": 1,
  222. "QueryIsGPUShared": 1,
  223. "QueryDCGMDeviceInfo": 1,
  224. "QueryDCGMDeviceUptime": 1,
  225. "QueryDCGMContainerUsageAvg": 1,
  226. "QueryDCGMContainerUsageMax": 1,
  227. "QueryPodPVCAllocation": 1,
  228. "QueryPVCBytesRequested": 1,
  229. "QueryPVCInfo": 1,
  230. "QueryKMPVCInfo": 1,
  231. "QueryPVCUptime": 1,
  232. "QueryPVCBytesUsedAverage": 1,
  233. "QueryPVCBytesUsedMax": 1,
  234. "QueryPVBytes": 1,
  235. "QueryPVPricePerGiBHour": 1,
  236. "QueryPVInfo": 1,
  237. "QueryPVActiveMinutes": 1,
  238. "QueryPVUsedAverage": 1,
  239. "QueryPVUsedMax": 1,
  240. "QueryKMPVInfo": 1,
  241. "QueryPVUptime": 1,
  242. "QueryDeploymentInfo": 1,
  243. "QueryDeploymentUptime": 1,
  244. "QueryDeploymentLabels": 1,
  245. "QueryDeploymentAnnotations": 1,
  246. "QueryDeploymentMatchLabels": 1,
  247. "QueryStatefulSetInfo": 1,
  248. "QueryStatefulSetUptime": 1,
  249. "QueryStatefulSetLabels": 1,
  250. "QueryStatefulSetAnnotations": 1,
  251. "QueryStatefulSetMatchLabels": 1,
  252. "QueryDaemonSetInfo": 1,
  253. "QueryDaemonSetUptime": 1,
  254. "QueryDaemonSetLabels": 1,
  255. "QueryDaemonSetAnnotations": 1,
  256. "QueryJobInfo": 1,
  257. "QueryJobUptime": 1,
  258. "QueryJobLabels": 1,
  259. "QueryJobAnnotations": 1,
  260. "QueryCronJobInfo": 1,
  261. "QueryCronJobUptime": 1,
  262. "QueryCronJobLabels": 1,
  263. "QueryCronJobAnnotations": 1,
  264. "QueryReplicaSetInfo": 1,
  265. "QueryReplicaSetUptime": 1,
  266. "QueryReplicaSetLabels": 1,
  267. "QueryReplicaSetAnnotations": 1,
  268. "QueryReplicaSetOwners": 1,
  269. "QueryNamespaceInfo": 1,
  270. "QueryNamespaceUptime": 1,
  271. "QueryServiceInfo": 1,
  272. "QueryServiceUptime": 1,
  273. "QueryServiceSelectorLabels": 1,
  274. "QueryNetZoneGiB": 1,
  275. "QueryNetZonePricePerGiB": 1,
  276. "QueryNetRegionGiB": 1,
  277. "QueryNetRegionPricePerGiB": 1,
  278. "QueryNetInternetGiB": 1,
  279. "QueryNetInternetPricePerGiB": 1,
  280. "QueryNetInternetServiceGiB": 1,
  281. "QueryNetNatGatewayPricePerGiB": 1,
  282. "QueryNetNatGatewayGiB": 1,
  283. "QueryNetTransferBytes": 1,
  284. "QueryNetZoneIngressGiB": 1,
  285. "QueryNetRegionIngressGiB": 1,
  286. "QueryNetInternetIngressGiB": 1,
  287. "QueryNetInternetServiceIngressGiB": 1,
  288. "QueryNetNatGatewayIngressPricePerGiB": 1,
  289. "QueryNetNatGatewayIngressGiB": 1,
  290. "QueryNetReceiveBytes": 1,
  291. "QueryNamespaceAnnotations": 1,
  292. "QueryPodAnnotations": 1,
  293. "QueryNodeLabels": 1,
  294. "QueryNamespaceLabels": 1,
  295. "QueryPodLabels": 1,
  296. "QueryPodsWithDaemonSetOwner": 1,
  297. "QueryPodsWithJobOwner": 1,
  298. "QueryPodsWithReplicaSetOwner": 1,
  299. "QueryReplicaSetsWithoutOwners": 1,
  300. "QueryReplicaSetsWithRollout": 1,
  301. "QueryResourceQuotaInfo": 1,
  302. "QueryResourceQuotaUptime": 1,
  303. "QueryResourceQuotaSpecCPURequestAverage": 1,
  304. "QueryResourceQuotaSpecCPURequestMax": 1,
  305. "QueryResourceQuotaSpecRAMRequestAverage": 1,
  306. "QueryResourceQuotaSpecRAMRequestMax": 1,
  307. "QueryResourceQuotaSpecCPULimitAverage": 1,
  308. "QueryResourceQuotaSpecCPULimitMax": 1,
  309. "QueryResourceQuotaSpecRAMLimitAverage": 1,
  310. "QueryResourceQuotaSpecRAMLimitMax": 1,
  311. "QueryResourceQuotaStatusUsedCPURequestAverage": 1,
  312. "QueryResourceQuotaStatusUsedCPURequestMax": 1,
  313. "QueryResourceQuotaStatusUsedRAMRequestAverage": 1,
  314. "QueryResourceQuotaStatusUsedRAMRequestMax": 1,
  315. "QueryResourceQuotaStatusUsedCPULimitAverage": 1,
  316. "QueryResourceQuotaStatusUsedCPULimitMax": 1,
  317. "QueryResourceQuotaStatusUsedRAMLimitAverage": 1,
  318. "QueryResourceQuotaStatusUsedRAMLimitMax": 1,
  319. "QueryDataCoverage": 1,
  320. }
  321. require.Equal(t, expected, r.Calls)
  322. }