Skip to content

Commit

Permalink
bcs-cluster-manager支持腾讯公有云CA (TencentBlueKing#1850)
Browse files Browse the repository at this point in the history
* feature: bcs-cluster-manager支持腾讯公有云CA
  • Loading branch information
evanlixin authored Jun 2, 2022
1 parent 3099c9c commit 42fa975
Show file tree
Hide file tree
Showing 82 changed files with 22,466 additions and 7,209 deletions.
11 changes: 11 additions & 0 deletions bcs-common/common/metric/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package metric

// NewMetricController metric controller
func NewMetricController(conf Config, healthFunc HealthFunc, metrics ...*MetricContructor) error {
return newMetricHandler(conf, healthFunc, metrics...)
}
Expand All @@ -30,6 +31,7 @@ const (
UnknownRole RoleType = "unknown"
)

// Config xxx
type Config struct {
// name of your module
ModuleName string
Expand All @@ -54,8 +56,10 @@ type Config struct {
SvrKeyPwd string
}

// HealthFunc xxx
type HealthFunc func() HealthMeta

// HealthMeta xxx
type HealthMeta struct {
// the running role of your module when you are running with Master_Slave_Mode.
// must be not empty. if you set with an empty value, an error will be occurred.
Expand All @@ -68,6 +72,7 @@ type HealthMeta struct {
Message string `json:"message"`
}

// MetricMeta xxx
type MetricMeta struct {
// metric's name
Name string
Expand All @@ -77,13 +82,19 @@ type MetricMeta struct {
ConstLables map[string]string
}

// GetMetaFunc xxx
type GetMetaFunc func() *MetricMeta

// GetResultFunc xxx
type GetResultFunc func() (*MetricResult, error)

// MetricContructor xxx
type MetricContructor struct {
GetMeta GetMetaFunc
GetResult GetResultFunc
}

// MetricResult xxx
type MetricResult struct {
Value *FloatOrString
// variable labels means that this labels value can be changed with each call.
Expand Down
5 changes: 5 additions & 0 deletions bcs-common/common/metric/fake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func main() {
select {}
}

// DemoMetric xxx
type DemoMetric struct{}

// GetNumericMeta xxx
func (DemoMetric) GetNumericMeta() *metric.MetricMeta {
return &metric.MetricMeta{
Name: "timenow_seconds",
Expand All @@ -81,6 +83,7 @@ func (DemoMetric) GetNumericMeta() *metric.MetricMeta {
}
}

// GetNumericResult xxx
func (DemoMetric) GetNumericResult() (*metric.MetricResult, error) {
v, err := metric.FormFloatOrString(time.Now().Unix())
if err != nil {
Expand All @@ -94,6 +97,7 @@ func (DemoMetric) GetNumericResult() (*metric.MetricResult, error) {
}, nil
}

// GetStringMeta xxx
func (DemoMetric) GetStringMeta() *metric.MetricMeta {
return &metric.MetricMeta{
Name: "birthday_string",
Expand All @@ -104,6 +108,7 @@ func (DemoMetric) GetStringMeta() *metric.MetricMeta {
}
}

// GetStringResult xxx
func (DemoMetric) GetStringResult() (*metric.MetricResult, error) {
v, err := metric.FormFloatOrString(time.Now().String())
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions bcs-common/common/metric/floatOrStr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strconv"
)

// FormFloatOrString xxx
func FormFloatOrString(val interface{}) (*FloatOrString, error) {
valueof := reflect.ValueOf(val)
switch valueof.Kind() {
Expand All @@ -38,19 +39,22 @@ func FormFloatOrString(val interface{}) (*FloatOrString, error) {
}
}

// ValueType xxx
type ValueType string

const (
Float ValueType = "Float"
String ValueType = "String"
)

// FloatOrString xxx
type FloatOrString struct {
Type ValueType
Float float64
String string
}

// MarshalJSON marshalJson
func (fs FloatOrString) MarshalJSON() ([]byte, error) {
switch fs.Type {
case Float:
Expand All @@ -62,6 +66,7 @@ func (fs FloatOrString) MarshalJSON() ([]byte, error) {
}
}

// UnmarshalJSON unmarshalJSON
func (fs *FloatOrString) UnmarshalJSON(b []byte) error {
f, err := strconv.ParseFloat(string(b), 10)
if nil == err {
Expand Down
2 changes: 2 additions & 0 deletions bcs-common/common/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type MetricController struct {
Metrics []*MetricContructor
}

// Describe xxx
func (m MetricController) Describe(ch chan<- *prometheus.Desc) {
for _, metric := range m.Metrics {
blog.V(5).Infof("describe metric name- > %s\n", metric.GetMeta().Name)
Expand All @@ -61,6 +62,7 @@ func (m MetricController) Describe(ch chan<- *prometheus.Desc) {
newRuntimeMetric(m.Meta).Describe(ch)
}

// Collect xxx
func (m MetricController) Collect(ch chan<- prometheus.Metric) {
for _, metric := range m.Metrics {
blog.V(5).Infof("collect metric - > %s\n", metric.GetMeta().Name)
Expand Down
3 changes: 3 additions & 0 deletions bcs-common/common/metric/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
)

// MetaData struct
type MetaData struct {
Module string `json:"module"`
IP string `json:"ip"`
Expand All @@ -26,6 +27,7 @@ type MetaData struct {
Labels map[string]string `json:"label"`
}

// Valid xxx
func (m MetaData) Valid() error {
var errs []error
if len(m.Module) == 0 {
Expand All @@ -47,6 +49,7 @@ func (m MetaData) Valid() error {
return nil
}

// HealthInfo health info
type HealthInfo struct {
RunMode RunModeType `json:"runMode"`
Module string `json:"module"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $(SWAGGEROBJ):$(PROTO)

%.pb.go: %.proto
protoc -I../../third_party --proto_path=. --go_out=plugins=grpc:. --validate_out=lang=go:. $<
sed -i '' 's/json:"-"/json:"-" bson:"-"/g' clustermanager.pb.go
sed -i "" 's/json:"-"/json:"-" bson:"-"/g' clustermanager.pb.go

%.pb.gw.go: %.proto
protoc -I../../third_party --proto_path=. --micro_out=. \
Expand Down
Loading

0 comments on commit 42fa975

Please sign in to comment.