github.com/matrixorigin/matrixone@v1.2.0/pkg/util/status/hakeeper.go (about) 1 // Copyright 2021 -2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package status 16 17 import ( 18 "context" 19 "strings" 20 "time" 21 22 "github.com/matrixorigin/matrixone/pkg/logservice" 23 pb "github.com/matrixorigin/matrixone/pkg/pb/logservice" 24 "github.com/matrixorigin/matrixone/pkg/pb/metadata" 25 ) 26 27 type NodeStatus struct { 28 NodeID string `json:"node_id"` 29 NodeType string `json:"node_type"` 30 Address string `json:"address"` 31 Labels map[string]metadata.LabelList `json:"Labels"` 32 WorkState metadata.WorkState `json:"WorkState"` 33 Resource pb.Resource `json:"Resource"` 34 UpTime time.Time `json:"up_time"` 35 DownTime time.Time `json:"down_time"` 36 } 37 38 // HAKeeperStatus contains the status of HAKeeper. Currently, we 39 // focus on the uptime/downtime of nodes in HAKeeper. 40 type HAKeeperStatus struct { 41 Nodes []NodeStatus `json:"nodes"` 42 DeletedNodes []NodeStatus `json:"deleted_nodes"` 43 ErrMsg string `json:"err_msg"` 44 } 45 46 func (s *HAKeeperStatus) fill(client logservice.ClusterHAKeeperClient) { 47 if client == nil { 48 return 49 } 50 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) 51 defer cancel() 52 details, err := client.GetClusterDetails(ctx) 53 if err != nil { 54 s.ErrMsg = err.Error() 55 return 56 } 57 for _, cn := range details.CNStores { 58 var addr string 59 addrItems := strings.Split(cn.SQLAddress, ":") 60 if len(addrItems) > 1 { 61 addr = addrItems[0] 62 } 63 s.Nodes = append(s.Nodes, NodeStatus{ 64 NodeID: cn.UUID, 65 NodeType: "CN", 66 Address: addr, 67 Labels: cn.Labels, 68 WorkState: cn.WorkState, 69 Resource: cn.Resource, 70 UpTime: time.Unix(cn.UpTime/1e9, cn.UpTime%1e9), 71 }) 72 } 73 for _, deleted := range details.DeletedStores { 74 s.DeletedNodes = append(s.DeletedNodes, NodeStatus{ 75 NodeID: deleted.UUID, 76 NodeType: deleted.StoreType, 77 Address: deleted.Address, 78 UpTime: time.Unix(deleted.UpTime/1e9, deleted.UpTime%1e9), 79 DownTime: time.Unix(deleted.DownTime/1e9, deleted.DownTime%1e9), 80 }) 81 } 82 }