models

package
v0.0.0-...-c38d673 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 一切正常
	ErrNothing = "L200"

	// 单机版 Runner 操作
	ErrConfigName     = "L1001"
	ErrRunnerAdd      = "L1002"
	ErrRunnerDelete   = "L1003"
	ErrRunnerStart    = "L1004"
	ErrRunnerStop     = "L1005"
	ErrRunnerReset    = "L1006"
	ErrRunnerUpdate   = "L1007"
	ErrRunnerErrorGet = "L1008"

	// read 相关
	ErrReadRead = "L1101"
	// parse 相关
	ErrParseParse = "L1201"
	// transform 相关
	ErrTransformTransform = "L1301"
	// send 相关
	ErrSendSend = "L1401"

	// 集群版 master API
	ErrClusterSlaves   = "L2001"
	ErrClusterStatus   = "L2002"
	ErrClusterConfigs  = "L2003"
	ErrClusterRegister = "L2004"
	ErrClusterConfig   = "L2014"

	// 集群版 slave API
	ErrClusterTag = "L2005"

	// 集群版 master 对 slaves 的操作
	ErrClusterRunnerAdd    = "L2006"
	ErrClusterRunnerDelete = "L2007"
	ErrClusterRunnerStart  = "L2008"
	ErrClusterRunnerStop   = "L2009"
	ErrClusterRunnerReset  = "L2010"
	ErrClusterRunnerUpdate = "L2011"
	ErrClusterSlavesDelete = "L2012"
	ErrClusterSlavesTag    = "L2013"
)
View Source
const (
	B = 1 << (iota * 10)
	KB
	MB
	GB
)
View Source
const (
	GlobalKeyName = "name"
	ExtraInfo     = "extra_info"

	KeyCore     = "core"
	KeyHostName = "hostname"
	KeyOsInfo   = "osinfo"
	KeyLocalIp  = "localip"

	ContentTypeHeader     = "Content-Type"
	ContentEncodingHeader = "Content-Encoding"

	ApplicationJson = "application/json"
	TestPlain       = "text/plain"
	ApplicationGzip = "application/gzip"

	KeyPandoraStash      = "pandora_stash"       // 当只有一条数据且 sendError 时候,将其转化为 raw 发送到 pandora_stash 这个字段
	KeyPandoraSeparateId = "pandora_separate_id" // 当一条数据大于2M且 sendError 时候,将其切片,切片记录到 pandora_separate_id 这个字段
	TypeIP               = "ip"                  // schema ip

	SchemaFreeTokensPrefix = "schema_free_tokens_"
	LogDBTokensPrefix      = "logdb_tokens_"
	TsDBTokensPrefix       = "tsdb_tokens_"
	KodoTokensPrefix       = "kodo_tokens_"

	KeyRunnerName = "runner_name"

	DefaultDirPerm  = 0755
	DefaultFilePerm = 0600

	DefaultMaxBatchSize = 2 * MB

	DefaultTruncateMaxSize = 1024

	DefaultErrorsListCap = 100

	PipeLineError = "ErrorMessage="

	Text        = "text"
	Checkbox    = "checkbox"
	Radio       = "radio"
	InputNumber = "inputNumber"
)

Variables

View Source
var (
	ErrNotSupport  = errors.New("runner does not support")
	ErrNotExist    = errors.New("runner does not exist")
	ErrQueueClosed = errors.New("queue is closed")
)
View Source
var (
	MaxProcs                    = 1
	NumCPU                      = runtime.NumCPU()
	LogkitAutoCreateDescription = "由logkit日志收集自动创建"
	MetricAutoCreateDescription = "由logkit监控收集自动创建"
)
View Source
var ErrorCodeHumanize = map[string]string{
	ErrNothing: "操作成功",

	ErrConfigName:   "获取 Config 出现错误",
	ErrRunnerAdd:    "添加 Runner 出现错误",
	ErrRunnerDelete: "删除 Runner 出现错误",
	ErrRunnerStart:  "开启 Runner 出现错误",
	ErrRunnerStop:   "关闭 Runner 出现错误",
	ErrRunnerReset:  "重置 Runner 出现错误",
	ErrRunnerUpdate: "更新 Runner 出现错误",

	ErrParseParse: "解析字符串失败",

	ErrTransformTransform: "转化字段失败",

	ErrClusterSlaves:   "获取 Slaves 列表出现错误",
	ErrClusterStatus:   "获取 Slaves 状态出现错误",
	ErrClusterConfig:   "获取 Slaves Config 出现错误",
	ErrClusterConfigs:  "获取 Slaves Configs 出现错误",
	ErrClusterRegister: "接受 Slaves 注册出现错误",

	ErrClusterTag: "更改 Tag 出现错误",

	ErrClusterRunnerAdd:    "Slaves 添加 Runner 出现错误",
	ErrClusterRunnerDelete: "Slaves 删除 Runner 出现错误",
	ErrClusterRunnerStart:  "Slaves 启动 Runner 出现错误",
	ErrClusterRunnerStop:   "Slaves 关闭 Runner 出现错误",
	ErrClusterRunnerReset:  "Slaves 重置 Runner 出现错误",
	ErrClusterRunnerUpdate: "Slaves 更新 Runner 出现错误",
	ErrClusterSlavesDelete: "Slaves 从列表中移除时出现错误",
	ErrClusterSlavesTag:    "Slaves 更改 Tag 出现错误",
}

