decoders.go 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. package source
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/core/pkg/log"
  5. "github.com/opencost/opencost/core/pkg/util"
  6. )
  7. const (
  8. ProviderLabel = "provider"
  9. AccountIDLabel = "account_id"
  10. ClusterNameLabel = "cluster_name"
  11. RegionLabel = "region"
  12. ClusterIDLabel = "cluster_id"
  13. NamespaceLabel = "namespace"
  14. NamespaceUIDLabel = "namespace_uid"
  15. NodeLabel = "node"
  16. NodeUIDLabel = "node_uid"
  17. InstanceLabel = "instance"
  18. InstanceTypeLabel = "instance_type"
  19. ContainerLabel = "container"
  20. PodLabel = "pod"
  21. PodUIDLabel = "pod_uid"
  22. PodNameLabel = "pod_name"
  23. PodVolumeNameLabel = "pod_volume_name"
  24. ProviderIDLabel = "provider_id"
  25. DeviceLabel = "device"
  26. PVCLabel = "persistentvolumeclaim"
  27. PVCUIDLabel = "persistentvolumeclaim_uid"
  28. PVLabel = "persistentvolume"
  29. CSIVolumeHandleLabel = "csi_volume_handle"
  30. StorageClassLabel = "storageclass"
  31. VolumeNameLabel = "volumename"
  32. PVUIDLabel = "persistentvolume_uid"
  33. ServiceLabel = "service"
  34. ServiceNameLabel = "service_name"
  35. ServiceTypeLabel = "service_type"
  36. IngressIPLabel = "ingress_ip"
  37. LBIngressAddress = "lb_ingress_address"
  38. ProvisionerNameLabel = "provisioner_name"
  39. UIDLabel = "uid"
  40. KubernetesNodeLabel = "kubernetes_node"
  41. ModeLabel = "mode"
  42. ModelNameLabel = "modelName"
  43. HostNameLabel = "Hostname"
  44. UUIDLabel = "UUID"
  45. ResourceLabel = "resource"
  46. DeploymentLabel = "deployment"
  47. StatefulSetLabel = "statefulSet"
  48. DaemonSetLabel = "daemonset"
  49. JobLabel = "job"
  50. CronJobLabel = "cronjob"
  51. ReplicaSetLabel = "replicaset"
  52. ResourceQuotaLabel = "resourcequota"
  53. OwnerNameLabel = "owner_name"
  54. OwnerKindLabel = "owner_kind"
  55. OwnerUIDLabel = "owner_uid"
  56. ControllerLabel = "controller"
  57. UnitLabel = "unit"
  58. InternetLabel = "internet"
  59. SameZoneLabel = "same_zone"
  60. SameRegionLabel = "same_region"
  61. NatGatewayLabel = "nat_gateway"
  62. )
  63. const (
  64. NoneLabelValue = "<none>"
  65. )
  66. type UIDValueResult struct {
  67. UID string
  68. Value float64
  69. }
  70. func DecodeUIDValueResult(result *QueryResult) *UIDValueResult {
  71. return decodeValueResult(result, UIDLabel)
  72. }
  73. type NodeUIDValueResult UIDValueResult
  74. func DecodeNodeUIDValueResult(result *QueryResult) *NodeUIDValueResult {
  75. return (*NodeUIDValueResult)(decodeValueResult(result, NodeUIDLabel))
  76. }
  77. func decodeValueResult(result *QueryResult, uidLabel string) *UIDValueResult {
  78. uid, _ := result.GetString(uidLabel)
  79. var value float64
  80. if len(result.Values) > 0 {
  81. value = result.Values[0].Value
  82. } else {
  83. log.Warnf("Error decoding value for uid '%s': empty value returned", uid)
  84. }
  85. return &UIDValueResult{
  86. UID: uid,
  87. Value: value,
  88. }
  89. }
  90. // UptimeResult represents the first and last recorded sample timestamp within the query window
  91. type UptimeResult struct {
  92. UID string
  93. First time.Time
  94. Last time.Time
  95. }
  96. func (res *UptimeResult) GetStartEnd(windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
  97. return getStartEnd(res.First, res.Last, windowStart, windowEnd, resolution)
  98. }
  99. func DecodeUptimeResult(result *QueryResult) *UptimeResult {
  100. uid, _ := result.GetString(UIDLabel)
  101. first := time.Unix(int64(result.Values[0].Timestamp), 0).UTC()
  102. last := time.Unix(int64(result.Values[len(result.Values)-1].Timestamp), 0).UTC()
  103. return &UptimeResult{
  104. UID: uid,
  105. First: first,
  106. Last: last,
  107. }
  108. }
  109. // Container requires some special results because container name and pod UID is required to uniqly identify it
  110. type ContainerUptimeResult struct {
  111. UptimeResult
  112. Container string
  113. }
  114. func DecodeContainerUptimeResult(result *QueryResult) *ContainerUptimeResult {
  115. container, _ := result.GetString(ContainerLabel)
  116. ur := DecodeUptimeResult(result)
  117. return &ContainerUptimeResult{
  118. UptimeResult: *ur,
  119. Container: container,
  120. }
  121. }
  122. type ContainerResourceResult struct {
  123. ResourceResult
  124. Container string
  125. }
  126. func DecodeContainerResourceResult(result *QueryResult) *ContainerResourceResult {
  127. container, _ := result.GetString(ContainerLabel)
  128. rr := DecodeResourceResult(result)
  129. return &ContainerResourceResult{
  130. ResourceResult: *rr,
  131. Container: container,
  132. }
  133. }
  134. type LabelsResult struct {
  135. UID string
  136. Cluster string
  137. Labels map[string]string
  138. }
  139. func DecodeLabelsResult(result *QueryResult) *LabelsResult {
  140. uid, _ := result.GetString(UIDLabel)
  141. cluster, _ := result.GetCluster()
  142. labels := result.GetLabels()
  143. return &LabelsResult{
  144. UID: uid,
  145. Cluster: cluster,
  146. Labels: labels,
  147. }
  148. }
  149. type AnnotationsResult struct {
  150. UID string
  151. Cluster string
  152. Annotations map[string]string
  153. }
  154. func DecodeAnnotationsResult(result *QueryResult) *AnnotationsResult {
  155. uid, _ := result.GetString(UIDLabel)
  156. cluster, _ := result.GetCluster()
  157. annotations := result.GetAnnotations()
  158. return &AnnotationsResult{
  159. UID: uid,
  160. Cluster: cluster,
  161. Annotations: annotations,
  162. }
  163. }
  164. type PVResult struct {
  165. Cluster string
  166. PersistentVolume string
  167. }
  168. type PVUsedAvgResult struct {
  169. Cluster string
  170. Namespace string
  171. PersistentVolumeClaim string
  172. Data []*util.Vector
  173. }
  174. func DecodePVUsedAvgResult(result *QueryResult) *PVUsedAvgResult {
  175. cluster, _ := result.GetCluster()
  176. namespace, _ := result.GetNamespace()
  177. pvc, _ := result.GetString(PVCLabel)
  178. return &PVUsedAvgResult{
  179. Cluster: cluster,
  180. Namespace: namespace,
  181. PersistentVolumeClaim: pvc,
  182. Data: result.Values,
  183. }
  184. }
  185. type PVActiveMinutesResult struct {
  186. UID string
  187. Cluster string
  188. PersistentVolume string
  189. Data []*util.Vector
  190. }
  191. func DecodePVActiveMinutesResult(result *QueryResult) *PVActiveMinutesResult {
  192. uid, _ := result.GetString(UIDLabel)
  193. cluster, _ := result.GetCluster()
  194. pv, _ := result.GetString(PVLabel)
  195. return &PVActiveMinutesResult{
  196. UID: uid,
  197. Cluster: cluster,
  198. PersistentVolume: pv,
  199. Data: result.Values,
  200. }
  201. }
  202. type PVUsedMaxResult struct {
  203. Cluster string
  204. Namespace string
  205. PersistentVolumeClaim string
  206. Data []*util.Vector
  207. }
  208. func DecodePVUsedMaxResult(result *QueryResult) *PVUsedMaxResult {
  209. cluster, _ := result.GetCluster()
  210. namespace, _ := result.GetNamespace()
  211. pvc, _ := result.GetString(PVCLabel)
  212. return &PVUsedMaxResult{
  213. Cluster: cluster,
  214. Namespace: namespace,
  215. PersistentVolumeClaim: pvc,
  216. Data: result.Values,
  217. }
  218. }
  219. type LocalStorageActiveMinutesResult struct {
  220. Cluster string
  221. Node string
  222. ProviderID string
  223. Data []*util.Vector
  224. }
  225. func DecodeLocalStorageActiveMinutesResult(result *QueryResult) *LocalStorageActiveMinutesResult {
  226. cluster, _ := result.GetCluster()
  227. node, _ := result.GetNode()
  228. if node == "" {
  229. node, _ = result.GetInstance()
  230. }
  231. providerId, _ := result.GetProviderID()
  232. return &LocalStorageActiveMinutesResult{
  233. Cluster: cluster,
  234. Node: node,
  235. ProviderID: providerId,
  236. Data: result.Values,
  237. }
  238. }
  239. type LocalStorageCostResult struct {
  240. UID string
  241. Cluster string
  242. Instance string
  243. Device string
  244. Data []*util.Vector
  245. }
  246. func DecodeLocalStorageCostResult(result *QueryResult) *LocalStorageCostResult {
  247. uid, _ := result.GetString(UIDLabel)
  248. cluster, _ := result.GetCluster()
  249. instance, _ := result.GetInstance()
  250. device, _ := result.GetDevice()
  251. return &LocalStorageCostResult{
  252. UID: uid,
  253. Cluster: cluster,
  254. Instance: instance,
  255. Device: device,
  256. Data: result.Values,
  257. }
  258. }
  259. type LocalStorageUsedCostResult struct {
  260. UID string
  261. Cluster string
  262. Instance string
  263. Device string
  264. Data []*util.Vector
  265. }
  266. func DecodeLocalStorageUsedCostResult(result *QueryResult) *LocalStorageUsedCostResult {
  267. uid, _ := result.GetString(UIDLabel)
  268. cluster, _ := result.GetCluster()
  269. instance, _ := result.GetInstance()
  270. device, _ := result.GetDevice()
  271. return &LocalStorageUsedCostResult{
  272. UID: uid,
  273. Cluster: cluster,
  274. Instance: instance,
  275. Device: device,
  276. Data: result.Values,
  277. }
  278. }
  279. type LocalStorageUsedAvgResult struct {
  280. UID string
  281. Cluster string
  282. Instance string
  283. Device string
  284. Data []*util.Vector
  285. }
  286. func DecodeLocalStorageUsedAvgResult(result *QueryResult) *LocalStorageUsedAvgResult {
  287. uid, _ := result.GetString(UIDLabel)
  288. cluster, _ := result.GetCluster()
  289. instance, _ := result.GetInstance()
  290. device, _ := result.GetDevice()
  291. return &LocalStorageUsedAvgResult{
  292. UID: uid,
  293. Cluster: cluster,
  294. Instance: instance,
  295. Device: device,
  296. Data: result.Values,
  297. }
  298. }
  299. type LocalStorageUsedMaxResult struct {
  300. UID string
  301. Cluster string
  302. Instance string
  303. Device string
  304. Data []*util.Vector
  305. }
  306. func DecodeLocalStorageUsedMaxResult(result *QueryResult) *LocalStorageUsedMaxResult {
  307. uid, _ := result.GetString(UIDLabel)
  308. cluster, _ := result.GetCluster()
  309. instance, _ := result.GetInstance()
  310. device, _ := result.GetDevice()
  311. return &LocalStorageUsedMaxResult{
  312. UID: uid,
  313. Cluster: cluster,
  314. Instance: instance,
  315. Device: device,
  316. Data: result.Values,
  317. }
  318. }
  319. type LocalStorageBytesResult struct {
  320. UID string
  321. Cluster string
  322. Instance string
  323. Device string
  324. Data []*util.Vector
  325. }
  326. func DecodeLocalStorageBytesResult(result *QueryResult) *LocalStorageBytesResult {
  327. uid, _ := result.GetString(UIDLabel)
  328. cluster, _ := result.GetCluster()
  329. instance, _ := result.GetInstance()
  330. device, _ := result.GetDevice()
  331. return &LocalStorageBytesResult{
  332. UID: uid,
  333. Cluster: cluster,
  334. Instance: instance,
  335. Device: device,
  336. Data: result.Values,
  337. }
  338. }
  339. type NodeInfoResult struct {
  340. UID string
  341. Cluster string
  342. Node string
  343. ProviderID string
  344. InstanceType string
  345. }
  346. func DecodeNodeInfoResult(result *QueryResult) *NodeInfoResult {
  347. uid, _ := result.GetString(UIDLabel)
  348. cluster, _ := result.GetCluster()
  349. node, _ := result.GetNode()
  350. providerId, _ := result.GetProviderID()
  351. instanceType, _ := result.GetInstanceType()
  352. return &NodeInfoResult{
  353. UID: uid,
  354. Cluster: cluster,
  355. Node: node,
  356. ProviderID: providerId,
  357. InstanceType: instanceType,
  358. }
  359. }
  360. type NodeActiveMinutesResult struct {
  361. UID string
  362. Cluster string
  363. Node string
  364. ProviderID string
  365. Data []*util.Vector
  366. }
  367. func DecodeNodeActiveMinutesResult(result *QueryResult) *NodeActiveMinutesResult {
  368. uid, _ := result.GetString(UIDLabel)
  369. cluster, _ := result.GetCluster()
  370. node, _ := result.GetNode()
  371. providerId, _ := result.GetProviderID()
  372. return &NodeActiveMinutesResult{
  373. UID: uid,
  374. Cluster: cluster,
  375. Node: node,
  376. ProviderID: providerId,
  377. Data: result.Values,
  378. }
  379. }
  380. type NodeCPUCoresCapacityResult struct {
  381. UID string
  382. Cluster string
  383. Node string
  384. CPUCores float64
  385. }
  386. func DecodeNodeCPUCoresCapacityResult(result *QueryResult) *NodeCPUCoresCapacityResult {
  387. uid, _ := result.GetString(UIDLabel)
  388. cluster, _ := result.GetCluster()
  389. node, _ := result.GetNode()
  390. var value float64
  391. if len(result.Values) > 0 {
  392. value = result.Values[0].Value
  393. } else {
  394. log.Warnf("Error decoding node CPU cores capacity result for node '%s': empty value returned", uid)
  395. }
  396. return &NodeCPUCoresCapacityResult{
  397. UID: uid,
  398. Cluster: cluster,
  399. Node: node,
  400. CPUCores: value,
  401. }
  402. }
  403. type NodeCPUCoresAllocatableResult = NodeCPUCoresCapacityResult
  404. func DecodeNodeCPUCoresAllocatableResult(result *QueryResult) *NodeCPUCoresAllocatableResult {
  405. return DecodeNodeCPUCoresCapacityResult(result)
  406. }
  407. type NodeRAMBytesCapacityResult struct {
  408. UID string
  409. Cluster string
  410. Node string
  411. RAMBytes float64
  412. }
  413. func DecodeNodeRAMBytesCapacityResult(result *QueryResult) *NodeRAMBytesCapacityResult {
  414. uid, _ := result.GetString(UIDLabel)
  415. cluster, _ := result.GetCluster()
  416. node, _ := result.GetNode()
  417. var value float64
  418. if len(result.Values) > 0 {
  419. value = result.Values[0].Value
  420. } else {
  421. log.Warnf("Error decoding node RAM bytes capacity result for node '%s': empty value returned", uid)
  422. }
  423. return &NodeRAMBytesCapacityResult{
  424. UID: uid,
  425. Cluster: cluster,
  426. Node: node,
  427. RAMBytes: value,
  428. }
  429. }
  430. type NodeRAMBytesAllocatableResult = NodeRAMBytesCapacityResult
  431. func DecodeNodeRAMBytesAllocatableResult(result *QueryResult) *NodeRAMBytesAllocatableResult {
  432. return DecodeNodeRAMBytesCapacityResult(result)
  433. }
  434. type NodeGPUCountResult struct {
  435. UID string
  436. Cluster string
  437. Node string
  438. ProviderID string
  439. GPUCount float64
  440. }
  441. func DecodeNodeGPUCountResult(result *QueryResult) *NodeGPUCountResult {
  442. uid, _ := result.GetString(UIDLabel)
  443. cluster, _ := result.GetCluster()
  444. node, _ := result.GetNode()
  445. providerId, _ := result.GetProviderID()
  446. var value float64
  447. if len(result.Values) > 0 {
  448. value = result.Values[0].Value
  449. } else {
  450. log.Warnf("Error decoding node GPU count capacity result for node '%s': empty value returned", uid)
  451. }
  452. return &NodeGPUCountResult{
  453. UID: uid,
  454. Cluster: cluster,
  455. Node: node,
  456. ProviderID: providerId,
  457. GPUCount: value,
  458. }
  459. }
  460. type NodeCPUModeTotalResult struct {
  461. UID string
  462. Cluster string
  463. Node string
  464. Mode string
  465. Data []*util.Vector
  466. }
  467. func DecodeNodeCPUModeTotalResult(result *QueryResult) *NodeCPUModeTotalResult {
  468. uid, _ := result.GetString(UIDLabel)
  469. cluster, _ := result.GetCluster()
  470. node, _ := result.GetString(KubernetesNodeLabel)
  471. mode, _ := result.GetString(ModeLabel)
  472. return &NodeCPUModeTotalResult{
  473. UID: uid,
  474. Cluster: cluster,
  475. Node: node,
  476. Mode: mode,
  477. Data: result.Values,
  478. }
  479. }
  480. type NodeIsSpotResult struct {
  481. UID string
  482. Cluster string
  483. Node string
  484. ProviderID string
  485. Data []*util.Vector
  486. }
  487. func DecodeNodeIsSpotResult(result *QueryResult) *NodeIsSpotResult {
  488. uid, _ := result.GetString(UIDLabel)
  489. cluster, _ := result.GetCluster()
  490. node, _ := result.GetNode()
  491. providerId, _ := result.GetProviderID()
  492. return &NodeIsSpotResult{
  493. UID: uid,
  494. Cluster: cluster,
  495. Node: node,
  496. ProviderID: providerId,
  497. Data: result.Values,
  498. }
  499. }
  500. type NodeRAMSystemPercentResult struct {
  501. UID string
  502. Cluster string
  503. Instance string
  504. Data []*util.Vector
  505. }
  506. func DecodeNodeRAMSystemPercentResult(result *QueryResult) *NodeRAMSystemPercentResult {
  507. uid, _ := result.GetString(UIDLabel)
  508. cluster, _ := result.GetCluster()
  509. instance, _ := result.GetInstance()
  510. return &NodeRAMSystemPercentResult{
  511. UID: uid,
  512. Cluster: cluster,
  513. Instance: instance,
  514. Data: result.Values,
  515. }
  516. }
  517. type NodeRAMUserPercentResult = NodeRAMSystemPercentResult
  518. func DecodeNodeRAMUserPercentResult(result *QueryResult) *NodeRAMUserPercentResult {
  519. return DecodeNodeRAMSystemPercentResult(result)
  520. }
  521. type LBActiveMinutesResult struct {
  522. UID string
  523. Cluster string
  524. Namespace string
  525. Service string
  526. IngressIP string
  527. Data []*util.Vector
  528. }
  529. func DecodeLBActiveMinutesResult(result *QueryResult) *LBActiveMinutesResult {
  530. uid, _ := result.GetString(UIDLabel)
  531. cluster, _ := result.GetCluster()
  532. namespace, _ := result.GetNamespace()
  533. service, _ := result.GetString(ServiceNameLabel)
  534. ingressIp, _ := result.GetString(IngressIPLabel)
  535. return &LBActiveMinutesResult{
  536. UID: uid,
  537. Cluster: cluster,
  538. Namespace: namespace,
  539. Service: service,
  540. IngressIP: ingressIp,
  541. Data: result.Values,
  542. }
  543. }
  544. type LBPricePerHrResult = LBActiveMinutesResult
  545. func DecodeLBPricePerHrResult(result *QueryResult) *LBPricePerHrResult {
  546. return DecodeLBActiveMinutesResult(result)
  547. }
  548. type ClusterInfoResult struct {
  549. UID string
  550. Cluster string
  551. Provider string
  552. AccountID string
  553. Provisioner string
  554. Region string
  555. }
  556. func DecodeClusterInfoResult(result *QueryResult) *ClusterInfoResult {
  557. uid, _ := result.GetString(UIDLabel)
  558. cluster, _ := result.GetString(ClusterNameLabel)
  559. provider, _ := result.GetString(ProviderLabel)
  560. accountID, _ := result.GetString(AccountIDLabel)
  561. provisioner, _ := result.GetString(ProvisionerNameLabel)
  562. region, _ := result.GetString(RegionLabel)
  563. return &ClusterInfoResult{
  564. UID: uid,
  565. Cluster: cluster,
  566. Provider: provider,
  567. AccountID: accountID,
  568. Provisioner: provisioner,
  569. Region: region,
  570. }
  571. }
  572. type ClusterManagementDurationResult struct {
  573. UID string
  574. Cluster string
  575. Provisioner string
  576. Data []*util.Vector
  577. }
  578. func DecodeClusterManagementDurationResult(result *QueryResult) *ClusterManagementDurationResult {
  579. uid, _ := result.GetString(UIDLabel)
  580. cluster, _ := result.GetCluster()
  581. provisioner, _ := result.GetString(ProvisionerNameLabel)
  582. return &ClusterManagementDurationResult{
  583. UID: uid,
  584. Cluster: cluster,
  585. Provisioner: provisioner,
  586. Data: result.Values,
  587. }
  588. }
  589. type ClusterManagementPricePerHrResult = ClusterManagementDurationResult
  590. func DecodeClusterManagementPricePerHrResult(result *QueryResult) *ClusterManagementPricePerHrResult {
  591. return DecodeClusterManagementDurationResult(result)
  592. }
  593. type PodInfoResult struct {
  594. UID string
  595. Cluster string
  596. Pod string
  597. NamespaceUID string
  598. NodeUID string
  599. }
  600. func DecodePodInfoResult(result *QueryResult) *PodInfoResult {
  601. uid, _ := result.GetString(UIDLabel)
  602. cluster, _ := result.GetCluster()
  603. pod, _ := result.GetPod()
  604. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  605. nodeUID, _ := result.GetString(NodeUIDLabel)
  606. return &PodInfoResult{
  607. UID: uid,
  608. Cluster: cluster,
  609. Pod: pod,
  610. NamespaceUID: namespaceUID,
  611. NodeUID: nodeUID,
  612. }
  613. }
  614. type PodPVCVolumeResult struct {
  615. UID string
  616. Cluster string
  617. PVCUID string
  618. PodVolumeName string
  619. }
  620. func DecodePodPVCVolumeResult(result *QueryResult) *PodPVCVolumeResult {
  621. uid, _ := result.GetString(UIDLabel)
  622. cluster, _ := result.GetCluster()
  623. pvcUID, _ := result.GetString(PVCUIDLabel)
  624. podVolumeName, _ := result.GetString(PodVolumeNameLabel)
  625. return &PodPVCVolumeResult{
  626. UID: uid,
  627. Cluster: cluster,
  628. PVCUID: pvcUID,
  629. PodVolumeName: podVolumeName,
  630. }
  631. }
  632. type OwnerResult struct {
  633. UID string
  634. Cluster string
  635. OwnerUID string
  636. OwnerKind string
  637. Controller bool
  638. }
  639. func DecodeOwnerResult(result *QueryResult) *OwnerResult {
  640. uid, _ := result.GetString(UIDLabel)
  641. cluster, _ := result.GetCluster()
  642. ownerUID, _ := result.GetString(OwnerUIDLabel)
  643. ownerKind, _ := result.GetString(OwnerKindLabel)
  644. controller, _ := result.GetBool(ControllerLabel)
  645. return &OwnerResult{
  646. UID: uid,
  647. Cluster: cluster,
  648. OwnerUID: ownerUID,
  649. OwnerKind: ownerKind,
  650. Controller: controller,
  651. }
  652. }
  653. type PodsResult struct {
  654. UID string
  655. Cluster string
  656. Namespace string
  657. Pod string
  658. Data []*util.Vector
  659. }
  660. func DecodePodsResult(result *QueryResult) *PodsResult {
  661. uid, _ := result.GetString(UIDLabel)
  662. cluster, _ := result.GetCluster()
  663. namespace, _ := result.GetNamespace()
  664. pod, _ := result.GetPod()
  665. return &PodsResult{
  666. UID: uid,
  667. Cluster: cluster,
  668. Namespace: namespace,
  669. Pod: pod,
  670. Data: result.Values,
  671. }
  672. }
  673. type ContainerMetricResult struct {
  674. UID string
  675. Cluster string
  676. Node string
  677. Instance string
  678. Namespace string
  679. Pod string
  680. Container string
  681. Data []*util.Vector
  682. }
  683. func DecodeContainerMetricResult(result *QueryResult) *ContainerMetricResult {
  684. uid, _ := result.GetString(UIDLabel)
  685. cluster, _ := result.GetCluster()
  686. node, _ := result.GetNode()
  687. instance, _ := result.GetInstance()
  688. // NOTE: this addresses cases where the node isn't set, but the instance is,
  689. // NOTE: we just inherit the instance as the node
  690. if node == "" {
  691. node = instance
  692. }
  693. namespace, _ := result.GetNamespace()
  694. pod, _ := result.GetPod()
  695. container, _ := result.GetContainer()
  696. return &ContainerMetricResult{
  697. UID: uid,
  698. Cluster: cluster,
  699. Node: node,
  700. Instance: instance,
  701. Namespace: namespace,
  702. Pod: pod,
  703. Container: container,
  704. Data: result.Values,
  705. }
  706. }
  707. type RAMBytesAllocatedResult = ContainerMetricResult
  708. func DecodeRAMBytesAllocatedResult(result *QueryResult) *RAMBytesAllocatedResult {
  709. return DecodeContainerMetricResult(result)
  710. }
  711. type RAMRequestsResult = ContainerMetricResult
  712. func DecodeRAMRequestsResult(result *QueryResult) *RAMRequestsResult {
  713. return DecodeContainerMetricResult(result)
  714. }
  715. type RAMLimitsResult = ContainerMetricResult
  716. func DecodeRAMLimitsResult(result *QueryResult) *RAMLimitsResult {
  717. return DecodeContainerMetricResult(result)
  718. }
  719. type RAMUsageAvgResult = ContainerMetricResult
  720. func DecodeRAMUsageAvgResult(result *QueryResult) *RAMUsageAvgResult {
  721. return DecodeContainerMetricResult(result)
  722. }
  723. type RAMUsageMaxResult = ContainerMetricResult
  724. func DecodeRAMUsageMaxResult(result *QueryResult) *RAMUsageMaxResult {
  725. return DecodeContainerMetricResult(result)
  726. }
  727. type NodeRAMPricePerGiBHrResult struct {
  728. UID string
  729. Cluster string
  730. Node string
  731. InstanceType string
  732. ProviderID string
  733. Data []*util.Vector
  734. }
  735. func DecodeNodeRAMPricePerGiBHrResult(result *QueryResult) *NodeRAMPricePerGiBHrResult {
  736. uid, _ := result.GetString(UIDLabel)
  737. cluster, _ := result.GetCluster()
  738. node, _ := result.GetNode()
  739. instanceType, _ := result.GetInstanceType()
  740. providerId, _ := result.GetProviderID()
  741. return &NodeRAMPricePerGiBHrResult{
  742. UID: uid,
  743. Cluster: cluster,
  744. Node: node,
  745. InstanceType: instanceType,
  746. ProviderID: providerId,
  747. Data: result.Values,
  748. }
  749. }
  750. type CPUCoresAllocatedResult = ContainerMetricResult
  751. func DecodeCPUCoresAllocatedResult(result *QueryResult) *CPUCoresAllocatedResult {
  752. return DecodeContainerMetricResult(result)
  753. }
  754. type CPURequestsResult = ContainerMetricResult
  755. func DecodeCPURequestsResult(result *QueryResult) *CPURequestsResult {
  756. return DecodeContainerMetricResult(result)
  757. }
  758. type CPULimitsResult = ContainerMetricResult
  759. func DecodeCPULimitsResult(result *QueryResult) *CPULimitsResult {
  760. return DecodeContainerMetricResult(result)
  761. }
  762. type CPUUsageAvgResult = ContainerMetricResult
  763. func DecodeCPUUsageAvgResult(result *QueryResult) *CPUUsageAvgResult {
  764. return DecodeContainerMetricResult(result)
  765. }
  766. type CPUUsageMaxResult = ContainerMetricResult
  767. func DecodeCPUUsageMaxResult(result *QueryResult) *CPUUsageMaxResult {
  768. return DecodeContainerMetricResult(result)
  769. }
  770. type NodeCPUPricePerHrResult struct {
  771. UID string
  772. Cluster string
  773. Node string
  774. InstanceType string
  775. ProviderID string
  776. Data []*util.Vector
  777. }
  778. func DecodeNodeCPUPricePerHrResult(result *QueryResult) *NodeCPUPricePerHrResult {
  779. uid, _ := result.GetString(UIDLabel)
  780. cluster, _ := result.GetCluster()
  781. node, _ := result.GetNode()
  782. instanceType, _ := result.GetInstanceType()
  783. providerId, _ := result.GetProviderID()
  784. return &NodeCPUPricePerHrResult{
  785. UID: uid,
  786. Cluster: cluster,
  787. Node: node,
  788. InstanceType: instanceType,
  789. ProviderID: providerId,
  790. Data: result.Values,
  791. }
  792. }
  793. // type alias requested result to allocated result, as you can only request a full GPU
  794. type GPUsRequestedResult = GPUsAllocatedResult
  795. func DecodeGPUsRequestedResult(result *QueryResult) *GPUsRequestedResult {
  796. return DecodeGPUsAllocatedResult(result)
  797. }
  798. type GPUsAllocatedResult struct {
  799. UID string
  800. Cluster string
  801. Namespace string
  802. Pod string
  803. Container string
  804. Data []*util.Vector
  805. }
  806. func DecodeGPUsAllocatedResult(result *QueryResult) *GPUsAllocatedResult {
  807. uid, _ := result.GetString(UIDLabel)
  808. cluster, _ := result.GetCluster()
  809. namespace, _ := result.GetNamespace()
  810. pod, _ := result.GetPod()
  811. container, _ := result.GetContainer()
  812. return &GPUsAllocatedResult{
  813. UID: uid,
  814. Cluster: cluster,
  815. Namespace: namespace,
  816. Pod: pod,
  817. Container: container,
  818. Data: result.Values,
  819. }
  820. }
  821. type GPUsUsageAvgResult struct {
  822. UID string
  823. Cluster string
  824. Namespace string
  825. Pod string
  826. Container string
  827. Data []*util.Vector
  828. }
  829. func DecodeGPUsUsageAvgResult(result *QueryResult) *GPUsUsageAvgResult {
  830. uid, _ := result.GetString(PodUIDLabel)
  831. cluster, _ := result.GetCluster()
  832. namespace, _ := result.GetNamespace()
  833. pod, _ := result.GetPod()
  834. container, _ := result.GetContainer()
  835. return &GPUsUsageAvgResult{
  836. UID: uid,
  837. Cluster: cluster,
  838. Namespace: namespace,
  839. Pod: pod,
  840. Container: container,
  841. Data: result.Values,
  842. }
  843. }
  844. type GPUsUsageMaxResult struct {
  845. UID string
  846. Cluster string
  847. Namespace string
  848. Pod string
  849. Container string
  850. Data []*util.Vector
  851. }
  852. func DecodeGPUsUsageMaxResult(result *QueryResult) *GPUsUsageMaxResult {
  853. uid, _ := result.GetString(PodUIDLabel)
  854. cluster, _ := result.GetCluster()
  855. namespace, _ := result.GetNamespace()
  856. pod, _ := result.GetPod()
  857. container, _ := result.GetContainer()
  858. return &GPUsUsageMaxResult{
  859. UID: uid,
  860. Cluster: cluster,
  861. Namespace: namespace,
  862. Pod: pod,
  863. Container: container,
  864. Data: result.Values,
  865. }
  866. }
  867. type NodeGPUPricePerHrResult struct {
  868. UID string
  869. Cluster string
  870. Node string
  871. InstanceType string
  872. ProviderID string
  873. Data []*util.Vector
  874. }
  875. func DecodeNodeGPUPricePerHrResult(result *QueryResult) *NodeGPUPricePerHrResult {
  876. uid, _ := result.GetString(UIDLabel)
  877. cluster, _ := result.GetCluster()
  878. node, _ := result.GetNode()
  879. instanceType, _ := result.GetInstanceType()
  880. providerId, _ := result.GetProviderID()
  881. return &NodeGPUPricePerHrResult{
  882. UID: uid,
  883. Cluster: cluster,
  884. Node: node,
  885. InstanceType: instanceType,
  886. ProviderID: providerId,
  887. Data: result.Values,
  888. }
  889. }
  890. type GPUInfoResult struct {
  891. UID string
  892. Cluster string
  893. Namespace string
  894. Pod string
  895. Container string
  896. Device string
  897. ModelName string
  898. UUID string
  899. Data []*util.Vector
  900. }
  901. func DecodeGPUInfoResult(result *QueryResult) *GPUInfoResult {
  902. uid, _ := result.GetString(PodUIDLabel)
  903. cluster, _ := result.GetCluster()
  904. namespace, _ := result.GetNamespace()
  905. pod, _ := result.GetPod()
  906. container, _ := result.GetContainer()
  907. device, _ := result.GetString(DeviceLabel)
  908. modelName, _ := result.GetString(ModelNameLabel)
  909. uuid, _ := result.GetString(UUIDLabel)
  910. return &GPUInfoResult{
  911. UID: uid,
  912. Cluster: cluster,
  913. Namespace: namespace,
  914. Pod: pod,
  915. Container: container,
  916. Device: device,
  917. ModelName: modelName,
  918. UUID: uuid,
  919. Data: result.Values,
  920. }
  921. }
  922. type IsGPUSharedResult struct {
  923. UID string
  924. Cluster string
  925. Namespace string
  926. Pod string
  927. Container string
  928. Resource string
  929. Data []*util.Vector
  930. }
  931. func DecodeIsGPUSharedResult(result *QueryResult) *IsGPUSharedResult {
  932. uid, _ := result.GetString(UIDLabel)
  933. cluster, _ := result.GetCluster()
  934. namespace, _ := result.GetNamespace()
  935. pod, _ := result.GetPod()
  936. container, _ := result.GetContainer()
  937. resource, _ := result.GetString(ResourceLabel)
  938. return &IsGPUSharedResult{
  939. UID: uid,
  940. Cluster: cluster,
  941. Namespace: namespace,
  942. Pod: pod,
  943. Container: container,
  944. Resource: resource,
  945. Data: result.Values,
  946. }
  947. }
  948. type PodPVCAllocationResult struct {
  949. UID string
  950. Cluster string
  951. Namespace string
  952. Pod string
  953. PersistentVolume string
  954. PersistentVolumeClaim string
  955. Data []*util.Vector
  956. }
  957. func DecodePodPVCAllocationResult(result *QueryResult) *PodPVCAllocationResult {
  958. uid, _ := result.GetString(UIDLabel)
  959. cluster, _ := result.GetCluster()
  960. namespace, _ := result.GetNamespace()
  961. pod, _ := result.GetPod()
  962. pv, _ := result.GetString(PVLabel)
  963. pvc, _ := result.GetString(PVCLabel)
  964. return &PodPVCAllocationResult{
  965. UID: uid,
  966. Cluster: cluster,
  967. Namespace: namespace,
  968. Pod: pod,
  969. PersistentVolume: pv,
  970. PersistentVolumeClaim: pvc,
  971. Data: result.Values,
  972. }
  973. }
  974. type PVCBytesRequestedResult struct {
  975. UID string
  976. Cluster string
  977. Namespace string
  978. PersistentVolumeClaim string
  979. Data []*util.Vector
  980. }
  981. func DecodePVCBytesRequestedResult(result *QueryResult) *PVCBytesRequestedResult {
  982. uid, _ := result.GetString(UIDLabel)
  983. cluster, _ := result.GetCluster()
  984. namespace, _ := result.GetNamespace()
  985. pvc, _ := result.GetString(PVCLabel)
  986. return &PVCBytesRequestedResult{
  987. UID: uid,
  988. Cluster: cluster,
  989. Namespace: namespace,
  990. PersistentVolumeClaim: pvc,
  991. Data: result.Values,
  992. }
  993. }
  994. type PVCInfoResult struct {
  995. UID string
  996. Cluster string
  997. NamespaceUID string
  998. Namespace string
  999. VolumeName string
  1000. PVUID string
  1001. PersistentVolumeClaim string
  1002. StorageClass string
  1003. Data []*util.Vector
  1004. }
  1005. func DecodePVCInfoResult(result *QueryResult) *PVCInfoResult {
  1006. uid, _ := result.GetString(UIDLabel)
  1007. cluster, _ := result.GetCluster()
  1008. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1009. namespace, _ := result.GetNamespace()
  1010. pvUID, _ := result.GetString(PVUIDLabel)
  1011. volumeName, _ := result.GetString(VolumeNameLabel)
  1012. pvc, _ := result.GetString(PVCLabel)
  1013. storageClass, _ := result.GetString(StorageClassLabel)
  1014. return &PVCInfoResult{
  1015. UID: uid,
  1016. Cluster: cluster,
  1017. NamespaceUID: namespaceUID,
  1018. Namespace: namespace,
  1019. PVUID: pvUID,
  1020. VolumeName: volumeName,
  1021. PersistentVolumeClaim: pvc,
  1022. StorageClass: storageClass,
  1023. Data: result.Values,
  1024. }
  1025. }
  1026. type PVBytesResult struct {
  1027. UID string
  1028. Cluster string
  1029. PersistentVolume string
  1030. Value float64
  1031. }
  1032. func DecodePVBytesResult(result *QueryResult) *PVBytesResult {
  1033. uid, _ := result.GetString(UIDLabel)
  1034. cluster, _ := result.GetCluster()
  1035. pv, _ := result.GetString(PVLabel)
  1036. var value float64
  1037. if len(result.Values) > 0 {
  1038. value = result.Values[0].Value
  1039. } else {
  1040. log.Warnf("Error decoding PV bytes result for pv '%s': empty value returned", uid)
  1041. }
  1042. return &PVBytesResult{
  1043. UID: uid,
  1044. Cluster: cluster,
  1045. PersistentVolume: pv,
  1046. Value: value,
  1047. }
  1048. }
  1049. type PVPricePerGiBHourResult struct {
  1050. UID string
  1051. Cluster string
  1052. VolumeName string
  1053. PersistentVolume string
  1054. ProviderID string
  1055. Data []*util.Vector
  1056. }
  1057. func DecodePVPricePerGiBHourResult(result *QueryResult) *PVPricePerGiBHourResult {
  1058. uid, _ := result.GetString(UIDLabel)
  1059. cluster, _ := result.GetCluster()
  1060. volumeName, _ := result.GetString(VolumeNameLabel)
  1061. pv, _ := result.GetString(PVLabel)
  1062. providerId, _ := result.GetProviderID()
  1063. return &PVPricePerGiBHourResult{
  1064. UID: uid,
  1065. Cluster: cluster,
  1066. VolumeName: volumeName,
  1067. PersistentVolume: pv,
  1068. ProviderID: providerId,
  1069. Data: result.Values,
  1070. }
  1071. }
  1072. type PVInfoResult struct {
  1073. UID string
  1074. Cluster string
  1075. PersistentVolume string
  1076. StorageClass string
  1077. ProviderID string
  1078. CSIVolumeHandle string
  1079. Data []*util.Vector
  1080. }
  1081. func DecodePVInfoResult(result *QueryResult) *PVInfoResult {
  1082. uid, _ := result.GetString(UIDLabel)
  1083. cluster, _ := result.GetCluster()
  1084. storageClass, _ := result.GetString(StorageClassLabel)
  1085. providerId, _ := result.GetProviderID()
  1086. pv, _ := result.GetString(PVLabel)
  1087. csiVolumeHandle, _ := result.GetString(CSIVolumeHandleLabel)
  1088. return &PVInfoResult{
  1089. UID: uid,
  1090. Cluster: cluster,
  1091. PersistentVolume: pv,
  1092. StorageClass: storageClass,
  1093. ProviderID: providerId,
  1094. CSIVolumeHandle: csiVolumeHandle,
  1095. Data: result.Values,
  1096. }
  1097. }
  1098. type PodNetworkBytesResult struct {
  1099. UID string
  1100. Cluster string
  1101. Service string
  1102. Internet bool
  1103. SameRegion bool
  1104. SameZone bool
  1105. NatGateway bool
  1106. Value float64
  1107. }
  1108. func DecodePodNetworkBytesResult(result *QueryResult) *PodNetworkBytesResult {
  1109. uid, _ := result.GetString(UIDLabel)
  1110. cluster, _ := result.GetCluster()
  1111. service, _ := result.GetString(ServiceLabel)
  1112. internet, _ := result.GetBool(InternetLabel)
  1113. sameRegion, _ := result.GetBool(SameRegionLabel)
  1114. sameZone, _ := result.GetBool(SameZoneLabel)
  1115. natGateway, _ := result.GetBool(NatGatewayLabel)
  1116. var value float64
  1117. if len(result.Values) > 0 {
  1118. value = result.Values[0].Value
  1119. } else {
  1120. log.Warnf("Error decoding pod network bytes result for pod '%s': empty value returned", uid)
  1121. }
  1122. return &PodNetworkBytesResult{
  1123. UID: uid,
  1124. Cluster: cluster,
  1125. Service: service,
  1126. Internet: internet,
  1127. SameRegion: sameRegion,
  1128. SameZone: sameZone,
  1129. NatGateway: natGateway,
  1130. Value: value,
  1131. }
  1132. }
  1133. // Base type for network usage results
  1134. type NetworkGiBResult struct {
  1135. UID string
  1136. Cluster string
  1137. Namespace string
  1138. Pod string
  1139. Service string
  1140. Data []*util.Vector
  1141. }
  1142. func DecodeNetworkGiBResult(result *QueryResult) *NetworkGiBResult {
  1143. uid, _ := result.GetString(UIDLabel)
  1144. cluster, _ := result.GetCluster()
  1145. namespace, _ := result.GetNamespace()
  1146. pod, _ := result.GetPod()
  1147. service, _ := result.GetString(ServiceLabel)
  1148. return &NetworkGiBResult{
  1149. UID: uid,
  1150. Cluster: cluster,
  1151. Namespace: namespace,
  1152. Pod: pod,
  1153. Service: service,
  1154. Data: result.Values,
  1155. }
  1156. }
  1157. // Base type for network price results
  1158. type NetworkPricePerGiBResult struct {
  1159. UID string
  1160. Cluster string
  1161. Data []*util.Vector
  1162. }
  1163. func DecodeNetworkPricePerGiBResult(result *QueryResult) *NetworkPricePerGiBResult {
  1164. uid, _ := result.GetString(UIDLabel)
  1165. cluster, _ := result.GetCluster()
  1166. return &NetworkPricePerGiBResult{
  1167. UID: uid,
  1168. Cluster: cluster,
  1169. Data: result.Values,
  1170. }
  1171. }
  1172. // Type alias the specific network subclassification results AND price results
  1173. type NetZoneGiBResult = NetworkGiBResult
  1174. type NetZonePricePerGiBResult = NetworkPricePerGiBResult
  1175. type NetRegionGiBResult = NetworkGiBResult
  1176. type NetRegionPricePerGiBResult = NetworkPricePerGiBResult
  1177. type NetInternetGiBResult = NetworkGiBResult
  1178. type NetInternetPricePerGiBResult = NetworkPricePerGiBResult
  1179. type NetInternetServiceGiBResult = NetworkGiBResult
  1180. type NetNatGatewayPricePerGiBResult = NetworkPricePerGiBResult
  1181. type NetNatGatewayGiBResult = NetworkGiBResult
  1182. type NetZoneIngressGiBResult = NetworkGiBResult
  1183. type NetRegionIngressGiBResult = NetworkGiBResult
  1184. type NetInternetIngressGiBResult = NetworkGiBResult
  1185. type NetInternetServiceIngressGiBResult = NetworkGiBResult
  1186. type NetNatGatewayIngressGiBResult = NetworkGiBResult
  1187. func DecodeNetZoneGiBResult(result *QueryResult) *NetZoneGiBResult {
  1188. return DecodeNetworkGiBResult(result)
  1189. }
  1190. func DecodeNetZonePricePerGiBResult(result *QueryResult) *NetZonePricePerGiBResult {
  1191. return DecodeNetworkPricePerGiBResult(result)
  1192. }
  1193. func DecodeNetRegionGiBResult(result *QueryResult) *NetRegionGiBResult {
  1194. return DecodeNetworkGiBResult(result)
  1195. }
  1196. func DecodeNetRegionPricePerGiBResult(result *QueryResult) *NetRegionPricePerGiBResult {
  1197. return DecodeNetworkPricePerGiBResult(result)
  1198. }
  1199. func DecodeNetInternetGiBResult(result *QueryResult) *NetInternetGiBResult {
  1200. return DecodeNetworkGiBResult(result)
  1201. }
  1202. func DecodeNetInternetPricePerGiBResult(result *QueryResult) *NetInternetPricePerGiBResult {
  1203. return DecodeNetworkPricePerGiBResult(result)
  1204. }
  1205. func DecodeNetInternetServiceGiBResult(result *QueryResult) *NetInternetServiceGiBResult {
  1206. return DecodeNetworkGiBResult(result)
  1207. }
  1208. func DecodeNetNatGatewayPricePerGiBResult(result *QueryResult) *NetNatGatewayPricePerGiBResult {
  1209. return DecodeNetworkPricePerGiBResult(result)
  1210. }
  1211. func DecodeNetNatGatewayGiBResult(result *QueryResult) *NetNatGatewayGiBResult {
  1212. return DecodeNetworkGiBResult(result)
  1213. }
  1214. func DecodeNetZoneIngressGiBResult(result *QueryResult) *NetZoneIngressGiBResult {
  1215. return DecodeNetworkGiBResult(result)
  1216. }
  1217. func DecodeNetRegionIngressGiBResult(result *QueryResult) *NetRegionIngressGiBResult {
  1218. return DecodeNetworkGiBResult(result)
  1219. }
  1220. func DecodeNetInternetIngressGiBResult(result *QueryResult) *NetInternetIngressGiBResult {
  1221. return DecodeNetworkGiBResult(result)
  1222. }
  1223. func DecodeNetInternetServiceIngressGiBResult(result *QueryResult) *NetInternetServiceIngressGiBResult {
  1224. return DecodeNetworkGiBResult(result)
  1225. }
  1226. func DecodeNetNatGatewayIngressGiBResult(result *QueryResult) *NetNatGatewayIngressGiBResult {
  1227. return DecodeNetworkGiBResult(result)
  1228. }
  1229. type NetReceiveBytesResult struct {
  1230. UID string
  1231. Cluster string
  1232. Namespace string
  1233. Pod string
  1234. Container string
  1235. Data []*util.Vector
  1236. }
  1237. func DecodeNetReceiveBytesResult(result *QueryResult) *NetReceiveBytesResult {
  1238. uid, _ := result.GetString(UIDLabel)
  1239. cluster, _ := result.GetCluster()
  1240. namespace, _ := result.GetNamespace()
  1241. pod, _ := result.GetPod()
  1242. container, _ := result.GetContainer()
  1243. return &NetReceiveBytesResult{
  1244. UID: uid,
  1245. Cluster: cluster,
  1246. Namespace: namespace,
  1247. Pod: pod,
  1248. Container: container,
  1249. Data: result.Values,
  1250. }
  1251. }
  1252. type NetTransferBytesResult struct {
  1253. UID string
  1254. Cluster string
  1255. Namespace string
  1256. Pod string
  1257. Container string
  1258. Data []*util.Vector
  1259. }
  1260. func DecodeNetTransferBytesResult(result *QueryResult) *NetTransferBytesResult {
  1261. uid, _ := result.GetString(UIDLabel)
  1262. cluster, _ := result.GetCluster()
  1263. namespace, _ := result.GetNamespace()
  1264. pod, _ := result.GetPod()
  1265. container, _ := result.GetContainer()
  1266. return &NetTransferBytesResult{
  1267. UID: uid,
  1268. Cluster: cluster,
  1269. Namespace: namespace,
  1270. Pod: pod,
  1271. Container: container,
  1272. Data: result.Values,
  1273. }
  1274. }
  1275. type NamespaceAnnotationsResult struct {
  1276. UID string
  1277. Cluster string
  1278. Namespace string
  1279. Annotations map[string]string
  1280. Data []*util.Vector
  1281. }
  1282. func DecodeNamespaceAnnotationsResult(result *QueryResult) *NamespaceAnnotationsResult {
  1283. uid, _ := result.GetString(UIDLabel)
  1284. cluster, _ := result.GetCluster()
  1285. namespace, _ := result.GetNamespace()
  1286. annotations := result.GetAnnotations()
  1287. return &NamespaceAnnotationsResult{
  1288. UID: uid,
  1289. Cluster: cluster,
  1290. Namespace: namespace,
  1291. Annotations: annotations,
  1292. Data: result.Values,
  1293. }
  1294. }
  1295. type PodAnnotationsResult struct {
  1296. UID string
  1297. Cluster string
  1298. Namespace string
  1299. Pod string
  1300. Annotations map[string]string
  1301. Data []*util.Vector
  1302. }
  1303. func DecodePodAnnotationsResult(result *QueryResult) *PodAnnotationsResult {
  1304. uid, _ := result.GetString(UIDLabel)
  1305. cluster, _ := result.GetCluster()
  1306. namespace, _ := result.GetNamespace()
  1307. pod, _ := result.GetPod()
  1308. annotations := result.GetAnnotations()
  1309. return &PodAnnotationsResult{
  1310. UID: uid,
  1311. Cluster: cluster,
  1312. Namespace: namespace,
  1313. Pod: pod,
  1314. Annotations: annotations,
  1315. Data: result.Values,
  1316. }
  1317. }
  1318. type NodeLabelsResult struct {
  1319. UID string
  1320. Cluster string
  1321. Node string
  1322. Labels map[string]string
  1323. }
  1324. func DecodeNodeLabelsResult(result *QueryResult) *NodeLabelsResult {
  1325. uid, _ := result.GetString(UIDLabel)
  1326. cluster, _ := result.GetCluster()
  1327. node, _ := result.GetNode()
  1328. labels := result.GetLabels()
  1329. return &NodeLabelsResult{
  1330. UID: uid,
  1331. Cluster: cluster,
  1332. Node: node,
  1333. Labels: labels,
  1334. }
  1335. }
  1336. type NamespaceInfoResult struct {
  1337. UID string
  1338. Cluster string
  1339. Namespace string
  1340. }
  1341. func DecodeNamespaceInfoResult(result *QueryResult) *NamespaceInfoResult {
  1342. uid, _ := result.GetString(UIDLabel)
  1343. cluster, _ := result.GetCluster()
  1344. namespace, _ := result.GetNamespace()
  1345. return &NamespaceInfoResult{
  1346. UID: uid,
  1347. Cluster: cluster,
  1348. Namespace: namespace,
  1349. }
  1350. }
  1351. type NamespaceLabelsResult struct {
  1352. UID string
  1353. Cluster string
  1354. Namespace string
  1355. Labels map[string]string
  1356. Data []*util.Vector
  1357. }
  1358. func DecodeNamespaceLabelsResult(result *QueryResult) *NamespaceLabelsResult {
  1359. uid, _ := result.GetString(UIDLabel)
  1360. cluster, _ := result.GetCluster()
  1361. namespace, _ := result.GetNamespace()
  1362. labels := result.GetLabels()
  1363. return &NamespaceLabelsResult{
  1364. UID: uid,
  1365. Cluster: cluster,
  1366. Namespace: namespace,
  1367. Labels: labels,
  1368. Data: result.Values,
  1369. }
  1370. }
  1371. type PodLabelsResult struct {
  1372. UID string
  1373. Cluster string
  1374. Namespace string
  1375. Pod string
  1376. Labels map[string]string
  1377. Data []*util.Vector
  1378. }
  1379. func DecodePodLabelsResult(result *QueryResult) *PodLabelsResult {
  1380. uid, _ := result.GetString(UIDLabel)
  1381. cluster, _ := result.GetCluster()
  1382. namespace, _ := result.GetNamespace()
  1383. pod, _ := result.GetPod()
  1384. labels := result.GetLabels()
  1385. return &PodLabelsResult{
  1386. UID: uid,
  1387. Cluster: cluster,
  1388. Namespace: namespace,
  1389. Pod: pod,
  1390. Labels: labels,
  1391. Data: result.Values,
  1392. }
  1393. }
  1394. type ServiceLabelsResult struct {
  1395. UID string
  1396. Cluster string
  1397. Namespace string
  1398. Service string
  1399. Labels map[string]string
  1400. Data []*util.Vector
  1401. }
  1402. func DecodeServiceLabelsResult(result *QueryResult) *ServiceLabelsResult {
  1403. uid, _ := result.GetString(UIDLabel)
  1404. cluster, _ := result.GetCluster()
  1405. namespace, _ := result.GetNamespace()
  1406. service, _ := result.GetString(ServiceLabel)
  1407. labels := result.GetLabels()
  1408. return &ServiceLabelsResult{
  1409. UID: uid,
  1410. Cluster: cluster,
  1411. Namespace: namespace,
  1412. Service: service,
  1413. Labels: labels,
  1414. Data: result.Values,
  1415. }
  1416. }
  1417. type ServiceInfoResult struct {
  1418. UID string
  1419. Cluster string
  1420. NamespaceUID string
  1421. Service string
  1422. ServiceType string
  1423. LBIngressAddress string
  1424. }
  1425. func DecodeServiceInfoResult(result *QueryResult) *ServiceInfoResult {
  1426. uid, _ := result.GetString(UIDLabel)
  1427. cluster, _ := result.GetCluster()
  1428. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1429. service, _ := result.GetString(ServiceLabel)
  1430. serviceType, _ := result.GetString(ServiceTypeLabel)
  1431. lbIngressAddress, _ := result.GetString(LBIngressAddress)
  1432. return &ServiceInfoResult{
  1433. UID: uid,
  1434. Cluster: cluster,
  1435. NamespaceUID: namespaceUID,
  1436. Service: service,
  1437. ServiceType: serviceType,
  1438. LBIngressAddress: lbIngressAddress,
  1439. }
  1440. }
  1441. type DeploymentInfoResult struct {
  1442. UID string
  1443. Cluster string
  1444. NamespaceUID string
  1445. Deployment string
  1446. }
  1447. func DecodeDeploymentInfoResult(result *QueryResult) *DeploymentInfoResult {
  1448. uid, _ := result.GetString(UIDLabel)
  1449. cluster, _ := result.GetCluster()
  1450. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1451. deployment, _ := result.GetString(DeploymentLabel)
  1452. return &DeploymentInfoResult{
  1453. UID: uid,
  1454. Cluster: cluster,
  1455. NamespaceUID: namespaceUID,
  1456. Deployment: deployment,
  1457. }
  1458. }
  1459. type DeploymentLabelsResult struct {
  1460. UID string
  1461. Cluster string
  1462. Namespace string
  1463. Deployment string
  1464. Labels map[string]string
  1465. Data []*util.Vector
  1466. }
  1467. func DecodeDeploymentLabelsResult(result *QueryResult) *DeploymentLabelsResult {
  1468. uid, _ := result.GetString(UIDLabel)
  1469. cluster, _ := result.GetCluster()
  1470. namespace, _ := result.GetNamespace()
  1471. deployment, _ := result.GetString(DeploymentLabel)
  1472. labels := result.GetLabels()
  1473. return &DeploymentLabelsResult{
  1474. UID: uid,
  1475. Cluster: cluster,
  1476. Namespace: namespace,
  1477. Deployment: deployment,
  1478. Labels: labels,
  1479. Data: result.Values,
  1480. }
  1481. }
  1482. type StatefulSetInfoResult struct {
  1483. UID string
  1484. Cluster string
  1485. NamespaceUID string
  1486. StatefulSet string
  1487. }
  1488. func DecodeStatefulSetInfoResult(result *QueryResult) *StatefulSetInfoResult {
  1489. uid, _ := result.GetString(UIDLabel)
  1490. cluster, _ := result.GetCluster()
  1491. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1492. statefulSet, _ := result.GetString(StatefulSetLabel)
  1493. return &StatefulSetInfoResult{
  1494. UID: uid,
  1495. Cluster: cluster,
  1496. NamespaceUID: namespaceUID,
  1497. StatefulSet: statefulSet,
  1498. }
  1499. }
  1500. type DaemonSetInfoResult struct {
  1501. UID string
  1502. Cluster string
  1503. NamespaceUID string
  1504. DaemonSet string
  1505. }
  1506. func DecodeDaemonSetInfoResult(result *QueryResult) *DaemonSetInfoResult {
  1507. uid, _ := result.GetString(UIDLabel)
  1508. cluster, _ := result.GetCluster()
  1509. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1510. daemonSet, _ := result.GetString(DaemonSetLabel)
  1511. return &DaemonSetInfoResult{
  1512. UID: uid,
  1513. Cluster: cluster,
  1514. NamespaceUID: namespaceUID,
  1515. DaemonSet: daemonSet,
  1516. }
  1517. }
  1518. type JobInfoResult struct {
  1519. UID string
  1520. Cluster string
  1521. NamespaceUID string
  1522. Job string
  1523. }
  1524. func DecodeJobInfoResult(result *QueryResult) *JobInfoResult {
  1525. uid, _ := result.GetString(UIDLabel)
  1526. cluster, _ := result.GetCluster()
  1527. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1528. job, _ := result.GetString(JobLabel)
  1529. return &JobInfoResult{
  1530. UID: uid,
  1531. Cluster: cluster,
  1532. NamespaceUID: namespaceUID,
  1533. Job: job,
  1534. }
  1535. }
  1536. type CronJobInfoResult struct {
  1537. UID string
  1538. Cluster string
  1539. NamespaceUID string
  1540. CronJob string
  1541. }
  1542. func DecodeCronJobInfoResult(result *QueryResult) *CronJobInfoResult {
  1543. uid, _ := result.GetString(UIDLabel)
  1544. cluster, _ := result.GetCluster()
  1545. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1546. cronJob, _ := result.GetString(CronJobLabel)
  1547. return &CronJobInfoResult{
  1548. UID: uid,
  1549. Cluster: cluster,
  1550. NamespaceUID: namespaceUID,
  1551. CronJob: cronJob,
  1552. }
  1553. }
  1554. type ReplicaSetInfoResult struct {
  1555. UID string
  1556. Cluster string
  1557. NamespaceUID string
  1558. ReplicaSet string
  1559. }
  1560. func DecodeReplicaSetInfoResult(result *QueryResult) *ReplicaSetInfoResult {
  1561. uid, _ := result.GetString(UIDLabel)
  1562. cluster, _ := result.GetCluster()
  1563. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1564. replicaSet, _ := result.GetString(ReplicaSetLabel)
  1565. return &ReplicaSetInfoResult{
  1566. UID: uid,
  1567. Cluster: cluster,
  1568. NamespaceUID: namespaceUID,
  1569. ReplicaSet: replicaSet,
  1570. }
  1571. }
  1572. type StatefulSetLabelsResult struct {
  1573. UID string
  1574. Cluster string
  1575. Namespace string
  1576. StatefulSet string
  1577. Labels map[string]string
  1578. Data []*util.Vector
  1579. }
  1580. func DecodeStatefulSetLabelsResult(result *QueryResult) *StatefulSetLabelsResult {
  1581. uid, _ := result.GetString(UIDLabel)
  1582. cluster, _ := result.GetCluster()
  1583. namespace, _ := result.GetNamespace()
  1584. statefulSet, _ := result.GetString(StatefulSetLabel)
  1585. labels := result.GetLabels()
  1586. return &StatefulSetLabelsResult{
  1587. UID: uid,
  1588. Cluster: cluster,
  1589. Namespace: namespace,
  1590. StatefulSet: statefulSet,
  1591. Labels: labels,
  1592. Data: result.Values,
  1593. }
  1594. }
  1595. type PodsWithDaemonSetOwnerResult struct {
  1596. UID string
  1597. Cluster string
  1598. Namespace string
  1599. Pod string
  1600. DaemonSet string
  1601. }
  1602. func DecodePodsWithDaemonSetOwnerResult(result *QueryResult) *PodsWithDaemonSetOwnerResult {
  1603. uid, _ := result.GetString(UIDLabel)
  1604. cluster, _ := result.GetCluster()
  1605. namespace, _ := result.GetNamespace()
  1606. pod, _ := result.GetPod()
  1607. daemonSet, _ := result.GetString(OwnerNameLabel)
  1608. return &PodsWithDaemonSetOwnerResult{
  1609. UID: uid,
  1610. Cluster: cluster,
  1611. Namespace: namespace,
  1612. Pod: pod,
  1613. DaemonSet: daemonSet,
  1614. }
  1615. }
  1616. type PodsWithJobOwnerResult struct {
  1617. UID string
  1618. Cluster string
  1619. Namespace string
  1620. Pod string
  1621. Job string
  1622. }
  1623. func DecodePodsWithJobOwnerResult(result *QueryResult) *PodsWithJobOwnerResult {
  1624. uid, _ := result.GetString(UIDLabel)
  1625. cluster, _ := result.GetCluster()
  1626. namespace, _ := result.GetNamespace()
  1627. pod, _ := result.GetPod()
  1628. job, _ := result.GetString(OwnerNameLabel)
  1629. return &PodsWithJobOwnerResult{
  1630. UID: uid,
  1631. Cluster: cluster,
  1632. Namespace: namespace,
  1633. Pod: pod,
  1634. Job: job,
  1635. }
  1636. }
  1637. type PodsWithReplicaSetOwnerResult struct {
  1638. UID string
  1639. Cluster string
  1640. Namespace string
  1641. Pod string
  1642. ReplicaSet string
  1643. Data []*util.Vector
  1644. }
  1645. func DecodePodsWithReplicaSetOwnerResult(result *QueryResult) *PodsWithReplicaSetOwnerResult {
  1646. uid, _ := result.GetString(UIDLabel)
  1647. cluster, _ := result.GetCluster()
  1648. namespace, _ := result.GetNamespace()
  1649. replicaSet, _ := result.GetString(OwnerNameLabel)
  1650. pod, _ := result.GetPod()
  1651. return &PodsWithReplicaSetOwnerResult{
  1652. UID: uid,
  1653. Cluster: cluster,
  1654. Namespace: namespace,
  1655. Pod: pod,
  1656. ReplicaSet: replicaSet,
  1657. Data: result.Values,
  1658. }
  1659. }
  1660. type ReplicaSetsWithoutOwnersResult struct {
  1661. UID string
  1662. Cluster string
  1663. Namespace string
  1664. ReplicaSet string
  1665. Data []*util.Vector
  1666. }
  1667. func DecodeReplicaSetsWithoutOwnersResult(result *QueryResult) *ReplicaSetsWithoutOwnersResult {
  1668. uid, _ := result.GetString(UIDLabel)
  1669. return &ReplicaSetsWithoutOwnersResult{
  1670. UID: uid,
  1671. Data: result.Values,
  1672. }
  1673. }
  1674. type ReplicaSetsWithRolloutResult struct {
  1675. UID string
  1676. Cluster string
  1677. Namespace string
  1678. ReplicaSet string
  1679. OwnerName string
  1680. OwnerKind string
  1681. Data []*util.Vector
  1682. }
  1683. func DecodeReplicaSetsWithRolloutResult(result *QueryResult) *ReplicaSetsWithRolloutResult {
  1684. uid, _ := result.GetString(UIDLabel)
  1685. cluster, _ := result.GetCluster()
  1686. namespace, _ := result.GetNamespace()
  1687. replicaSet, _ := result.GetString(ReplicaSetLabel)
  1688. ownerName, _ := result.GetString(OwnerNameLabel)
  1689. ownerKind, _ := result.GetString(OwnerKindLabel)
  1690. return &ReplicaSetsWithRolloutResult{
  1691. UID: uid,
  1692. Cluster: cluster,
  1693. Namespace: namespace,
  1694. ReplicaSet: replicaSet,
  1695. OwnerName: ownerName,
  1696. OwnerKind: ownerKind,
  1697. Data: result.Values,
  1698. }
  1699. }
  1700. type ResourceQuotaInfoResult struct {
  1701. UID string
  1702. NamespaceUID string
  1703. ResourceQuota string
  1704. }
  1705. func DecodeResourceQuotaInfoResult(result *QueryResult) *ResourceQuotaInfoResult {
  1706. uid, _ := result.GetString(UIDLabel)
  1707. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1708. resourceQuota, _ := result.GetString(ResourceQuotaLabel)
  1709. return &ResourceQuotaInfoResult{
  1710. UID: uid,
  1711. NamespaceUID: namespaceUID,
  1712. ResourceQuota: resourceQuota,
  1713. }
  1714. }
  1715. type ResourceResult struct {
  1716. UID string
  1717. Resource string
  1718. Unit string
  1719. Value float64
  1720. }
  1721. func DecodeResourceResult(result *QueryResult) *ResourceResult {
  1722. uid, _ := result.GetString(UIDLabel)
  1723. resource, _ := result.GetString(ResourceLabel)
  1724. unit, _ := result.GetString(UnitLabel)
  1725. var value float64
  1726. if len(result.Values) > 0 {
  1727. value = result.Values[0].Value
  1728. } else {
  1729. log.Warnf("Error decoding resource for uid '%s': empty value returned", uid)
  1730. }
  1731. return &ResourceResult{
  1732. UID: uid,
  1733. Resource: resource,
  1734. Unit: unit,
  1735. Value: value,
  1736. }
  1737. }
  1738. // DCGM needs specialized results because it uses UUID instead of the uid label that we use.
  1739. type DCGMDeviceInfoResult struct {
  1740. UUID string
  1741. Device string
  1742. ModelName string
  1743. HostName string
  1744. }
  1745. func DecodeDCGMDeviceInfoResult(result *QueryResult) *DCGMDeviceInfoResult {
  1746. uuid, _ := result.GetString(UUIDLabel)
  1747. device, _ := result.GetString(DeviceLabel)
  1748. modelName, _ := result.GetString(ModelNameLabel)
  1749. hostName, _ := result.GetString(HostNameLabel)
  1750. return &DCGMDeviceInfoResult{
  1751. UUID: uuid,
  1752. Device: device,
  1753. ModelName: modelName,
  1754. HostName: hostName,
  1755. }
  1756. }
  1757. type DCGMDeviceUptimeResult struct {
  1758. UUID string
  1759. First time.Time
  1760. Last time.Time
  1761. }
  1762. func (res *DCGMDeviceUptimeResult) GetStartEnd(windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
  1763. return getStartEnd(res.First, res.Last, windowStart, windowEnd, resolution)
  1764. }
  1765. func getStartEnd(first, last, windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
  1766. // The only corner-case here is what to do if you only get one timestamp.
  1767. // This dilemma still requires the use of the resolution, and can be
  1768. // clamped using the window. In this case, we want to honor the existence
  1769. // of the pod by giving "one resolution" worth of duration, half on each
  1770. // side of the given timestamp.
  1771. if first.Equal(last) {
  1772. first = first.Add(-1 * resolution / time.Duration(2))
  1773. last = last.Add(resolution / time.Duration(2))
  1774. }
  1775. if first.Before(windowStart) {
  1776. first = windowStart
  1777. }
  1778. if last.After(windowEnd) {
  1779. last = windowEnd
  1780. }
  1781. // prevent end times in the future
  1782. now := time.Now().UTC()
  1783. if last.After(now) {
  1784. last = now
  1785. }
  1786. return first, last
  1787. }
  1788. func DecodeDCGMDeviceUptimeResult(result *QueryResult) *DCGMDeviceUptimeResult {
  1789. uuid, _ := result.GetString(UUIDLabel)
  1790. first := time.Unix(int64(result.Values[0].Timestamp), 0).UTC()
  1791. last := time.Unix(int64(result.Values[len(result.Values)-1].Timestamp), 0).UTC()
  1792. return &DCGMDeviceUptimeResult{
  1793. UUID: uuid,
  1794. First: first,
  1795. Last: last,
  1796. }
  1797. }
  1798. type DCGMDeviceContainerUsageResult struct {
  1799. UUID string
  1800. PodUID string
  1801. Container string
  1802. Value float64
  1803. }
  1804. func DecodeDCGMDeviceContainerUsageResult(result *QueryResult) *DCGMDeviceContainerUsageResult {
  1805. uuid, _ := result.GetString(UUIDLabel)
  1806. podUID, _ := result.GetString(PodUIDLabel)
  1807. container, _ := result.GetString(ContainerLabel)
  1808. var value float64
  1809. if len(result.Values) > 0 {
  1810. value = result.Values[0].Value
  1811. } else {
  1812. log.Warnf("Error decoding DCGM Device Container Udage Result for device '%s': empty value returned", uuid)
  1813. }
  1814. return &DCGMDeviceContainerUsageResult{
  1815. UUID: uuid,
  1816. PodUID: podUID,
  1817. Container: container,
  1818. Value: value,
  1819. }
  1820. }
  1821. func DecodeAll[T any](results []*QueryResult, decode ResultDecoder[T]) []*T {
  1822. decoded := make([]*T, 0, len(results))
  1823. for _, result := range results {
  1824. decoded = append(decoded, decode(result))
  1825. }
  1826. return decoded
  1827. }