alils

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr. SLS).

For more description about SLS, please read this article: http://gitlab.alibaba-inc.com/sls/doc.

Index

Constants

View Source
const (
	// CacheSize set the flush size
	CacheSize int = 64
	// Delimiter define the topic delimiter
	Delimiter string = "##"
)
View Source
const (

	// OffsetNewest stands for the log head offset, i.e. the offset that will be
	// assigned to the next message that will be produced to the shard.
	OffsetNewest = "end"
	// OffsetOldest stands for the oldest offset available on the logstore for a
	// shard.
	OffsetOldest = "begin"
)

Variables

View Source
var (
	// ErrInvalidLengthLog invalid proto
	ErrInvalidLengthLog = fmt.Errorf("proto: negative length found during unmarshaling")
	// ErrIntOverflowLog overflow
	ErrIntOverflowLog = fmt.Errorf("proto: integer overflow")
)

Functions

func NewAliLS

func NewAliLS() logs.Logger

NewAliLS create a new Logger

Types

type Config

type Config struct {
	Project   string   `json:"project"`
	Endpoint  string   `json:"endpoint"`
	KeyID     string   `json:"key_id"`
	KeySecret string   `json:"key_secret"`
	LogStore  string   `json:"log_store"`
	Topics    []string `json:"topics"`
	Source    string   `json:"source"`
	Level     int      `json:"level"`
	FlushWhen int      `json:"flush_when"`
}

Config is the Config for Ali Log

type InputDetail

type InputDetail struct {
	LogType       string   `json:"logType"`
	LogPath       string   `json:"logPath"`
	FilePattern   string   `json:"filePattern"`
	LocalStorage  bool     `json:"localStorage"`
	TimeFormat    string   `json:"timeFormat"`
	LogBeginRegex string   `json:"logBeginRegex"`
	Regex         string   `json:"regex"`
	Keys          []string `json:"key"`
	FilterKeys    []string `json:"filterKey"`
	FilterRegex   []string `json:"filterRegex"`
	TopicFormat   string   `json:"topicFormat"`
}

InputDetail define log detail

type Log

type Log struct {
	Time            *uint32       `protobuf:"varint,1,req,name=Time" json:"Time,omitempty"`
	Contents        []*LogContent `protobuf:"bytes,2,rep,name=Contents" json:"Contents,omitempty"`
	XXXUnrecognized []byte        `json:"-"`
}

Log define the proto Log

func (*Log) GetContents

func (m *Log) GetContents() []*LogContent

GetContents return the Log's Contents

func (*Log) GetTime

func (m *Log) GetTime() uint32

GetTime return the Log's Time

func (*Log) Marshal

func (m *Log) Marshal() (data []byte, err error)

Marshal the logs to byte slice

func (*Log) MarshalTo

func (m *Log) MarshalTo(data []byte) (int, error)

MarshalTo data

func (*Log) ProtoMessage

func (*Log) ProtoMessage()

ProtoMessage not implemented

func (*Log) Reset

func (m *Log) Reset()

Reset the Log

func (*Log) Size

func (m *Log) Size() (n int)

Size return the log's size

func (*Log) String

func (m *Log) String() string

String return the Compact Log

func (*Log) Unmarshal

func (m *Log) Unmarshal(data []byte) error

Unmarshal data to log

type LogConfig

type LogConfig struct {
	Name         string       `json:"configName"`
	InputType    string       `json:"inputType"`
	InputDetail  InputDetail  `json:"inputDetail"`
	OutputType   string       `json:"outputType"`
	OutputDetail OutputDetail `json:"outputDetail"`

	CreateTime     uint32
	LastModifyTime uint32
	// contains filtered or unexported fields
}

LogConfig define Log Config

func (*LogConfig) GetAppliedMachineGroup

func (c *LogConfig) GetAppliedMachineGroup(confName string) (groupNames []string, err error)

GetAppliedMachineGroup returns applied machine group of this config.

type LogContent

