decoders.go 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163
  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. func DecodeDCGMDeviceContainerUsageResult(result *QueryResult) *DCGMDeviceContainerUsageResult {
  1822. uuid, _ := result.GetString(UUIDLabel)
  1823. podUID, _ := result.GetString(PodUIDLabel)
  1824. container, _ := result.GetString(ContainerLabel)
  1825. var value float64
  1826. if len(result.Values) > 0 {
  1827. value = result.Values[0].Value
  1828. } else {
  1829. log.Warnf("Error decoding DCGM Device Container Udage Result for device '%s': empty value returned", uuid)
  1830. }
  1831. return &DCGMDeviceContainerUsageResult{
  1832. UUID: uuid,
  1833. PodUID: podUID,
  1834. Container: container,
  1835. Value: value,
  1836. }
  1837. }
  1838. func DecodeAll[T any](results []*QueryResult, decode ResultDecoder[T]) []*T {
  1839. decoded := make([]*T, 0, len(results))
  1840. for _, result := range results {
  1841. decoded = append(decoded, decode(result))
  1842. }
  1843. return decoded
  1844. }