tracefall

package module
v0.0.0-...-93818c8 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 8 Imported by: 0

README

Build Status Version Maintainability Test Coverage Go Report Card codecov

Info

Package for sending logs to the storage, for the subsequent withdrawal of the traceViewer service and display there.

Supported storage drivers:

  • Console // invalid realisation
  • Postgres // invalid realisation
  • Algolia
  • ElasticSearch

Content

  • Thread Line: Line of logs. Contains Logs. Thread ID = First root Log ID
  • Log: data node. May contents other Logs as children

ScreenShort of TraceViewer based on traceFall

screen of trace viewer

Union Logs

Independent Logs may union to one log thread via LogParentShadow

logChild := tracefall.NewLog(`prepare Scrapping`).SetApplication(`micro.1`)
logChild.ParentFromShadow(job.LogShadow)
Example

microservice #1

logParent := tracefall.NewLog(`Start`)
// send to RabbitMQ job with logParent.ToShadow() data

microservice #2

// get from RabbitMQ job with logParent.ToShadow() data
logChild := tracefall.NewLog(`prepare Scrapping`).SetApplication(`micro.2`)
logChild.ParentFromShadow(job.LogShadow)

Now logChild has parent logParent

Use

Create new Log node

import "github.com/efureev/tracefall"
// ...
log := tracefall.NewLog(`test log`)

Finish log

log := tracefall.NewLog(`test log`)

// with fail result
log.Fail(err error)

// with success result 
log.Success()

// without result: set finish time of the log
log.FinishTimeEnd()

Finish thred of logs

log.ThreadFinish()

Add extra data to Log

log := tracefall.NewLog(`test log`)
log.Data.Set(`url`, `http://google.com`).Set(`service`, service.Name)

Add notes to Log

log.Notes.Add(`send to redis`, `ok`).Add(`send to rabbit`, `ok`)
//or
log.Notes.AddGroup(`send to redis`, [`ping`,`processing`,`done`])

Sending logs to storage

var logStorage *tracefall.DB
func tracerLogStart(tracerHost, tracerUser, tracerPassword, tracerDbName, tracerTable string) {
	var err error

	logStorage, err = tracefall.Open(`postgres`, postgres.GetConnParams(tracerHost, tracerDbName, tracerTable, tracerUser, tracerPassword))
	if err != nil {
		log.Fatal(err)
	}
}
func send(m) {
	if logStorage == nil {
        return
    }
	_, err := logStorage.Send(m *tracefall.Log)
    if err != nil {
        fmt.Println(`[error sent to trace logs] -> ` + err.Error())
    }
}

Documentation

Index

Constants

View Source
const (
	EnvironmentDev  = `dev`
	EnvironmentProd = `prod`
	EnvironmentTest = `test`
)

Environments

Variables

View Source
var ErrorParentFinish = errors.New(`the Parent does not have to be the finish point`)

ErrorParentFinish error

View Source
var ErrorParentThreadDiff = errors.New(`the Parent Thread is different from the Thread of own log`)

ErrorParentThreadDiff error

Functions

func Drivers

func Drivers() []string

Drivers returns a sorted list of the names of the registered drivers.

func Register

func Register(name string, driver Driver)

Types

type BaseResponse