type LogContent struct {
	Key             *string `protobuf:"bytes,1,req,name=Key" json:"Key,omitempty"`
	Value           *string `protobuf:"bytes,2,req,name=Value" json:"Value,omitempty"`
	XXXUnrecognized []byte  `json:"-"`
}

LogContent define the Log content struct

func (*LogContent) GetKey

func (m *LogContent) GetKey() string

GetKey return the Key

func (*LogContent) GetValue

func (m *LogContent) GetValue() string

GetValue return the Value

func (*LogContent) Marshal

func (m *LogContent) Marshal() (data []byte, err error)

Marshal LogContent

func (*LogContent) MarshalTo

func (m *LogContent) MarshalTo(data []byte) (int, error)

MarshalTo logcontent to data

func (*LogContent) ProtoMessage

func (*LogContent) ProtoMessage()

ProtoMessage not implemented

func (*LogContent) Reset

func (m *LogContent) Reset()

Reset LogContent

func (*LogContent) Size

func (m *LogContent) Size() (n int)

Size return LogContent size based on Key and Value

func (*LogContent) String

func (m *LogContent) String() string

String return the compact text

func (*LogContent) Unmarshal

func (m *LogContent) Unmarshal(data []byte) error

Unmarshal data to LogContent

type LogGroup

type LogGroup struct {
	Logs            []*Log  `protobuf:"bytes,1,rep,name=Logs" json:"Logs,omitempty"`
	Reserved        *string `protobuf:"bytes,2,opt,name=Reserved" json:"Reserved,omitempty"`
	Topic           *string `protobuf:"bytes,3,opt,name=Topic" json:"Topic,omitempty"`
	Source          *string `protobuf:"bytes,4,opt,name=Source" json:"Source,omitempty"`
	XXXUnrecognized []byte  `json:"-"`
}

LogGroup define the logs struct

func (*LogGroup) GetLogs

func (m *LogGroup) GetLogs() []*Log

GetLogs return the loggroup logs

func (*LogGroup) GetReserved

func (m *LogGroup) GetReserved() string

GetReserved return Reserved

func (*LogGroup) GetSource

func (m *LogGroup) GetSource() string

GetSource return Source

func (*LogGroup) GetTopic

func (m *LogGroup) GetTopic() string

GetTopic return Topic

func (*LogGroup) Marshal

func (m *LogGroup) Marshal() (data []byte, err error)

Marshal LogGroup

func (*LogGroup) MarshalTo

func (m *LogGroup) MarshalTo(data []byte) (int, error)

MarshalTo LogGroup to data

func (*LogGroup) ProtoMessage

func (*LogGroup) ProtoMessage()

ProtoMessage not implemented

func (*LogGroup) Reset

func (m *LogGroup) Reset()

Reset LogGroup

func (*LogGroup) Size

func (m *LogGroup) Size() (n int)

Size return LogGroup size based on Logs

func (*LogGroup) String

func (m *LogGroup) String() string

String return the compact text

func (*LogGroup) Unmarshal

func (m *LogGroup) Unmarshal(data []byte) error

Unmarshal data to LogGroup

type LogGroupList

type LogGroupList struct {
	LogGroups       []*LogGroup `protobuf:"bytes,1,rep,name=logGroups" json:"logGroups,omitempty"`
	XXXUnrecognized []byte      `json:"-"`
}

LogGroupList define the LogGroups

func LogsBytesDecode

func LogsBytesDecode(data []byte) (gl *LogGroupList, err error)

LogsBytesDecode decodes logs binary data retruned by GetLogsBytes API

func (*LogGroupList) GetLogGroups

func (m *LogGroupList) GetLogGroups() []*LogGroup

GetLogGroups return the LogGroups

func (*LogGroupList) Marshal

func (m *LogGroupList) Marshal() (data []byte, err error)

Marshal LogGroupList

func (*LogGroupList) MarshalTo

func (m *LogGroupList) MarshalTo(data []byte) (int, error)

MarshalTo LogGroupList to data

