decoders.go 54 KB

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