github.com/polarismesh/polaris@v1.17.8/service/healthcheck/config.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package healthcheck 19 20 import ( 21 "time" 22 23 "github.com/polarismesh/polaris/plugin" 24 ) 25 26 // Config 健康检查配置 27 type Config struct { 28 Open bool `yaml:"open"` 29 Service string `yaml:"service"` 30 SlotNum int `yaml:"slotNum"` 31 LocalHost string `yaml:"localHost"` 32 MinCheckInterval time.Duration `yaml:"minCheckInterval"` 33 MaxCheckInterval time.Duration `yaml:"maxCheckInterval"` 34 ClientCheckInterval time.Duration `yaml:"clientCheckInterval"` 35 ClientCheckTtl time.Duration `yaml:"clientCheckTtl"` 36 Checkers []plugin.ConfigEntry `yaml:"checkers"` 37 Batch map[string]interface{} `yaml:"batch"` 38 } 39 40 const ( 41 defaultMinCheckInterval = 1 * time.Second 42 defaultMaxCheckInterval = 30 * time.Second 43 defaultSlotNum = 30 44 defaultClientReportTtl = 120 * time.Second 45 defaultClientCheckInterval = 120 * time.Second 46 ) 47 48 // SetDefault 设置默认值 49 func (c *Config) SetDefault() { 50 if len(c.Service) == 0 { 51 c.Service = "polaris.checker" 52 } 53 if c.SlotNum == 0 { 54 c.SlotNum = defaultSlotNum 55 } 56 if c.MinCheckInterval == 0 { 57 c.MinCheckInterval = defaultMinCheckInterval 58 } 59 if c.MaxCheckInterval == 0 { 60 c.MaxCheckInterval = defaultMaxCheckInterval 61 } 62 if c.MinCheckInterval > c.MaxCheckInterval { 63 c.MinCheckInterval = defaultMinCheckInterval 64 c.MaxCheckInterval = defaultMaxCheckInterval 65 } 66 if c.ClientCheckInterval == 0 { 67 c.ClientCheckInterval = defaultClientCheckInterval 68 } 69 if c.ClientCheckTtl == 0 { 70 c.ClientCheckTtl = defaultClientReportTtl 71 } 72 }