oplog

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package oplog implements standard (but extensible) logging for operations (events with status, start/end times). Useful for operational queries and dashboarding with CloudWatch Insights/Metrics. Using standard attributes describing operations and their status allows easy creation of Cloudwatch alarms for discrete system operations. The 3 level (namespace, component, operation) hierarchy enables grouping when graphing/querying. For example, if the hierarchy has top level namespace of "logprocessor" then you can see all errors where namespace="logprocessor" in single graph/query. Similarly you can compute latency and other performance related metrics in aggregate over different _standard_ dimensions.

Example usage:

  manager := oplog.NewManager("panther", "logprocessor")
  // record every S3 object read
  operation := manager.Start("readlogfile")
  defer func() {
		operation.Stop()
        operation.Log(err,
           zap.String("bucket", bucket),
           zap.String("object", object))
  }()
  ... code to read log from S3

Index

Constants

View Source
const (
	Success = "success"
	Failure = "failure"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	Namespace string
	Component string
}

func NewManager

func NewManager(namespace, component string) *Manager

func (*Manager) Start

func (m *Manager) Start(operation string, dimensions ...zap.Field) *Operation

type Operation

type Operation struct {
	Manager        *Manager
	Name           string
	Dimensions     []zap.Field
	StartTime      time.Time
	EndTime        time.Time
	StartMemStats  *runtime.MemStats // can be nil!
	EndMemStats    *runtime.MemStats // can be nil!
	AvailableMemMB int               // if not zero, the available memory, use to calc percentage
}

func (*Operation) Log

func (o *Operation) Log(err error, fields ...zap.Field)

wrapper handling err

func (*Operation) LogError

func (o *Operation) LogError(err error, fields ...zap.Field)

implies status=Fail

func (*Operation) LogSuccess

func (o *Operation) LogSuccess(fields ...zap.Field)

func (*Operation) LogWarn

func (o *Operation) LogWarn(err error, fields ...zap.Field)

implies status=Fail

func (*Operation) Stop

func (o *Operation) Stop() *Operation

func (*Operation) WithMemStats added in v0.3.0

func (o *Operation) WithMemStats() *Operation

func (*Operation) WithMemUsed added in v0.3.0

func (o *Operation) WithMemUsed(availableMemMB int) *Operation

Jump to

Keyboard shortcuts

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