func (*LogGroupList) ProtoMessage

func (*LogGroupList) ProtoMessage()

ProtoMessage not implemented

func (*LogGroupList) Reset

func (m *LogGroupList) Reset()

Reset LogGroupList

func (*LogGroupList) Size

func (m *LogGroupList) Size() (n int)

Size return LogGroupList size

func (*LogGroupList) String

func (m *LogGroupList) String() string

String return compact text

func (*LogGroupList) Unmarshal

func (m *LogGroupList) Unmarshal(data []byte) error

Unmarshal data to LogGroupList

type LogProject

type LogProject struct {
	Name            string // Project name
	Endpoint        string // IP or hostname of SLS endpoint
	AccessKeyID     string
	AccessKeySecret string
}

LogProject Define the Ali Project detail

func NewLogProject

func NewLogProject(name, endpoint, AccessKeyID, accessKeySecret string) (p *LogProject, err error)

NewLogProject creates a new SLS project.

func (*LogProject) ApplyConfigToMachineGroup

func (p *LogProject) ApplyConfigToMachineGroup(confName, groupName string) (err error)

ApplyConfigToMachineGroup applies config to machine group.

func (*LogProject) CreateConfig

func (p *LogProject) CreateConfig(c *LogConfig) (err error)

CreateConfig creates a new config in SLS.

func (*LogProject) CreateLogStore

func (p *LogProject) CreateLogStore(name string, ttl, shardCnt int) (err error)

CreateLogStore creates a new logstore in SLS, where name is logstore name, and ttl is time-to-live(in day) of logs, and shardCnt is the number of shards.

func (*LogProject) CreateMachineGroup

func (p *LogProject) CreateMachineGroup(m *MachineGroup) (err error)

CreateMachineGroup creates a new machine group in SLS.

func (*LogProject) DeleteConfig

func (p *LogProject) DeleteConfig(name string) (err error)

DeleteConfig deletes a config according by config name.

func (*LogProject) DeleteLogStore

func (p *LogProject) DeleteLogStore(name string) (err error)

DeleteLogStore deletes a logstore according by logstore name.

func (*LogProject) DeleteMachineGroup

func (p *LogProject) DeleteMachineGroup(name string) (err error)

DeleteMachineGroup deletes machine group according machine group name.

func (*LogProject) GetAppliedConfigs

func (p *LogProject) GetAppliedConfigs(groupName string) (confNames []string, err error)

GetAppliedConfigs returns applied config names list according machine group name groupName.

func (*LogProject) GetAppliedMachineGroups

func (p *LogProject) GetAppliedMachineGroups(confName string) (groupNames []string, err error)

GetAppliedMachineGroups returns applied machine group names list according config name.

func (*LogProject) GetConfig

func (p *LogProject) GetConfig(name string) (c *LogConfig, err error)

GetConfig returns config according by config name.

func (*LogProject) GetLogStore

func (p *LogProject) GetLogStore(name string) (s *LogStore, err error)

GetLogStore returns logstore according by logstore name.

func (*LogProject) GetMachineGroup

func (p *LogProject) GetMachineGroup(name string) (m *MachineGroup, err error)

GetMachineGroup retruns machine group according by machine group name.

func (*LogProject) ListConfig

func (p *LogProject) ListConfig(offset, size int) (cfgNames []string, total int, err error)

ListConfig returns config names list and the total number of configs. The offset starts from 0 and the size is the max number of configs could be returned.

func (*LogProject) ListLogStore

func (p *LogProject) ListLogStore() (storeNames []string, err error)

ListLogStore returns all logstore names of project p.

func (*LogProject) ListMachineGroup

func (p *LogProject) ListMachineGroup(offset, size int) (m []string, total int, err error)

ListMachineGroup returns machine group name list and the total number of machine groups. The offset starts from 0 and the size is the max number of machine groups could be returned.

func (*LogProject) RemoveConfigFromMachineGroup

func (p *LogProject) RemoveConfigFromMachineGroup(confName, groupName string) (err error)

