2
0

decoders.go 54 KB

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