github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/utils/nodeinfoutils.go (about)

     1  /*
     2  Copyright 2023.
     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 utils
    18  
    19  type NodeInfo struct {
    20  	IP                         string `json:"ip"`
    21  	BuildHash                  string `json:"build_hash"`
    22  	TotalIndexingBuffer        int64  `json:"total_indexing_buffer"`
    23  	TotalIndexingBufferInBytes string `json:"total_indexing_buffer_in_bytes"`
    24  	Version                    string `json:"version"`
    25  	HttpPublishAddress         string `json:"http.publish_address"`
    26  }
    27  
    28  type IndexInfo struct {
    29  	Name            string `json:"index"`
    30  	Health          string `json:"health"`
    31  	Status          string `json:"status"`
    32  	UUID            string `json:"uuid"`
    33  	Rep             int    `json:"rep"`
    34  	Pri             uint64 `json:"pri"`
    35  	DocsDeleted     int    `json:"docs.deleted"`
    36  	DocsCount       int    `json:"docs.count"`
    37  	StoreSize       uint64 `json:"store.size"`
    38  	OnDiskStoreSize uint64 `json:"store.onDiskBytes"`
    39  	PriStoreSize    uint64 `json:"pri.store.size"`
    40  }
    41  
    42  type NodeStatusEnum int
    43  
    44  const (
    45  	GREEN NodeStatusEnum = iota
    46  	YELLOW
    47  	RED
    48  	UNKNOWN_NODESTATUS
    49  )
    50  
    51  func (s NodeStatusEnum) String() string {
    52  	switch s {
    53  	case GREEN:
    54  		return "GREEN"
    55  	case YELLOW:
    56  		return "YELLOW"
    57  	case RED:
    58  		return "RED"
    59  
    60  	default:
    61  		return "UNKNOWN_NODESTATUS"
    62  	}
    63  }
    64  
    65  type NodeTypeEnum int
    66  
    67  const (
    68  	INGEST NodeTypeEnum = iota
    69  	QUERY
    70  	SEED
    71  	SEGREADER
    72  	METAREADER
    73  )
    74  
    75  func (s NodeTypeEnum) String() string {
    76  	switch s {
    77  	case INGEST:
    78  		return "INGEST"
    79  	case QUERY:
    80  		return "QUERY"
    81  	case SEED:
    82  		return "SEED"
    83  	case SEGREADER:
    84  		return "SEGREADER"
    85  	case METAREADER:
    86  		return "METAREADER"
    87  
    88  	default:
    89  		return "UNKNOWN_NODETYPE"
    90  	}
    91  }
    92  
    93  type ClusterNode struct {
    94  	NodeIP     string         `json:"NodeIp"`
    95  	RaftPort   string         `json:"RaftPort"`
    96  	GRPCPort   string         `json:"GRPCPort"`
    97  	NodeTypes  []NodeTypeEnum `json:"NodeTypes"`
    98  	NodeStatus string         `json:"NodeStatus"`
    99  }
   100  
   101  type ClusterNodeStr struct {
   102  	NodeIP     string   `json:"NodeIp"`
   103  	RaftPort   string   `json:"RaftPort"`
   104  	GRPCPort   string   `json:"GRPCPort"`
   105  	NodeTypes  []string `json:"NodeTypes"`
   106  	NodeStatus string   `json:"NodeStatus"`
   107  }
   108  
   109  type MemberInfo struct {
   110  	ClusterId      uint64                     `json:"ClusterId"`
   111  	ConfigChangeId uint64                     `json:"ConfigChangeId"`
   112  	Nodes          map[uint64]*ClusterNodeStr `json:"ClusterNode"`
   113  	Observers      map[uint64]string          `json:"Observers"`
   114  	Witnesses      map[uint64]string          `json:"Witnesses"`
   115  	Removed        map[uint64]struct{}        `json:"Removed"`
   116  	LeaderId       uint64                     `json:"LeaderId"`
   117  	LeaderValid    bool                       `json:"LeaderValid"`
   118  }
   119  
   120  func NewNodeInfo(esVersion string) *NodeInfo {
   121  	return &NodeInfo{
   122  		IP:                         "127.0.0.1",
   123  		BuildHash:                  "123456",
   124  		TotalIndexingBuffer:        123456,
   125  		TotalIndexingBufferInBytes: "123456",
   126  		// todo get this version from config
   127  		Version:            esVersion,
   128  		HttpPublishAddress: "127.0.0.1:8081",
   129  	}
   130  }
   131  
   132  func GetAllNodesInfo(hostname string, esVersion string) map[string]*NodeInfo {
   133  
   134  	allNodesInfo := make(map[string]*NodeInfo)
   135  	allNodesInfo[hostname] = NewNodeInfo(esVersion)
   136  	return allNodesInfo
   137  }
   138  
   139  func CreateIndexInfo(name string, uuid string, docsCount int, storeSize uint64, onDiskBytesCount uint64) *IndexInfo {
   140  	// TODO: Implement docsCount & storeSize
   141  
   142  	// constant values:
   143  	health := "green"
   144  	docs_deleted := 0
   145  	status := ""
   146  	rep := 0
   147  
   148  	return &IndexInfo{
   149  		Name:            name,
   150  		Health:          health,
   151  		UUID:            uuid,
   152  		Status:          status,
   153  		Pri:             1,
   154  		Rep:             rep,
   155  		DocsCount:       docsCount,
   156  		DocsDeleted:     docs_deleted,
   157  		StoreSize:       storeSize,
   158  		OnDiskStoreSize: onDiskBytesCount,
   159  		PriStoreSize:    storeSize,
   160  	}
   161  }