Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["event.go"],
importpath = "go-common/app/service/ops/log-agent/event",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//library/log:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,71 @@
package event
import (
"sync"
"time"
"go-common/library/log"
)
var pool sync.Pool
// event between input and processor
type ProcessorEvent struct {
Source string
Destination string
LogId string
AppId []byte
Level []byte
Time time.Time
Body []byte
Priority string
Length int
TimeRangeKey string
Fields map[string]interface{}
ParsedFields map[string]string
Tags []string
}
// GetEvent get event from pool.
func GetEvent() (e *ProcessorEvent) {
var (
ok bool
tmp = pool.Get()
)
if e, ok = tmp.(*ProcessorEvent); !ok {
e = &ProcessorEvent{Body: make([]byte, 1024*64), Tags: make([]string, 0, 1)} // max 64K, should be longer than max log lentth
}
e.LogId = ""
e.Length = 0
e.AppId = nil
e.Level = nil
e.Time = time.Time{}
e.TimeRangeKey = ""
e.Source = ""
e.Priority = ""
e.Destination = ""
e.Tags = e.Tags[:0]
e.Fields = make(map[string]interface{})
e.ParsedFields = make(map[string]string)
return e
}
// PutEvent put event back to pool
func PutEvent(e *ProcessorEvent) {
pool.Put(e)
}
func (e *ProcessorEvent) Bytes() []byte {
return e.Body[:e.Length]
}
func (e *ProcessorEvent) String() string {
return string(e.Body[:e.Length])
}
func (e *ProcessorEvent) Write(b []byte) {
if len(b) > cap(e.Body) {
log.Error("bytes write beyond e.Body capacity")
}
e.Length = copy(e.Body, b)
}