github.com/kubewharf/katalyst-core@v0.5.3/pkg/custom-metric/store/data/const.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package data 18 19 import ( 20 "sync" 21 22 "k8s.io/apimachinery/pkg/runtime/schema" 23 ) 24 25 type CustomMetricLabelKey string 26 27 // those const variables define the standard semantics of metric labels 28 // 29 // CustomMetricLabelKeyNamespace defines the namespace; 30 // CustomMetricLabelKeyObject defines the standard kubernetes objects; 31 // CustomMetricLabelKeyObjectName defines the name of kubernetes objects; 32 // CustomMetricLabelKeyTimestamp defines the timestamp of this metric; 33 // CustomMetricLabelSelectorPrefixKey nominates those labels that should be used as selector; 34 const ( 35 CustomMetricLabelKeyNamespace CustomMetricLabelKey = "namespace" 36 CustomMetricLabelKeyObject CustomMetricLabelKey = "object" 37 CustomMetricLabelKeyObjectName CustomMetricLabelKey = "object_name" 38 CustomMetricLabelKeyTimestamp CustomMetricLabelKey = "timestamp" 39 CustomMetricLabelSelectorPrefixKey CustomMetricLabelKey = "selector_" 40 ) 41 42 // SupportedMetricObject defines those kubernetes objects/CRDs that are supported, 43 // the mapped values indicate the GVR for the corresponding objects/CRDs 44 // this cab be set only once 45 var supportedMetricObject = map[string]schema.GroupVersionResource{ 46 "nodes": {Version: "v1", Resource: "nodes"}, 47 "pods": {Version: "v1", Resource: "pods"}, 48 } 49 50 var supportedMetricObjectSettingOnce = sync.Once{} 51 52 func AppendSupportedMetricObject(supported map[string]schema.GroupVersionResource) { 53 supportedMetricObjectSettingOnce.Do(func() { 54 for k, v := range supported { 55 supportedMetricObject[k] = v 56 } 57 }) 58 } 59 60 func GetSupportedMetricObject() map[string]schema.GroupVersionResource { 61 return supportedMetricObject 62 } 63 64 type MetricData struct { 65 Data float64 `json:"data,omitempty"` 66 Timestamp int64 `json:"timestamp,omitempty"` 67 } 68 69 type MetricSeries struct { 70 Name string `json:"name,omitempty"` 71 Labels map[string]string `json:"labels,omitempty"` 72 Series []*MetricData `json:"series,omitempty"` 73 }