type BaseResponse struct {
	ID     string
	Error  error
	Result bool
	Time   time.Time
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(request interface{}) *BaseResponse

func (*BaseResponse) GenerateID

func (r *BaseResponse) GenerateID() *BaseResponse

func (*BaseResponse) Request

func (r *BaseResponse) Request() interface{}

func (*BaseResponse) SetError

func (r *BaseResponse) SetError(err error) *BaseResponse

func (*BaseResponse) SetID

func (r *BaseResponse) SetID(id string) *BaseResponse

func (*BaseResponse) Success

func (r *BaseResponse) Success() *BaseResponse

func (*BaseResponse) ToCmd

func (r *BaseResponse) ToCmd() *ResponseCmd

func (*BaseResponse) ToLog

func (r *BaseResponse) ToLog(log *LogJSON) *ResponseLog

func (*BaseResponse) ToThread

func (r *BaseResponse) ToThread(thread Thread) *ResponseThread

type Connector

type Connector interface {
	Connect(ctx context.Context) (interface{}, error)
	Driver() Driver
}

type DB

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

func Open

func Open(driverName string, connectParams map[string]string) (*DB, error)

func OpenDB

func OpenDB(c drvConnector) (*DB, error)

func (*DB) Driver

func (d *DB) Driver() Driver

func (*DB) GetLog

func (d *DB) GetLog(id uuid.UUID) (ResponseLog, error)

func (*DB) GetThread

func (d *DB) GetThread(id uuid.UUID) (ResponseThread, error)

func (*DB) RemoveByTags

func (d *DB) RemoveByTags(tags Tags) (ResponseCmd, error)

func (*DB) RemoveThread

func (d *DB) RemoveThread(id uuid.UUID) (ResponseCmd, error)

func (*DB) Send

func (d *DB) Send(log *Log) (ResponseCmd, error)

func (*DB) Truncate

func (d *DB) Truncate(ind string) (ResponseCmd, error)

type Driver

type Driver interface {
	Open(map[string]string) (interface{}, error)
	Send(log *Log) (ResponseCmd, error)
	RemoveThread(id uuid.UUID) (ResponseCmd, error)
	RemoveByTags(tags Tags) (ResponseCmd, error)
	GetLog(id uuid.UUID) (ResponseLog, error)
	GetThread(id uuid.UUID) (ResponseThread, error)
	Truncate(ind string) (ResponseCmd, error)
}

type ExtraData

type ExtraData map[string]interface{}

ExtraData is data tree

func NewExtraData

func NewExtraData() ExtraData

NewExtraData create new Data struct

func (*ExtraData) Clear

func (e *ExtraData) Clear() *ExtraData

Clear make empty data struct

func (*ExtraData) FromJSON

func (e *ExtraData) FromJSON(b []byte) error

FromJSON set data to struct from json

func (ExtraData) Get

func (e ExtraData) Get(key string) interface{}

Get return value by key

func (*ExtraData) Set

func (e *ExtraData) Set(key string, val interface{}) *ExtraData

Set data by key

func (ExtraData) ToJSON

func (e ExtraData) ToJSON() []byte

ToJSON get json from data

type Log

type Log struct {
	ID          uuid.UUID
	Thread      uuid.UUID
	Name        string
	Data        ExtraData
	App         string
	Notes       NoteGroups
	Tags        Tags
	Error       error
	Environment string

	Result bool
	Finish bool

	Time    time.Time
	TimeEnd *time.Time
	Parent  *Log
}

Log struct

func NewLog

func NewLog(name string) *Log

NewLog create new Log

func (*Log) CreateChild

func (l *Log) CreateChild(name string) (*Log, error)

CreateChild make new log and attach it to current log as child

func (*Log) Fail

func (l *Log) Fail(err error) *Log

Fail set result of the log: error

func (*Log) FinishTimeEnd

func (l *Log) FinishTimeEnd() *Log

FinishTimeEnd set finish time of the log

func (*Log) GetLevel

func (l *Log) GetLevel() int

GetLevel return depth level of Log in thread

func (*Log) MarshalJSON

func (l *Log) MarshalJSON() ([]byte, error)

MarshalJSON marshal json

func (*Log) ParentFromShadow

func (l *Log) ParentFromShadow(shadow *LogParentShadow) *Log

ParentFromShadow return Parent's ID from LogShadow

func (*Log) SetApplication

func (l *Log) SetApplication(str string) *Log

SetApplication set application name of log

func (*Log) SetDefaults

func (l *Log) SetDefaults() *Log

SetDefaults set values for Log by default

func (*Log) SetEnvironment

func (l *Log) SetEnvironment(env string) *Log

SetEnvironment set environment name of log

func (*Log) SetName

func (l *Log) SetName(name string) *Log

SetName set log name

func (*Log) SetParent

func (l *Log) SetParent(parent *Log) error

SetParent set parent to log for for create Thread

func (*Log) SetParentID

func (l *Log) SetParentID(id uuid.UUID) *Log

SetParentID set parent ID to log

func (Log) String

func (l Log) String() string

String return string representation of log

func (*Log) Success

func (l *Log) Success() *Log

Success set result of the log: success

func (*Log) ThreadFinish

func (l *Log) ThreadFinish() *Log

ThreadFinish finish thread line

func (Log) ToJSON

func (l Log) ToJSON() []byte

ToJSON create json bytes from Log data

func (Log) ToLogJSON

func (l Log) ToLogJSON() *LogJSON

ToLogJSON return JsonLog Struct

func (Log) ToShadow

func (l Log) ToShadow() *LogParentShadow

ToShadow create new shadow struct of log

type LogJSON

type LogJSON struct {
	ID          uuid.UUID     `json:"id"`
	Thread      uuid.UUID     `json:"thread"`
	Name        string        `json:"name"`
	App         string        `json:"app"`
	Time        int64         `json:"time"`
	TimeEnd     *int64        `json:"timeEnd"`
	Result      bool          `json:"result"`
	Finish      bool          `json:"finish"`
	Environment string        `json:"env"`
	Error       *string       `json:"error"`
	Data        ExtraData     `json:"data"`
	Notes       NoteGroupList `json:"notes"`
	Tags        []string      `json:"tags"`
	Parent      *string       `json:"parent"`
}

LogJSON struct

type LogParentShadow

type LogParentShadow struct {
	ID     uuid.UUID `json:"id"`
	Thread uuid.UUID `json:"thread"`
}

LogParentShadow struct

type Logable

type Logable interface {
	Success() Logable
	Fail(err error) Logable
	SetParentID(id uuid.UUID) Logable
	SetParent(parent Logable) error
	CreateChild(name string) (Logable, error)
	ToJSON() []byte
	ToLogJSON() LogJSON
}

Logable interface

type Note

type Note struct {
	Time int64  `json:"t"`
	Note string `json:"v"`
}

Note struct

func NewNote

func NewNote(note string) *Note

NewNote struct

type NoteGroup

type NoteGroup struct {
	Notes Notes  `json:"notes"`
	Label string `json:"label"`
}

NoteGroup struct

func NewNoteGroup

func NewNoteGroup(groupLabel string) *NoteGroup

NewNoteGroup create new NoteGroup

func (*NoteGroup) Add

func (n *NoteGroup) Add(note string) *NoteGroup

Add note to NoteGroup

func (*NoteGroup) Clear

func (n *NoteGroup) Clear() *NoteGroup

Clear NoteGroup from notes

func (NoteGroup) Count

func (n NoteGroup) Count() int

Count elements in NoteGroup

type NoteGroupList

type NoteGroupList []*NoteGroup

NoteGroupList is list of NoteGroup

func (*NoteGroupList) FromJSON

func (n *NoteGroupList) FromJSON(b []byte) error

FromJSON fill NoteGroupList from json

type NoteGroups

type NoteGroups map[string]*NoteGroup

NoteGroups is list of NoteGroup

func NewNotesGroups

func NewNotesGroups() NoteGroups

NewNotesGroups creates new NoteGroups struct

func (NoteGroups) Add

func (n NoteGroups) Add(group, note string) NoteGroups

Add new note to exist group (or create new if absent) in NoteGroups

func (NoteGroups) AddGroup

func (n NoteGroups) AddGroup(group string, notes []string) NoteGroups

AddGroup add notes list to exist group (or create new if absent) in NoteGroups

func (NoteGroups) AddNoteGroup

func (n NoteGroups) AddNoteGroup(group *NoteGroup) NoteGroups

AddNoteGroup add group struct to list

func (*NoteGroups) Clear

func (n *NoteGroups) Clear() *NoteGroups

Clear NoteGroups list

func (NoteGroups) Count

func (n NoteGroups) Count() int

Count elements in NoteGroups

func (*NoteGroups) FromJSON

func (n *NoteGroups) FromJSON(b []byte) error

FromJSON fill NoteGroups from json. Previously clear list

func (NoteGroups) Get

func (n NoteGroups) Get(groupName string) *NoteGroup

Get NoteGroup from NoteGroup list

func (NoteGroups) Remove

func (n NoteGroups) Remove(groupName string) NoteGroups

Remove NoteGroup from list

func (NoteGroups) ToJSON

func (n NoteGroups) ToJSON() []byte

ToJSON return json bytes of NoteGroups

func (NoteGroups) ToJSONString

func (n NoteGroups) ToJSONString() string

ToJSONString return json string of NoteGroups

type Notes

type Notes []*Note

Notes list of Note

type ResponseCmd

type ResponseCmd struct {
	BaseResponse
}

type ResponseLog

type ResponseLog struct {
	BaseResponse
	Log *LogJSON
}

type ResponseThread

type ResponseThread struct {
	BaseResponse
	Thread Thread
}

type Responsible

type Responsible interface {
	Success() Responsible
}

type Tags

type Tags []string

Tags struct is list of string

func (*Tags) Add

func (t *Tags) Add(tag string) *Tags

Add new Tag by name

func (*Tags) Clear

func (t *Tags) Clear() *Tags

Clear tag list

func (Tags) List

func (t Tags) List() []string

List of tags

type Thread

type Thread []*LogJSON

Thread is list of LogJSON struct

func ThreadFromList

func ThreadFromList(list []*LogJSON) Thread

ThreadFromList make Thread from list of LogJSON structs

func (*Thread) Add

func (t *Thread) Add(log *LogJSON) Thread

Add Log to Thread

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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