Functions

func AddHttpProtocal

func AddHttpProtocal(url string) string

func Bool2String

func Bool2String(i bool) string

func CheckErr

func CheckErr(err error) error

func CheckFileMode

func CheckFileMode(path string, fileMode os.FileMode) error

func CheckPandoraKey

func CheckPandoraKey(key string) bool

为了提升性能做的一个预先检查,避免CPU浪费

func ConvertDate

func ConvertDate(layoutBefore, layoutAfter string, offset int, loc *time.Location, v interface{}) (interface{}, error)

func CreateDirIfNotExist

func CreateDirIfNotExist(dir string) (err error)

CreateDirIfNotExist 检查文件夹,不存在时创建

func DecodeString

func DecodeString(target string) (result string, err error)

func DecompressTarGzip

func DecompressTarGzip(srcPath, dstPath, targetFile string) (targetDir string, _ error)

DecompressTarGzip 将 TAR.GZ 格式的文件解包到指定目录并返回指定文件所在的解包后的目录, 如果存在多个同名指定文件,则返回第一个找到的目录

func DecompressZip

func DecompressZip(srcPath, dstPath, targetFile string) (targetDir string, _ error)

DecompressZip 将 ZIP 格式的文件解包到指定目录并返回指定文件所在的解包后的目录, 如果存在多个同名指定文件,则返回第一个找到的目录

func DeepConvertKey

func DeepConvertKey(data map[string]interface{}) map[string]interface{}

func DeepConvertKeyWithCache

func DeepConvertKeyWithCache(data map[string]interface{}, cache map[string]KeyInfo) map[string]interface{}

注意:cache如果是nil,这个函数就完全没有意义,不如调用 DeepConvertKey

func DeleteMapValue

func DeleteMapValue(m map[string]interface{}, keys ...string) (interface{}, bool)

通过层级key删除key-val,并返回被删除的val,是否删除成功 如果key不存在,则返回 nil,false

func EncodeString

func EncodeString(target string) (result string)

func ExtractField

func ExtractField(slice []string) ([]string, error)

func FormatWithUserOption

func FormatWithUserOption(layoutAfter string, offset int, t time.Time) interface{}

func GetEnv

func GetEnv(env string) string

parse ${ENV} to ENV get ENV value from os

func GetKeys

func GetKeys(keyStr string) []string

根据key字符串,拆分出层级keys数据

func GetMapList

func GetMapList(data string) map[string]string

func GetMapValue

func GetMapValue(m map[string]interface{}, keys ...string) (interface{}, error)

通过层级key获取value. 所有层级的map必须为 map[string]interface{} 类型. keys为空切片,返回原m

func GetRealPath

func GetRealPath(path string) (newPath string, fi os.FileInfo, err error)

GetRealPath 处理软链接等,找到文件真实路径

func Hash

func Hash(s string) string

func IsJsonString

func IsJsonString(s string) bool

func IsNotExist

func IsNotExist(err error) bool

func IsNotSupport

func IsNotSupport(err error) bool

func LogDirAndPattern

func LogDirAndPattern(logpath string) (dir, pattern string, err error)

创建目录,并返回日志模式

func ModTimeLater

func ModTimeLater(f1, f2 os.FileInfo) bool

ModTimeLater 按最后修改时间进行比较

func PandoraKey

func PandoraKey(key string) (string, bool)

