decoders.go 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  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. KubeModelVersion = "kubemodel_version"
  63. ArgLabel = "arg"
  64. ValueLabel = "value"
  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 ClusterKubeModelVersionResult struct {
  580. UID string
  581. Version string
  582. }
  583. func DecodeClusterKubeModelVersionResult(result *QueryResult) *ClusterKubeModelVersionResult {
  584. uid, _ := result.GetString(UIDLabel)
  585. version, _ := result.GetString(KubeModelVersion)
  586. return &ClusterKubeModelVersionResult{
  587. UID: uid,
  588. Version: version,
  589. }
  590. }
  591. type ClusterManagementDurationResult struct {
  592. UID string
  593. Cluster string
  594. Provisioner string
  595. Data []*util.Vector
  596. }
  597. func DecodeClusterManagementDurationResult(result *QueryResult) *ClusterManagementDurationResult {
  598. uid, _ := result.GetString(UIDLabel)
  599. cluster, _ := result.GetCluster()
  600. provisioner, _ := result.GetString(ProvisionerNameLabel)
  601. return &ClusterManagementDurationResult{
  602. UID: uid,
  603. Cluster: cluster,
  604. Provisioner: provisioner,
  605. Data: result.Values,
  606. }
  607. }
  608. type ClusterManagementPricePerHrResult = ClusterManagementDurationResult
  609. func DecodeClusterManagementPricePerHrResult(result *QueryResult) *ClusterManagementPricePerHrResult {
  610. return DecodeClusterManagementDurationResult(result)
  611. }
  612. type PodInfoResult struct {
  613. UID string
  614. Cluster string
  615. Pod string
  616. NamespaceUID string
  617. NodeUID string
  618. }
  619. func DecodePodInfoResult(result *QueryResult) *PodInfoResult {
  620. uid, _ := result.GetString(UIDLabel)
  621. cluster, _ := result.GetCluster()
  622. pod, _ := result.GetPod()
  623. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  624. nodeUID, _ := result.GetString(NodeUIDLabel)
  625. return &PodInfoResult{
  626. UID: uid,
  627. Cluster: cluster,
  628. Pod: pod,
  629. NamespaceUID: namespaceUID,
  630. NodeUID: nodeUID,
  631. }
  632. }
  633. type PodPVCVolumeResult struct {
  634. UID string
  635. Cluster string
  636. PVCUID string
  637. PodVolumeName string
  638. }
  639. func DecodePodPVCVolumeResult(result *QueryResult) *PodPVCVolumeResult {
  640. uid, _ := result.GetString(UIDLabel)
  641. cluster, _ := result.GetCluster()
  642. pvcUID, _ := result.GetString(PVCUIDLabel)
  643. podVolumeName, _ := result.GetString(PodVolumeNameLabel)
  644. return &PodPVCVolumeResult{
  645. UID: uid,
  646. Cluster: cluster,
  647. PVCUID: pvcUID,
  648. PodVolumeName: podVolumeName,
  649. }
  650. }
  651. type OwnerResult struct {
  652. UID string
  653. Cluster string
  654. OwnerUID string
  655. OwnerKind string
  656. Controller bool
  657. }
  658. func DecodeOwnerResult(result *QueryResult) *OwnerResult {
  659. uid, _ := result.GetString(UIDLabel)
  660. cluster, _ := result.GetCluster()
  661. ownerUID, _ := result.GetString(OwnerUIDLabel)
  662. ownerKind, _ := result.GetString(OwnerKindLabel)
  663. controller, _ := result.GetBool(ControllerLabel)
  664. return &OwnerResult{
  665. UID: uid,
  666. Cluster: cluster,
  667. OwnerUID: ownerUID,
  668. OwnerKind: ownerKind,
  669. Controller: controller,
  670. }
  671. }
  672. type PodsResult struct {
  673. UID string
  674. Cluster string
  675. Namespace string
  676. Pod string
  677. Data []*util.Vector
  678. }
  679. func DecodePodsResult(result *QueryResult) *PodsResult {
  680. uid, _ := result.GetString(UIDLabel)
  681. cluster, _ := result.GetCluster()
  682. namespace, _ := result.GetNamespace()
  683. pod, _ := result.GetPod()
  684. return &PodsResult{
  685. UID: uid,
  686. Cluster: cluster,
  687. Namespace: namespace,
  688. Pod: pod,
  689. Data: result.Values,
  690. }
  691. }
  692. type ContainerMetricResult struct {
  693. UID string
  694. Cluster string
  695. Node string
  696. Instance string
  697. Namespace string
  698. Pod string
  699. Container string
  700. Data []*util.Vector
  701. }
  702. func DecodeContainerMetricResult(result *QueryResult) *ContainerMetricResult {
  703. uid, _ := result.GetString(UIDLabel)
  704. cluster, _ := result.GetCluster()
  705. node, _ := result.GetNode()
  706. instance, _ := result.GetInstance()
  707. // NOTE: this addresses cases where the node isn't set, but the instance is,
  708. // NOTE: we just inherit the instance as the node
  709. if node == "" {
  710. node = instance
  711. }
  712. namespace, _ := result.GetNamespace()
  713. pod, _ := result.GetPod()
  714. container, _ := result.GetContainer()
  715. return &ContainerMetricResult{
  716. UID: uid,
  717. Cluster: cluster,
  718. Node: node,
  719. Instance: instance,
  720. Namespace: namespace,
  721. Pod: pod,
  722. Container: container,
  723. Data: result.Values,
  724. }
  725. }
  726. type RAMBytesAllocatedResult = ContainerMetricResult
  727. func DecodeRAMBytesAllocatedResult(result *QueryResult) *RAMBytesAllocatedResult {
  728. return DecodeContainerMetricResult(result)
  729. }
  730. type RAMRequestsResult = ContainerMetricResult
  731. func DecodeRAMRequestsResult(result *QueryResult) *RAMRequestsResult {
  732. return DecodeContainerMetricResult(result)
  733. }
  734. type RAMLimitsResult = ContainerMetricResult
  735. func DecodeRAMLimitsResult(result *QueryResult) *RAMLimitsResult {
  736. return DecodeContainerMetricResult(result)
  737. }
  738. type RAMUsageAvgResult = ContainerMetricResult
  739. func DecodeRAMUsageAvgResult(result *QueryResult) *RAMUsageAvgResult {
  740. return DecodeContainerMetricResult(result)
  741. }
  742. type RAMUsageMaxResult = ContainerMetricResult
  743. func DecodeRAMUsageMaxResult(result *QueryResult) *RAMUsageMaxResult {
  744. return DecodeContainerMetricResult(result)
  745. }
  746. type NodeRAMPricePerGiBHrResult struct {
  747. UID string
  748. Cluster string
  749. Node string
  750. InstanceType string
  751. ProviderID string
  752. Data []*util.Vector
  753. }
  754. func DecodeNodeRAMPricePerGiBHrResult(result *QueryResult) *NodeRAMPricePerGiBHrResult {
  755. uid, _ := result.GetString(UIDLabel)
  756. cluster, _ := result.GetCluster()
  757. node, _ := result.GetNode()
  758. instanceType, _ := result.GetInstanceType()
  759. providerId, _ := result.GetProviderID()
  760. return &NodeRAMPricePerGiBHrResult{
  761. UID: uid,
  762. Cluster: cluster,
  763. Node: node,
  764. InstanceType: instanceType,
  765. ProviderID: providerId,
  766. Data: result.Values,
  767. }
  768. }
  769. type CPUCoresAllocatedResult = ContainerMetricResult
  770. func DecodeCPUCoresAllocatedResult(result *QueryResult) *CPUCoresAllocatedResult {
  771. return DecodeContainerMetricResult(result)
  772. }
  773. type CPURequestsResult = ContainerMetricResult
  774. func DecodeCPURequestsResult(result *QueryResult) *CPURequestsResult {
  775. return DecodeContainerMetricResult(result)
  776. }
  777. type CPULimitsResult = ContainerMetricResult
  778. func DecodeCPULimitsResult(result *QueryResult) *CPULimitsResult {
  779. return DecodeContainerMetricResult(result)
  780. }
  781. type CPUUsageAvgResult = ContainerMetricResult
  782. func DecodeCPUUsageAvgResult(result *QueryResult) *CPUUsageAvgResult {
  783. return DecodeContainerMetricResult(result)
  784. }
  785. type CPUUsageMaxResult = ContainerMetricResult
  786. func DecodeCPUUsageMaxResult(result *QueryResult) *CPUUsageMaxResult {
  787. return DecodeContainerMetricResult(result)
  788. }
  789. type NodeCPUPricePerHrResult struct {
  790. UID string
  791. Cluster string
  792. Node string
  793. InstanceType string
  794. ProviderID string
  795. Data []*util.Vector
  796. }
  797. func DecodeNodeCPUPricePerHrResult(result *QueryResult) *NodeCPUPricePerHrResult {
  798. uid, _ := result.GetString(UIDLabel)
  799. cluster, _ := result.GetCluster()
  800. node, _ := result.GetNode()
  801. instanceType, _ := result.GetInstanceType()
  802. providerId, _ := result.GetProviderID()
  803. return &NodeCPUPricePerHrResult{
  804. UID: uid,
  805. Cluster: cluster,
  806. Node: node,
  807. InstanceType: instanceType,
  808. ProviderID: providerId,
  809. Data: result.Values,
  810. }
  811. }
  812. // type alias requested result to allocated result, as you can only request a full GPU
  813. type GPUsRequestedResult = GPUsAllocatedResult
  814. func DecodeGPUsRequestedResult(result *QueryResult) *GPUsRequestedResult {
  815. return DecodeGPUsAllocatedResult(result)
  816. }
  817. type GPUsAllocatedResult struct {
  818. UID string
  819. Cluster string
  820. Namespace string
  821. Pod string
  822. Container string
  823. Data []*util.Vector
  824. }
  825. func DecodeGPUsAllocatedResult(result *QueryResult) *GPUsAllocatedResult {
  826. uid, _ := result.GetString(UIDLabel)
  827. cluster, _ := result.GetCluster()
  828. namespace, _ := result.GetNamespace()
  829. pod, _ := result.GetPod()
  830. container, _ := result.GetContainer()
  831. return &GPUsAllocatedResult{
  832. UID: uid,
  833. Cluster: cluster,
  834. Namespace: namespace,
  835. Pod: pod,
  836. Container: container,
  837. Data: result.Values,
  838. }
  839. }
  840. type GPUsUsageAvgResult struct {
  841. UID string
  842. Cluster string
  843. Namespace string
  844. Pod string
  845. Container string
  846. Data []*util.Vector
  847. }
  848. func DecodeGPUsUsageAvgResult(result *QueryResult) *GPUsUsageAvgResult {
  849. uid, _ := result.GetString(PodUIDLabel)
  850. cluster, _ := result.GetCluster()
  851. namespace, _ := result.GetNamespace()
  852. pod, _ := result.GetPod()
  853. container, _ := result.GetContainer()
  854. return &GPUsUsageAvgResult{
  855. UID: uid,
  856. Cluster: cluster,
  857. Namespace: namespace,
  858. Pod: pod,
  859. Container: container,
  860. Data: result.Values,
  861. }
  862. }
  863. type GPUsUsageMaxResult struct {
  864. UID string
  865. Cluster string
  866. Namespace string
  867. Pod string
  868. Container string
  869. Data []*util.Vector
  870. }
  871. func DecodeGPUsUsageMaxResult(result *QueryResult) *GPUsUsageMaxResult {
  872. uid, _ := result.GetString(PodUIDLabel)
  873. cluster, _ := result.GetCluster()
  874. namespace, _ := result.GetNamespace()
  875. pod, _ := result.GetPod()
  876. container, _ := result.GetContainer()
  877. return &GPUsUsageMaxResult{
  878. UID: uid,
  879. Cluster: cluster,
  880. Namespace: namespace,
  881. Pod: pod,
  882. Container: container,
  883. Data: result.Values,
  884. }
  885. }
  886. type NodeGPUPricePerHrResult struct {
  887. UID string
  888. Cluster string
  889. Node string
  890. InstanceType string
  891. ProviderID string
  892. Data []*util.Vector
  893. }
  894. func DecodeNodeGPUPricePerHrResult(result *QueryResult) *NodeGPUPricePerHrResult {
  895. uid, _ := result.GetString(UIDLabel)
  896. cluster, _ := result.GetCluster()
  897. node, _ := result.GetNode()
  898. instanceType, _ := result.GetInstanceType()
  899. providerId, _ := result.GetProviderID()
  900. return &NodeGPUPricePerHrResult{
  901. UID: uid,
  902. Cluster: cluster,
  903. Node: node,
  904. InstanceType: instanceType,
  905. ProviderID: providerId,
  906. Data: result.Values,
  907. }
  908. }
  909. type GPUInfoResult struct {
  910. UID string
  911. Cluster string
  912. Namespace string
  913. Pod string
  914. Container string
  915. Device string
  916. ModelName string
  917. UUID string
  918. Data []*util.Vector
  919. }
  920. func DecodeGPUInfoResult(result *QueryResult) *GPUInfoResult {
  921. uid, _ := result.GetString(PodUIDLabel)
  922. cluster, _ := result.GetCluster()
  923. namespace, _ := result.GetNamespace()
  924. pod, _ := result.GetPod()
  925. container, _ := result.GetContainer()
  926. device, _ := result.GetString(DeviceLabel)
  927. modelName, _ := result.GetString(ModelNameLabel)
  928. uuid, _ := result.GetString(UUIDLabel)
  929. return &GPUInfoResult{
  930. UID: uid,
  931. Cluster: cluster,
  932. Namespace: namespace,
  933. Pod: pod,
  934. Container: container,
  935. Device: device,
  936. ModelName: modelName,
  937. UUID: uuid,
  938. Data: result.Values,
  939. }
  940. }
  941. type IsGPUSharedResult struct {
  942. UID string
  943. Cluster string
  944. Namespace string
  945. Pod string
  946. Container string
  947. Resource string
  948. Data []*util.Vector
  949. }
  950. func DecodeIsGPUSharedResult(result *QueryResult) *IsGPUSharedResult {
  951. uid, _ := result.GetString(UIDLabel)
  952. cluster, _ := result.GetCluster()
  953. namespace, _ := result.GetNamespace()
  954. pod, _ := result.GetPod()
  955. container, _ := result.GetContainer()
  956. resource, _ := result.GetString(ResourceLabel)
  957. return &IsGPUSharedResult{
  958. UID: uid,
  959. Cluster: cluster,
  960. Namespace: namespace,
  961. Pod: pod,
  962. Container: container,
  963. Resource: resource,
  964. Data: result.Values,
  965. }
  966. }
  967. type PodPVCAllocationResult struct {
  968. UID string
  969. Cluster string
  970. Namespace string
  971. Pod string
  972. PersistentVolume string
  973. PersistentVolumeClaim string
  974. Data []*util.Vector
  975. }
  976. func DecodePodPVCAllocationResult(result *QueryResult) *PodPVCAllocationResult {
  977. uid, _ := result.GetString(UIDLabel)
  978. cluster, _ := result.GetCluster()
  979. namespace, _ := result.GetNamespace()
  980. pod, _ := result.GetPod()
  981. pv, _ := result.GetString(PVLabel)
  982. pvc, _ := result.GetString(PVCLabel)
  983. return &PodPVCAllocationResult{
  984. UID: uid,
  985. Cluster: cluster,
  986. Namespace: namespace,
  987. Pod: pod,
  988. PersistentVolume: pv,
  989. PersistentVolumeClaim: pvc,
  990. Data: result.Values,
  991. }
  992. }
  993. type PVCBytesRequestedResult struct {
  994. UID string
  995. Cluster string
  996. Namespace string
  997. PersistentVolumeClaim string
  998. Data []*util.Vector
  999. }
  1000. func DecodePVCBytesRequestedResult(result *QueryResult) *PVCBytesRequestedResult {
  1001. uid, _ := result.GetString(UIDLabel)
  1002. cluster, _ := result.GetCluster()
  1003. namespace, _ := result.GetNamespace()
  1004. pvc, _ := result.GetString(PVCLabel)
  1005. return &PVCBytesRequestedResult{
  1006. UID: uid,
  1007. Cluster: cluster,
  1008. Namespace: namespace,
  1009. PersistentVolumeClaim: pvc,
  1010. Data: result.Values,
  1011. }
  1012. }
  1013. type PVCInfoResult struct {
  1014. UID string
  1015. Cluster string
  1016. NamespaceUID string
  1017. Namespace string
  1018. VolumeName string
  1019. PVUID string
  1020. PersistentVolumeClaim string
  1021. StorageClass string
  1022. Data []*util.Vector
  1023. }
  1024. func DecodePVCInfoResult(result *QueryResult) *PVCInfoResult {
  1025. uid, _ := result.GetString(UIDLabel)
  1026. cluster, _ := result.GetCluster()
  1027. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1028. namespace, _ := result.GetNamespace()
  1029. pvUID, _ := result.GetString(PVUIDLabel)
  1030. volumeName, _ := result.GetString(VolumeNameLabel)
  1031. pvc, _ := result.GetString(PVCLabel)
  1032. storageClass, _ := result.GetString(StorageClassLabel)
  1033. return &PVCInfoResult{
  1034. UID: uid,
  1035. Cluster: cluster,
  1036. NamespaceUID: namespaceUID,
  1037. Namespace: namespace,
  1038. PVUID: pvUID,
  1039. VolumeName: volumeName,
  1040. PersistentVolumeClaim: pvc,
  1041. StorageClass: storageClass,
  1042. Data: result.Values,
  1043. }
  1044. }
  1045. type PVBytesResult struct {
  1046. UID string
  1047. Cluster string
  1048. PersistentVolume string
  1049. Value float64
  1050. }
  1051. func DecodePVBytesResult(result *QueryResult) *PVBytesResult {
  1052. uid, _ := result.GetString(UIDLabel)
  1053. cluster, _ := result.GetCluster()
  1054. pv, _ := result.GetString(PVLabel)
  1055. var value float64
  1056. if len(result.Values) > 0 {
  1057. value = result.Values[0].Value
  1058. } else {
  1059. log.Warnf("Error decoding PV bytes result for pv '%s': empty value returned", uid)
  1060. }
  1061. return &PVBytesResult{
  1062. UID: uid,
  1063. Cluster: cluster,
  1064. PersistentVolume: pv,
  1065. Value: value,
  1066. }
  1067. }
  1068. type PVPricePerGiBHourResult struct {
  1069. UID string
  1070. Cluster string
  1071. VolumeName string
  1072. PersistentVolume string
  1073. ProviderID string
  1074. Data []*util.Vector
  1075. }
  1076. func DecodePVPricePerGiBHourResult(result *QueryResult) *PVPricePerGiBHourResult {
  1077. uid, _ := result.GetString(UIDLabel)
  1078. cluster, _ := result.GetCluster()
  1079. volumeName, _ := result.GetString(VolumeNameLabel)
  1080. pv, _ := result.GetString(PVLabel)
  1081. providerId, _ := result.GetProviderID()
  1082. return &PVPricePerGiBHourResult{
  1083. UID: uid,
  1084. Cluster: cluster,
  1085. VolumeName: volumeName,
  1086. PersistentVolume: pv,
  1087. ProviderID: providerId,
  1088. Data: result.Values,
  1089. }
  1090. }
  1091. type PVInfoResult struct {
  1092. UID string
  1093. Cluster string
  1094. PersistentVolume string
  1095. StorageClass string
  1096. ProviderID string
  1097. CSIVolumeHandle string
  1098. Data []*util.Vector
  1099. }
  1100. func DecodePVInfoResult(result *QueryResult) *PVInfoResult {
  1101. uid, _ := result.GetString(UIDLabel)
  1102. cluster, _ := result.GetCluster()
  1103. storageClass, _ := result.GetString(StorageClassLabel)
  1104. providerId, _ := result.GetProviderID()
  1105. pv, _ := result.GetString(PVLabel)
  1106. csiVolumeHandle, _ := result.GetString(CSIVolumeHandleLabel)
  1107. return &PVInfoResult{
  1108. UID: uid,
  1109. Cluster: cluster,
  1110. PersistentVolume: pv,
  1111. StorageClass: storageClass,
  1112. ProviderID: providerId,
  1113. CSIVolumeHandle: csiVolumeHandle,
  1114. Data: result.Values,
  1115. }
  1116. }
  1117. type PodNetworkBytesResult struct {
  1118. UID string
  1119. Cluster string
  1120. Service string
  1121. Internet bool
  1122. SameRegion bool
  1123. SameZone bool
  1124. NatGateway bool
  1125. Value float64
  1126. }
  1127. func DecodePodNetworkBytesResult(result *QueryResult) *PodNetworkBytesResult {
  1128. uid, _ := result.GetString(UIDLabel)
  1129. cluster, _ := result.GetCluster()
  1130. service, _ := result.GetString(ServiceLabel)
  1131. internet, _ := result.GetBool(InternetLabel)
  1132. sameRegion, _ := result.GetBool(SameRegionLabel)
  1133. sameZone, _ := result.GetBool(SameZoneLabel)
  1134. natGateway, _ := result.GetBool(NatGatewayLabel)
  1135. var value float64
  1136. if len(result.Values) > 0 {
  1137. value = result.Values[0].Value
  1138. } else {
  1139. log.Warnf("Error decoding pod network bytes result for pod '%s': empty value returned", uid)
  1140. }
  1141. return &PodNetworkBytesResult{
  1142. UID: uid,
  1143. Cluster: cluster,
  1144. Service: service,
  1145. Internet: internet,
  1146. SameRegion: sameRegion,
  1147. SameZone: sameZone,
  1148. NatGateway: natGateway,
  1149. Value: value,
  1150. }
  1151. }
  1152. // Base type for network usage results
  1153. type NetworkGiBResult struct {
  1154. UID string
  1155. Cluster string
  1156. Namespace string
  1157. Pod string
  1158. Service string
  1159. Data []*util.Vector
  1160. }
  1161. func DecodeNetworkGiBResult(result *QueryResult) *NetworkGiBResult {
  1162. uid, _ := result.GetString(UIDLabel)
  1163. cluster, _ := result.GetCluster()
  1164. namespace, _ := result.GetNamespace()
  1165. pod, _ := result.GetPod()
  1166. service, _ := result.GetString(ServiceLabel)
  1167. return &NetworkGiBResult{
  1168. UID: uid,
  1169. Cluster: cluster,
  1170. Namespace: namespace,
  1171. Pod: pod,
  1172. Service: service,
  1173. Data: result.Values,
  1174. }
  1175. }
  1176. // Base type for network price results
  1177. type NetworkPricePerGiBResult struct {
  1178. UID string
  1179. Cluster string
  1180. Data []*util.Vector
  1181. }
  1182. func DecodeNetworkPricePerGiBResult(result *QueryResult) *NetworkPricePerGiBResult {
  1183. uid, _ := result.GetString(UIDLabel)
  1184. cluster, _ := result.GetCluster()
  1185. return &NetworkPricePerGiBResult{
  1186. UID: uid,
  1187. Cluster: cluster,
  1188. Data: result.Values,
  1189. }
  1190. }
  1191. // Type alias the specific network subclassification results AND price results
  1192. type NetZoneGiBResult = NetworkGiBResult
  1193. type NetZonePricePerGiBResult = NetworkPricePerGiBResult
  1194. type NetRegionGiBResult = NetworkGiBResult
  1195. type NetRegionPricePerGiBResult = NetworkPricePerGiBResult
  1196. type NetInternetGiBResult = NetworkGiBResult
  1197. type NetInternetPricePerGiBResult = NetworkPricePerGiBResult
  1198. type NetInternetServiceGiBResult = NetworkGiBResult
  1199. type NetNatGatewayPricePerGiBResult = NetworkPricePerGiBResult
  1200. type NetNatGatewayGiBResult = NetworkGiBResult
  1201. type NetZoneIngressGiBResult = NetworkGiBResult
  1202. type NetRegionIngressGiBResult = NetworkGiBResult
  1203. type NetInternetIngressGiBResult = NetworkGiBResult
  1204. type NetInternetServiceIngressGiBResult = NetworkGiBResult
  1205. type NetNatGatewayIngressGiBResult = NetworkGiBResult
  1206. func DecodeNetZoneGiBResult(result *QueryResult) *NetZoneGiBResult {
  1207. return DecodeNetworkGiBResult(result)
  1208. }
  1209. func DecodeNetZonePricePerGiBResult(result *QueryResult) *NetZonePricePerGiBResult {
  1210. return DecodeNetworkPricePerGiBResult(result)
  1211. }
  1212. func DecodeNetRegionGiBResult(result *QueryResult) *NetRegionGiBResult {
  1213. return DecodeNetworkGiBResult(result)
  1214. }
  1215. func DecodeNetRegionPricePerGiBResult(result *QueryResult) *NetRegionPricePerGiBResult {
  1216. return DecodeNetworkPricePerGiBResult(result)
  1217. }
  1218. func DecodeNetInternetGiBResult(result *QueryResult) *NetInternetGiBResult {
  1219. return DecodeNetworkGiBResult(result)
  1220. }
  1221. func DecodeNetInternetPricePerGiBResult(result *QueryResult) *NetInternetPricePerGiBResult {
  1222. return DecodeNetworkPricePerGiBResult(result)
  1223. }
  1224. func DecodeNetInternetServiceGiBResult(result *QueryResult) *NetInternetServiceGiBResult {
  1225. return DecodeNetworkGiBResult(result)
  1226. }
  1227. func DecodeNetNatGatewayPricePerGiBResult(result *QueryResult) *NetNatGatewayPricePerGiBResult {
  1228. return DecodeNetworkPricePerGiBResult(result)
  1229. }
  1230. func DecodeNetNatGatewayGiBResult(result *QueryResult) *NetNatGatewayGiBResult {
  1231. return DecodeNetworkGiBResult(result)
  1232. }
  1233. func DecodeNetZoneIngressGiBResult(result *QueryResult) *NetZoneIngressGiBResult {
  1234. return DecodeNetworkGiBResult(result)
  1235. }
  1236. func DecodeNetRegionIngressGiBResult(result *QueryResult) *NetRegionIngressGiBResult {
  1237. return DecodeNetworkGiBResult(result)
  1238. }
  1239. func DecodeNetInternetIngressGiBResult(result *QueryResult) *NetInternetIngressGiBResult {
  1240. return DecodeNetworkGiBResult(result)
  1241. }
  1242. func DecodeNetInternetServiceIngressGiBResult(result *QueryResult) *NetInternetServiceIngressGiBResult {
  1243. return DecodeNetworkGiBResult(result)
  1244. }
  1245. func DecodeNetNatGatewayIngressGiBResult(result *QueryResult) *NetNatGatewayIngressGiBResult {
  1246. return DecodeNetworkGiBResult(result)
  1247. }
  1248. type NetReceiveBytesResult struct {
  1249. UID string
  1250. Cluster string
  1251. Namespace string
  1252. Pod string
  1253. Container string
  1254. Data []*util.Vector
  1255. }
  1256. func DecodeNetReceiveBytesResult(result *QueryResult) *NetReceiveBytesResult {
  1257. uid, _ := result.GetString(UIDLabel)
  1258. cluster, _ := result.GetCluster()
  1259. namespace, _ := result.GetNamespace()
  1260. pod, _ := result.GetPod()
  1261. container, _ := result.GetContainer()
  1262. return &NetReceiveBytesResult{
  1263. UID: uid,
  1264. Cluster: cluster,
  1265. Namespace: namespace,
  1266. Pod: pod,
  1267. Container: container,
  1268. Data: result.Values,
  1269. }
  1270. }
  1271. type NetTransferBytesResult struct {
  1272. UID string
  1273. Cluster string
  1274. Namespace string
  1275. Pod string
  1276. Container string
  1277. Data []*util.Vector
  1278. }
  1279. func DecodeNetTransferBytesResult(result *QueryResult) *NetTransferBytesResult {
  1280. uid, _ := result.GetString(UIDLabel)
  1281. cluster, _ := result.GetCluster()
  1282. namespace, _ := result.GetNamespace()
  1283. pod, _ := result.GetPod()
  1284. container, _ := result.GetContainer()
  1285. return &NetTransferBytesResult{
  1286. UID: uid,
  1287. Cluster: cluster,
  1288. Namespace: namespace,
  1289. Pod: pod,
  1290. Container: container,
  1291. Data: result.Values,
  1292. }
  1293. }
  1294. type NamespaceAnnotationsResult struct {
  1295. UID string
  1296. Cluster string
  1297. Namespace string
  1298. Annotations map[string]string
  1299. Data []*util.Vector
  1300. }
  1301. func DecodeNamespaceAnnotationsResult(result *QueryResult) *NamespaceAnnotationsResult {
  1302. uid, _ := result.GetString(UIDLabel)
  1303. cluster, _ := result.GetCluster()
  1304. namespace, _ := result.GetNamespace()
  1305. annotations := result.GetAnnotations()
  1306. return &NamespaceAnnotationsResult{
  1307. UID: uid,
  1308. Cluster: cluster,
  1309. Namespace: namespace,
  1310. Annotations: annotations,
  1311. Data: result.Values,
  1312. }
  1313. }
  1314. type PodAnnotationsResult struct {
  1315. UID string
  1316. Cluster string
  1317. Namespace string
  1318. Pod string
  1319. Annotations map[string]string
  1320. Data []*util.Vector
  1321. }
  1322. func DecodePodAnnotationsResult(result *QueryResult) *PodAnnotationsResult {
  1323. uid, _ := result.GetString(UIDLabel)
  1324. cluster, _ := result.GetCluster()
  1325. namespace, _ := result.GetNamespace()
  1326. pod, _ := result.GetPod()
  1327. annotations := result.GetAnnotations()
  1328. return &PodAnnotationsResult{
  1329. UID: uid,
  1330. Cluster: cluster,
  1331. Namespace: namespace,
  1332. Pod: pod,
  1333. Annotations: annotations,
  1334. Data: result.Values,
  1335. }
  1336. }
  1337. type NodeLabelsResult struct {
  1338. UID string
  1339. Cluster string
  1340. Node string
  1341. Labels map[string]string
  1342. }
  1343. func DecodeNodeLabelsResult(result *QueryResult) *NodeLabelsResult {
  1344. uid, _ := result.GetString(UIDLabel)
  1345. cluster, _ := result.GetCluster()
  1346. node, _ := result.GetNode()
  1347. labels := result.GetLabels()
  1348. return &NodeLabelsResult{
  1349. UID: uid,
  1350. Cluster: cluster,
  1351. Node: node,
  1352. Labels: labels,
  1353. }
  1354. }
  1355. type NamespaceInfoResult struct {
  1356. UID string
  1357. Cluster string
  1358. Namespace string
  1359. }
  1360. func DecodeNamespaceInfoResult(result *QueryResult) *NamespaceInfoResult {
  1361. uid, _ := result.GetString(UIDLabel)
  1362. cluster, _ := result.GetCluster()
  1363. namespace, _ := result.GetNamespace()
  1364. return &NamespaceInfoResult{
  1365. UID: uid,
  1366. Cluster: cluster,
  1367. Namespace: namespace,
  1368. }
  1369. }
  1370. type NamespaceLabelsResult struct {
  1371. UID string
  1372. Cluster string
  1373. Namespace string
  1374. Labels map[string]string
  1375. Data []*util.Vector
  1376. }
  1377. func DecodeNamespaceLabelsResult(result *QueryResult) *NamespaceLabelsResult {
  1378. uid, _ := result.GetString(UIDLabel)
  1379. cluster, _ := result.GetCluster()
  1380. namespace, _ := result.GetNamespace()
  1381. labels := result.GetLabels()
  1382. return &NamespaceLabelsResult{
  1383. UID: uid,
  1384. Cluster: cluster,
  1385. Namespace: namespace,
  1386. Labels: labels,
  1387. Data: result.Values,
  1388. }
  1389. }
  1390. type PodLabelsResult struct {
  1391. UID string
  1392. Cluster string
  1393. Namespace string
  1394. Pod string
  1395. Labels map[string]string
  1396. Data []*util.Vector
  1397. }
  1398. func DecodePodLabelsResult(result *QueryResult) *PodLabelsResult {
  1399. uid, _ := result.GetString(UIDLabel)
  1400. cluster, _ := result.GetCluster()
  1401. namespace, _ := result.GetNamespace()
  1402. pod, _ := result.GetPod()
  1403. labels := result.GetLabels()
  1404. return &PodLabelsResult{
  1405. UID: uid,
  1406. Cluster: cluster,
  1407. Namespace: namespace,
  1408. Pod: pod,
  1409. Labels: labels,
  1410. Data: result.Values,
  1411. }
  1412. }
  1413. type ServiceLabelsResult struct {
  1414. UID string
  1415. Cluster string
  1416. Namespace string
  1417. Service string
  1418. Labels map[string]string
  1419. Data []*util.Vector
  1420. }
  1421. func DecodeServiceLabelsResult(result *QueryResult) *ServiceLabelsResult {
  1422. uid, _ := result.GetString(UIDLabel)
  1423. cluster, _ := result.GetCluster()
  1424. namespace, _ := result.GetNamespace()
  1425. service, _ := result.GetString(ServiceLabel)
  1426. labels := result.GetLabels()
  1427. return &ServiceLabelsResult{
  1428. UID: uid,
  1429. Cluster: cluster,
  1430. Namespace: namespace,
  1431. Service: service,
  1432. Labels: labels,
  1433. Data: result.Values,
  1434. }
  1435. }
  1436. type ServiceInfoResult struct {
  1437. UID string
  1438. Cluster string
  1439. NamespaceUID string
  1440. Service string
  1441. ServiceType string
  1442. LBIngressAddress string
  1443. }
  1444. func DecodeServiceInfoResult(result *QueryResult) *ServiceInfoResult {
  1445. uid, _ := result.GetString(UIDLabel)
  1446. cluster, _ := result.GetCluster()
  1447. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1448. service, _ := result.GetString(ServiceLabel)
  1449. serviceType, _ := result.GetString(ServiceTypeLabel)
  1450. lbIngressAddress, _ := result.GetString(LBIngressAddress)
  1451. return &ServiceInfoResult{
  1452. UID: uid,
  1453. Cluster: cluster,
  1454. NamespaceUID: namespaceUID,
  1455. Service: service,
  1456. ServiceType: serviceType,
  1457. LBIngressAddress: lbIngressAddress,
  1458. }
  1459. }
  1460. type DeploymentInfoResult struct {
  1461. UID string
  1462. Cluster string
  1463. NamespaceUID string
  1464. Deployment string
  1465. }
  1466. func DecodeDeploymentInfoResult(result *QueryResult) *DeploymentInfoResult {
  1467. uid, _ := result.GetString(UIDLabel)
  1468. cluster, _ := result.GetCluster()
  1469. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1470. deployment, _ := result.GetString(DeploymentLabel)
  1471. return &DeploymentInfoResult{
  1472. UID: uid,
  1473. Cluster: cluster,
  1474. NamespaceUID: namespaceUID,
  1475. Deployment: deployment,
  1476. }
  1477. }
  1478. type DeploymentLabelsResult struct {
  1479. UID string
  1480. Cluster string
  1481. Namespace string
  1482. Deployment string
  1483. Labels map[string]string
  1484. Data []*util.Vector
  1485. }
  1486. func DecodeDeploymentLabelsResult(result *QueryResult) *DeploymentLabelsResult {
  1487. uid, _ := result.GetString(UIDLabel)
  1488. cluster, _ := result.GetCluster()
  1489. namespace, _ := result.GetNamespace()
  1490. deployment, _ := result.GetString(DeploymentLabel)
  1491. labels := result.GetLabels()
  1492. return &DeploymentLabelsResult{
  1493. UID: uid,
  1494. Cluster: cluster,
  1495. Namespace: namespace,
  1496. Deployment: deployment,
  1497. Labels: labels,
  1498. Data: result.Values,
  1499. }
  1500. }
  1501. type StatefulSetInfoResult struct {
  1502. UID string
  1503. Cluster string
  1504. NamespaceUID string
  1505. StatefulSet string
  1506. }
  1507. func DecodeStatefulSetInfoResult(result *QueryResult) *StatefulSetInfoResult {
  1508. uid, _ := result.GetString(UIDLabel)
  1509. cluster, _ := result.GetCluster()
  1510. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1511. statefulSet, _ := result.GetString(StatefulSetLabel)
  1512. return &StatefulSetInfoResult{
  1513. UID: uid,
  1514. Cluster: cluster,
  1515. NamespaceUID: namespaceUID,
  1516. StatefulSet: statefulSet,
  1517. }
  1518. }
  1519. type DaemonSetInfoResult struct {
  1520. UID string
  1521. Cluster string
  1522. NamespaceUID string
  1523. DaemonSet string
  1524. }
  1525. func DecodeDaemonSetInfoResult(result *QueryResult) *DaemonSetInfoResult {
  1526. uid, _ := result.GetString(UIDLabel)
  1527. cluster, _ := result.GetCluster()
  1528. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1529. daemonSet, _ := result.GetString(DaemonSetLabel)
  1530. return &DaemonSetInfoResult{
  1531. UID: uid,
  1532. Cluster: cluster,
  1533. NamespaceUID: namespaceUID,
  1534. DaemonSet: daemonSet,
  1535. }
  1536. }
  1537. // DaemonSetArgumentResult represents a single "--key=value" container argument parsed off a
  1538. // DaemonSet. One row is emitted per argument, so a DaemonSet with N arguments produces N results.
  1539. type DaemonSetArgumentResult struct {
  1540. UID string
  1541. Cluster string
  1542. Arg string
  1543. Value string
  1544. }
  1545. func DecodeDaemonSetArgumentResult(result *QueryResult) *DaemonSetArgumentResult {
  1546. uid, _ := result.GetString(UIDLabel)
  1547. cluster, _ := result.GetCluster()
  1548. arg, _ := result.GetString(ArgLabel)
  1549. value, _ := result.GetString(ValueLabel)
  1550. return &DaemonSetArgumentResult{
  1551. UID: uid,
  1552. Cluster: cluster,
  1553. Arg: arg,
  1554. Value: value,
  1555. }
  1556. }
  1557. type JobInfoResult struct {
  1558. UID string
  1559. Cluster string
  1560. NamespaceUID string
  1561. Job string
  1562. }
  1563. func DecodeJobInfoResult(result *QueryResult) *JobInfoResult {
  1564. uid, _ := result.GetString(UIDLabel)
  1565. cluster, _ := result.GetCluster()
  1566. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1567. job, _ := result.GetString(JobLabel)
  1568. return &JobInfoResult{
  1569. UID: uid,
  1570. Cluster: cluster,
  1571. NamespaceUID: namespaceUID,
  1572. Job: job,
  1573. }
  1574. }
  1575. type CronJobInfoResult struct {
  1576. UID string
  1577. Cluster string
  1578. NamespaceUID string
  1579. CronJob string
  1580. }
  1581. func DecodeCronJobInfoResult(result *QueryResult) *CronJobInfoResult {
  1582. uid, _ := result.GetString(UIDLabel)
  1583. cluster, _ := result.GetCluster()
  1584. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1585. cronJob, _ := result.GetString(CronJobLabel)
  1586. return &CronJobInfoResult{
  1587. UID: uid,
  1588. Cluster: cluster,
  1589. NamespaceUID: namespaceUID,
  1590. CronJob: cronJob,
  1591. }
  1592. }
  1593. type ReplicaSetInfoResult struct {
  1594. UID string
  1595. Cluster string
  1596. NamespaceUID string
  1597. ReplicaSet string
  1598. }
  1599. func DecodeReplicaSetInfoResult(result *QueryResult) *ReplicaSetInfoResult {
  1600. uid, _ := result.GetString(UIDLabel)
  1601. cluster, _ := result.GetCluster()
  1602. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1603. replicaSet, _ := result.GetString(ReplicaSetLabel)
  1604. return &ReplicaSetInfoResult{
  1605. UID: uid,
  1606. Cluster: cluster,
  1607. NamespaceUID: namespaceUID,
  1608. ReplicaSet: replicaSet,
  1609. }
  1610. }
  1611. type StatefulSetLabelsResult struct {
  1612. UID string
  1613. Cluster string
  1614. Namespace string
  1615. StatefulSet string
  1616. Labels map[string]string
  1617. Data []*util.Vector
  1618. }
  1619. func DecodeStatefulSetLabelsResult(result *QueryResult) *StatefulSetLabelsResult {
  1620. uid, _ := result.GetString(UIDLabel)
  1621. cluster, _ := result.GetCluster()
  1622. namespace, _ := result.GetNamespace()
  1623. statefulSet, _ := result.GetString(StatefulSetLabel)
  1624. labels := result.GetLabels()
  1625. return &StatefulSetLabelsResult{
  1626. UID: uid,
  1627. Cluster: cluster,
  1628. Namespace: namespace,
  1629. StatefulSet: statefulSet,
  1630. Labels: labels,
  1631. Data: result.Values,
  1632. }
  1633. }
  1634. type PodsWithDaemonSetOwnerResult struct {
  1635. UID string
  1636. Cluster string
  1637. Namespace string
  1638. Pod string
  1639. DaemonSet string
  1640. }
  1641. func DecodePodsWithDaemonSetOwnerResult(result *QueryResult) *PodsWithDaemonSetOwnerResult {
  1642. uid, _ := result.GetString(UIDLabel)
  1643. cluster, _ := result.GetCluster()
  1644. namespace, _ := result.GetNamespace()
  1645. pod, _ := result.GetPod()
  1646. daemonSet, _ := result.GetString(OwnerNameLabel)
  1647. return &PodsWithDaemonSetOwnerResult{
  1648. UID: uid,
  1649. Cluster: cluster,
  1650. Namespace: namespace,
  1651. Pod: pod,
  1652. DaemonSet: daemonSet,
  1653. }
  1654. }
  1655. type PodsWithJobOwnerResult struct {
  1656. UID string
  1657. Cluster string
  1658. Namespace string
  1659. Pod string
  1660. Job string
  1661. }
  1662. func DecodePodsWithJobOwnerResult(result *QueryResult) *PodsWithJobOwnerResult {
  1663. uid, _ := result.GetString(UIDLabel)
  1664. cluster, _ := result.GetCluster()
  1665. namespace, _ := result.GetNamespace()
  1666. pod, _ := result.GetPod()
  1667. job, _ := result.GetString(OwnerNameLabel)
  1668. return &PodsWithJobOwnerResult{
  1669. UID: uid,
  1670. Cluster: cluster,
  1671. Namespace: namespace,
  1672. Pod: pod,
  1673. Job: job,
  1674. }
  1675. }
  1676. type PodsWithReplicaSetOwnerResult struct {
  1677. UID string
  1678. Cluster string
  1679. Namespace string
  1680. Pod string
  1681. ReplicaSet string
  1682. Data []*util.Vector
  1683. }
  1684. func DecodePodsWithReplicaSetOwnerResult(result *QueryResult) *PodsWithReplicaSetOwnerResult {
  1685. uid, _ := result.GetString(UIDLabel)
  1686. cluster, _ := result.GetCluster()
  1687. namespace, _ := result.GetNamespace()
  1688. replicaSet, _ := result.GetString(OwnerNameLabel)
  1689. pod, _ := result.GetPod()
  1690. return &PodsWithReplicaSetOwnerResult{
  1691. UID: uid,
  1692. Cluster: cluster,
  1693. Namespace: namespace,
  1694. Pod: pod,
  1695. ReplicaSet: replicaSet,
  1696. Data: result.Values,
  1697. }
  1698. }
  1699. type ReplicaSetsWithoutOwnersResult struct {
  1700. UID string
  1701. Cluster string
  1702. Namespace string
  1703. ReplicaSet string
  1704. Data []*util.Vector
  1705. }
  1706. func DecodeReplicaSetsWithoutOwnersResult(result *QueryResult) *ReplicaSetsWithoutOwnersResult {
  1707. uid, _ := result.GetString(UIDLabel)
  1708. return &ReplicaSetsWithoutOwnersResult{
  1709. UID: uid,
  1710. Data: result.Values,
  1711. }
  1712. }
  1713. type ReplicaSetsWithRolloutResult struct {
  1714. UID string
  1715. Cluster string
  1716. Namespace string
  1717. ReplicaSet string
  1718. OwnerName string
  1719. OwnerKind string
  1720. Data []*util.Vector
  1721. }
  1722. func DecodeReplicaSetsWithRolloutResult(result *QueryResult) *ReplicaSetsWithRolloutResult {
  1723. uid, _ := result.GetString(UIDLabel)
  1724. cluster, _ := result.GetCluster()
  1725. namespace, _ := result.GetNamespace()
  1726. replicaSet, _ := result.GetString(ReplicaSetLabel)
  1727. ownerName, _ := result.GetString(OwnerNameLabel)
  1728. ownerKind, _ := result.GetString(OwnerKindLabel)
  1729. return &ReplicaSetsWithRolloutResult{
  1730. UID: uid,
  1731. Cluster: cluster,
  1732. Namespace: namespace,
  1733. ReplicaSet: replicaSet,
  1734. OwnerName: ownerName,
  1735. OwnerKind: ownerKind,
  1736. Data: result.Values,
  1737. }
  1738. }
  1739. type ResourceQuotaInfoResult struct {
  1740. UID string
  1741. NamespaceUID string
  1742. ResourceQuota string
  1743. }
  1744. func DecodeResourceQuotaInfoResult(result *QueryResult) *ResourceQuotaInfoResult {
  1745. uid, _ := result.GetString(UIDLabel)
  1746. namespaceUID, _ := result.GetString(NamespaceUIDLabel)
  1747. resourceQuota, _ := result.GetString(ResourceQuotaLabel)
  1748. return &ResourceQuotaInfoResult{
  1749. UID: uid,
  1750. NamespaceUID: namespaceUID,
  1751. ResourceQuota: resourceQuota,
  1752. }
  1753. }
  1754. type ResourceResult struct {
  1755. UID string
  1756. Resource string
  1757. Unit string
  1758. Value float64
  1759. }
  1760. func DecodeResourceResult(result *QueryResult) *ResourceResult {
  1761. uid, _ := result.GetString(UIDLabel)
  1762. resource, _ := result.GetString(ResourceLabel)
  1763. unit, _ := result.GetString(UnitLabel)
  1764. var value float64
  1765. if len(result.Values) > 0 {
  1766. value = result.Values[0].Value
  1767. } else {
  1768. log.Warnf("Error decoding resource for uid '%s': empty value returned", uid)
  1769. }
  1770. return &ResourceResult{
  1771. UID: uid,
  1772. Resource: resource,
  1773. Unit: unit,
  1774. Value: value,
  1775. }
  1776. }
  1777. // DCGM needs specialized results because it uses UUID instead of the uid label that we use.
  1778. type DCGMDeviceInfoResult struct {
  1779. UUID string
  1780. Device string
  1781. ModelName string
  1782. HostName string
  1783. }
  1784. func DecodeDCGMDeviceInfoResult(result *QueryResult) *DCGMDeviceInfoResult {
  1785. uuid, _ := result.GetString(UUIDLabel)
  1786. device, _ := result.GetString(DeviceLabel)
  1787. modelName, _ := result.GetString(ModelNameLabel)
  1788. hostName, _ := result.GetString(HostNameLabel)
  1789. return &DCGMDeviceInfoResult{
  1790. UUID: uuid,
  1791. Device: device,
  1792. ModelName: modelName,
  1793. HostName: hostName,
  1794. }
  1795. }
  1796. type DCGMDeviceUptimeResult struct {
  1797. UUID string
  1798. First time.Time
  1799. Last time.Time
  1800. }
  1801. func (res *DCGMDeviceUptimeResult) GetStartEnd(windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
  1802. return getStartEnd(res.First, res.Last, windowStart, windowEnd, resolution)
  1803. }
  1804. func getStartEnd(first, last, windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
  1805. // The only corner-case here is what to do if you only get one timestamp.
  1806. // This dilemma still requires the use of the resolution, and can be
  1807. // clamped using the window. In this case, we want to honor the existence
  1808. // of the pod by giving "one resolution" worth of duration, half on each
  1809. // side of the given timestamp.
  1810. if first.Equal(last) {
  1811. first = first.Add(-1 * resolution / time.Duration(2))
  1812. last = last.Add(resolution / time.Duration(2))
  1813. }
  1814. if first.Before(windowStart) {
  1815. first = windowStart
  1816. }
  1817. if last.After(windowEnd) {
  1818. last = windowEnd
  1819. }
  1820. // prevent end times in the future
  1821. now := time.Now().UTC()
  1822. if last.After(now) {
  1823. last = now
  1824. }
  1825. return first, last
  1826. }
  1827. func DecodeDCGMDeviceUptimeResult(result *QueryResult) *DCGMDeviceUptimeResult {
  1828. uuid, _ := result.GetString(UUIDLabel)
  1829. first := time.Unix(int64(result.Values[0].Timestamp), 0).UTC()
  1830. last := time.Unix(int64(result.Values[len(result.Values)-1].Timestamp), 0).UTC()
  1831. return &DCGMDeviceUptimeResult{
  1832. UUID: uuid,
  1833. First: first,
  1834. Last: last,
  1835. }
  1836. }
  1837. type DCGMDeviceContainerUsageResult struct {
  1838. UUID string
  1839. PodUID string
  1840. Container string
  1841. Value float64
  1842. }
  1843. func DecodeDCGMDeviceContainerUsageResult(result *QueryResult) *DCGMDeviceContainerUsageResult {
  1844. uuid, _ := result.GetString(UUIDLabel)
  1845. podUID, _ := result.GetString(PodUIDLabel)
  1846. container, _ := result.GetString(ContainerLabel)
  1847. var value float64
  1848. if len(result.Values) > 0 {
  1849. value = result.Values[0].Value
  1850. } else {
  1851. log.Warnf("Error decoding DCGM Device Container Usage Result for device '%s': empty value returned", uuid)
  1852. }
  1853. return &DCGMDeviceContainerUsageResult{
  1854. UUID: uuid,
  1855. PodUID: podUID,
  1856. Container: container,
  1857. Value: value,
  1858. }
  1859. }
  1860. // Inference Metrics Decoders
  1861. func DecodeInferenceTokensResult(result *QueryResult) *InferenceTokensResult {
  1862. modelName, _ := result.GetString("model_name")
  1863. namespace, _ := result.GetString("namespace")
  1864. key := modelName + ":" + namespace
  1865. // Get the value from the last vector point if available
  1866. var value float64
  1867. if len(result.Values) > 0 {
  1868. value = result.Values[len(result.Values)-1].Value
  1869. }
  1870. return &InferenceTokensResult{
  1871. Values: map[string]float64{
  1872. key: value,
  1873. },
  1874. }
  1875. }
  1876. func DecodeInferenceProcessingTimeResult(result *QueryResult) *InferenceProcessingTimeResult {
  1877. modelName, _ := result.GetString("model_name")
  1878. namespace, _ := result.GetString("namespace")
  1879. key := modelName + ":" + namespace
  1880. // Get the value from the last vector point if available
  1881. var value float64
  1882. if len(result.Values) > 0 {
  1883. value = result.Values[len(result.Values)-1].Value
  1884. }
  1885. return &InferenceProcessingTimeResult{
  1886. Values: map[string]float64{
  1887. key: value,
  1888. },
  1889. }
  1890. }
  1891. func DecodeInferenceCacheConfigResult(result *QueryResult) *InferenceCacheConfigResult {
  1892. modelName, _ := result.GetString("model_name")
  1893. namespace, _ := result.GetString("namespace")
  1894. key := modelName + ":" + namespace
  1895. // Get the value from the last vector point if available
  1896. var prefixCachingEnabled float64
  1897. if len(result.Values) > 0 {
  1898. prefixCachingEnabled = result.Values[len(result.Values)-1].Value
  1899. }
  1900. return &InferenceCacheConfigResult{
  1901. Configs: map[string]*InferenceCacheConfig{
  1902. key: {
  1903. PrefixCachingEnabled: prefixCachingEnabled > 0,
  1904. },
  1905. },
  1906. }
  1907. }
  1908. func DecodeAll[T any](results []*QueryResult, decode ResultDecoder[T]) []*T {
  1909. decoded := make([]*T, 0, len(results))
  1910. for _, result := range results {
  1911. decoded = append(decoded, decode(result))
  1912. }
  1913. return decoded
  1914. }