RemoveConfigFromMachineGroup removes config from machine group.

func (*LogProject) UpdateConfig

func (p *LogProject) UpdateConfig(c *LogConfig) (err error)

UpdateConfig updates a config.

func (*LogProject) UpdateLogStore

func (p *LogProject) UpdateLogStore(name string, ttl, shardCnt int) (err error)

UpdateLogStore updates a logstore according by logstore name, obviously we can't modify the logstore name itself.

func (*LogProject) UpdateMachineGroup

func (p *LogProject) UpdateMachineGroup(m *MachineGroup) (err error)

UpdateMachineGroup updates a machine group.

type LogStore

type LogStore struct {
	Name       string `json:"logstoreName"`
	TTL        int
	ShardCount int

	CreateTime     uint32
	LastModifyTime uint32
	// contains filtered or unexported fields
}

LogStore Store the logs

func (*LogStore) GetCursor

func (s *LogStore) GetCursor(shardID int, from string) (cursor string, err error)

GetCursor gets log cursor of one shard specified by shardID. The from can be in three form: a) unix timestamp in seccond, b) "begin", c) "end". For more detail please read: http://gitlab.alibaba-inc.com/sls/doc/blob/master/api/shard.md#logstore

func (*LogStore) GetLogs

func (s *LogStore) GetLogs(shardID int, cursor string,
	logGroupMaxCount int) (gl *LogGroupList, nextCursor string, err error)

GetLogs gets logs from shard specified by shardID according cursor. The logGroupMaxCount is the max number of logGroup could be returned. The nextCursor is the next curosr can be used to read logs at next time.

func (*LogStore) GetLogsBytes

func (s *LogStore) GetLogsBytes(shardID int, cursor string,
	logGroupMaxCount int) (out []byte, nextCursor string, err error)

GetLogsBytes gets logs binary data from shard specified by shardID according cursor. The logGroupMaxCount is the max number of logGroup could be returned. The nextCursor is the next curosr can be used to read logs at next time.

func (*LogStore) ListShards

func (s *LogStore) ListShards() (shardIDs []int, err error)

ListShards returns shard id list of this logstore.

func (*LogStore) PutLogs

func (s *LogStore) PutLogs(lg *LogGroup) (err error)

PutLogs put logs into logstore. The callers should transform user logs into LogGroup.

type Machine

type Machine struct {
	IP            string
	UniqueID      string `json:"machine-uniqueid"`
	UserdefinedID string `json:"userdefined-id"`
}

Machine define the Machine

type MachineGroup

type MachineGroup struct {
	Name          string   `json:"groupName"`
	Type          string   `json:"groupType"`
	MachineIDType string   `json:"machineIdentifyType"`
	MachineIDList []string `json:"machineList"`

	Attribute MachineGroupAttribute `json:"groupAttribute"`

	CreateTime     uint32
	LastModifyTime uint32
	// contains filtered or unexported fields
}

MachineGroup define the machine Group

func (*MachineGroup) GetAppliedConfigs

func (m *MachineGroup) GetAppliedConfigs() (confNames []string, err error)

GetAppliedConfigs returns applied configs of this machine group.

func (*MachineGroup) ListMachines

func (m *MachineGroup) ListMachines() (ms []*Machine, total int, err error)

ListMachines returns machine list of this machine group.

type MachineGroupAttribute

type MachineGroupAttribute struct {
	ExternalName string `json:"externalName"`
	TopicName    string `json:"groupTopic"`
}

MachineGroupAttribute define the Attribute

type MachineList

type MachineList struct {
	Total    int
	Machines []*Machine
}

MachineList define the Machine List

type OutputDetail

type OutputDetail struct {
	Endpoint     string `json:"endpoint"`
	LogStoreName string `json:"logstoreName"`
}

OutputDetail define the output detail

type Shard

type Shard struct {
	ShardID int `json:"shardID"`
}

Shard define the Log Shard

Jump to

Keyboard shortcuts

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