判断时只有数字和字母为合法字符,规则: 1. 首字符为数字时,增加首字符 "K" 2. 首字符为非法字符时,去掉首字符(例如,如果字符串全为非法字符,则转换后为空) 3. 非首字符并且为非法字符时,使用 "_" 替代非法字符

func PickMapValue

func PickMapValue(m map[string]interface{}, pick map[string]interface{}, keys ...string)

func ReadDirByTime

func ReadDirByTime(dir string) (files []os.FileInfo, err error)

ReadDirByTime 读取文件目录后按时间排序,时间最新的文件在前

func ReadFileContent

func ReadFileContent(path string) (content []string, err error)

func RemoveHttpProtocal

func RemoveHttpProtocal(url string) (hostport, schema string)

func SetMapValue

func SetMapValue(m map[string]interface{}, val interface{}, coercive bool, keys ...string) error

通过层级key设置value值. 如果key不存在,将会自动创建. 当coercive为true时,会强制将非map[string]interface{}类型替换为map[string]interface{}类型,有可能导致数据丢失

func SetMapValueExistWithPrefix

func SetMapValueExistWithPrefix(m map[string]interface{}, val interface{}, prefix string, keys ...string) error

通过层级key设置value值, 如果keys不存在则不加前缀,否则加前缀

func SortFilesByTime

func SortFilesByTime(files FileInfos) (soredfiles []os.FileInfo)

SortFilesByTime 按照文件更新的unixnano从大到小排,即最新的文件在前,相同时间的则按照文件名字典序,字典序在后面的排在前面

func TrimeList

func TrimeList(strs []string) (ret []string)

func TruncateStrSize

func TruncateStrSize(err string, size int) string

func TuoDecode

func TuoDecode(value []byte) (values [][]byte, err error)

TuoDecode 按照 TuoEncode的压缩算法解压,还原出[]byte数组。

func TuoEncode

func TuoEncode(values []sql.RawBytes) (ret []byte)

TuoEncode 把[]byte数组按照长度拼接到一起,每个sql.RawBytes之间间隔4个byte用于存储长度。

Types

type AuthTokens

type AuthTokens struct {
	RunnerName   string
	SenderIndex  int
	SenderTokens conf.MapConf
}

type Data

type Data map[string]interface{}

Data store as use key/value map

type ErrorInfo

type ErrorInfo struct {
	Error     string `json:"error"`
	Timestamp int64  `json:"timestamp"`
	Count     int64  `json:"count"`
}

type ErrorQueue

type ErrorQueue struct {
	ErrorSlice []ErrorInfo `json:"error_slice"`
	Front      int         `json:"front"`
	Rear       int         `json:"rear"`
	MaxSize    int         `json:"max_size"`
	// contains filtered or unexported fields
}

func NewErrorQueue

func NewErrorQueue(maxSize int) *ErrorQueue

func (*ErrorQueue) Append

func (queue *ErrorQueue) Append(errors []ErrorInfo)

向队列中添加元素

func (*ErrorQueue) Copy

func (queue *ErrorQueue) Copy(e ErrorInfo)

将另一个queue复制到当前queue中

func (*ErrorQueue) CopyQueue

func (queue *ErrorQueue) CopyQueue(src *ErrorQueue)

将另一个queue复制到当前queue中

func (*ErrorQueue) EqualLast

func (queue *ErrorQueue) EqualLast(e ErrorInfo) bool

向队列中添加元素

func (*ErrorQueue) Get

func (queue *ErrorQueue) Get() ErrorInfo

获取队列中最后一个元素

func (*ErrorQueue) GetErrorSlice

func (queue *ErrorQueue) GetErrorSlice(front, rear int) []ErrorInfo

获取 queue 中 front rear之间的数据

func (*ErrorQueue) GetMaxSize

func (queue *ErrorQueue) GetMaxSize() int

返回队列实际容量

func (*ErrorQueue) IsEmpty

func (queue *ErrorQueue) IsEmpty() bool

func (*ErrorQueue) Put

func (queue *ErrorQueue) Put(e ErrorInfo)

向队列中添加单个元素

func (*ErrorQueue) Set

func (queue *ErrorQueue) Set(index int, e ErrorInfo)

将另一个queue复制到当前queue中

func (*ErrorQueue) Size

func (queue *ErrorQueue) Size() int

func (*ErrorQueue) Sort

func (queue *ErrorQueue) Sort() []ErrorInfo

按进出顺序复制到数组中

type ErrorResponse

type ErrorResponse struct {
	Error error `json:"error"`
}

