config_common.go 2.8 KB
Newer Older
Z
zhj-luo 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * Copyright (c) 2023 OceanBase
 * OCP Express is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

W
wangzelin.wzl 已提交
13 14
package config

O
ob-robot 已提交
15 16 17
import (
	"strconv"
	"time"
W
wangzelin.wzl 已提交
18

O
ob-robot 已提交
19 20
	"github.com/oceanbase/obagent/lib/crypto"
)
W
wangzelin.wzl 已提交
21

O
ob-robot 已提交
22 23 24 25 26 27 28
var (
	CurProcess     Process
	AgentVersion   string
	Mode           AgentMode = ReleaseMode
	BuildEpoch     string
	BuildGoVersion string
)
W
wangzelin.wzl 已提交
29

O
ob-robot 已提交
30 31 32 33 34
var (
	GitBranch        string
	GitCommitId      string
	GitShortCommitId string
	GitCommitTime    string
W
wangzelin.wzl 已提交
35 36 37 38
)

type AgentMode = string

O
ob-robot 已提交
39 40 41 42 43
const (
	DebugMode   AgentMode = "debug"
	ReleaseMode AgentMode = "release"
)

W
wangzelin.wzl 已提交
44 45 46
type Process = string

const (
O
ob-robot 已提交
47 48 49
	ProcessManagerAgent Process = "ob_mgragent"
	ProcessMonitorAgent Process = "ob_monagent"
	ProcessAgentCtl     Process = "ob_agentctl"
W
wangzelin.wzl 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
)

type InstallConfig struct {
	Path string `yaml:"path"`
}

type LogConfig struct {
	// log level
	Level string `yaml:"level"`
	// log filename
	Filename string `yaml:"filename"`
	// maxsize of log file
	MaxSize int `yaml:"maxsize"`
	// maxage of log file
	MaxAge int `yaml:"maxage"`
	// max backups of log files
	MaxBackups int  `yaml:"maxbackups"`
	LocalTime  bool `yaml:"localtime"`
	// compress log file
	Compress bool `yaml:"compress"`
}

// Log log wrapper
type Log struct {
	Log LogConfig `yaml:"log"`
}

type SDKConfig struct {
	ConfigPropertiesDir string              `yaml:"configPropertiesDir"`
	ModuleConfigDir     string              `yaml:"moduleConfigDir"`
	CryptoPath          string              `yaml:"cryptoPath"`
	CryptoMethod        crypto.CryptoMethod `yaml:"cryptoMethod"`
}

O
ob-robot 已提交
84 85 86 87 88
type ShellfConfig struct {
	// shell template config file path
	TemplatePath string `yaml:"template"`
}

W
wangzelin.wzl 已提交
89
type BasicAuthConfig struct {
O
ob-robot 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
	Auth              string `yaml:"auth"`
	MetricAuthEnabled bool   `yaml:"metricAuthEnabled"`
	Username          string `yaml:"username"`
	Password          string `yaml:"password"`
}

func GetAgentInfo() map[string]interface{} {
	var infoMap = map[string]interface{}{
		"name":           CurProcess,
		"version":        AgentVersion,
		"mode":           Mode,
		"buildGoVersion": BuildGoVersion,
	}
	if epoch, err := strconv.Atoi(BuildEpoch); err == nil {
		buildTime := time.Unix(int64(epoch), 0)
		infoMap["buildTime"] = buildTime
	}
	return infoMap
}

func GetGitInfo() map[string]interface{} {
	return map[string]interface{}{
		"branch":        GitBranch,
		"commitId":      GitCommitId,
		"shortCommitId": GitShortCommitId,
		"commitTime":    GitCommitTime,
	}
W
wangzelin.wzl 已提交
117
}