func NewErrorResponse

func NewErrorResponse(err error) *ErrorResponse

type File

type File struct {
	Info os.FileInfo
	Path string
}

func GetLogFiles

func GetLogFiles(doneFilePath string) (files []File)

type FileInfos

type FileInfos []os.FileInfo

FileInfos attaches the methods of Interface to []int64, sorting in decreasing order.

func (FileInfos) Len

func (p FileInfos) Len() int

func (FileInfos) Less

func (p FileInfos) Less(i, j int) bool

func (FileInfos) Sort

func (p FileInfos) Sort()

Sort is a convenience method.

func (FileInfos) Swap

func (p FileInfos) Swap(i, j int)

type HashSet

type HashSet struct {
	// contains filtered or unexported fields
}

func NewHashSet

func NewHashSet() *HashSet

func (*HashSet) Add

func (s *HashSet) Add(ele interface{})

func (*HashSet) AddStringArray

func (s *HashSet) AddStringArray(ele []string)

func (*HashSet) Clear

func (s *HashSet) Clear()

func (*HashSet) Elements

func (s *HashSet) Elements() []interface{}

func (*HashSet) IsEmpty

func (s *HashSet) IsEmpty() bool

func (*HashSet) IsIn

func (s *HashSet) IsIn(ele interface{}) bool

func (*HashSet) Len

func (s *HashSet) Len() int

func (*HashSet) Remove

func (s *HashSet) Remove(ele interface{})

type KeyInfo

type KeyInfo struct {
	Valid  bool
	NewKey string
}

type KeyValue

type KeyValue struct {
	Key     string `json:"key"`
	Value   string `json:"value"`
	SortKey string `json:"sort_key"`
}

type KeyValueSlice

type KeyValueSlice []KeyValue

func (KeyValueSlice) Len

func (slice KeyValueSlice) Len() int

func (KeyValueSlice) Less

func (slice KeyValueSlice) Less(i, j int) bool

func (KeyValueSlice) Swap

func (slice KeyValueSlice) Swap(i, j int)

type LagInfo

type LagInfo struct {
	Size     int64  `json:"size"`
	SizeUnit string `json:"sizeunit"`
	Ftlags   int64  `json:"ftlags"`
	Total    int64  `json:"total"`
}

type Option

type Option struct {
	KeyName            string
	ChooseOnly         bool
	Element            string // 前端显示类型
	ChooseOptions      []interface{}
	Default            interface{}
	DefaultNoUse       bool // 是否使用默认值,true为不使用默认值,false为使用默认值
	Description        string
	CheckRegex         string
	Style              string `json:"style"`
	Required           bool   `json:"required"` // 是否必填
	Placeholder        string `json:"placeholder"`
	Type               string `json:"Type,omitempty"`
	Secret             bool
	Advance            bool        `json:"advance,omitempty"`
	AdvanceDepend      string      `json:"advance_depend,omitempty"`
	AdvanceDependValue interface{} `json:"advance_depend_value,omitempty"`
	ToolTip            string      `json:"tooltip,omitempty"` // 该选项说明
}

type Resetable

type Resetable interface {
	Reset() error
}

type SchemaErr

type SchemaErr struct {
	Number int64
	Last   time.Time
}

func (*SchemaErr) Output

func (s *SchemaErr) Output(count int64, err error)

type StatsError

type StatsError struct {
	StatsInfo
	ErrorDetail         error `json:"error"`
	Ft                  bool  `json:"-"`
	FtNotRetry          bool  `json:"-"`
	DatasourceSkipIndex []int
	RemainDatas         []Data
}

func (*StatsError) AddErrors

func (se *StatsError) AddErrors()

func (*StatsError) AddErrorsNum

func (se *StatsError) AddErrorsNum(n int)

func (*StatsError) AddSuccess

func (se *StatsError) AddSuccess()

func (*StatsError) AddSuccessNum

func (se *StatsError) AddSuccessNum(n int)

func (*StatsError) Error

func (se *StatsError) Error() string

func (*StatsError) ErrorIndexIn

func (se *StatsError) ErrorIndexIn(idx int) bool

type StatsInfo

type StatsInfo struct {
	Errors     int64   `json:"errors"`
	Success    int64   `json:"success"`
	Speed      float64 `json:"speed"`
	Trend      string  `json:"trend"`
	LastError  string  `json:"last_error"`
	FtQueueLag int64   `json:"-"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL