server

package
v0.0.0-...-f1eb0ed Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: AGPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// QueryAuthTokenEnv environment variable
	QueryAuthTokenEnv = "MINIO_LOG_QUERY_AUTH_TOKEN"
	// PgConnStrEnv environment variable
	PgConnStrEnv = "LOGSEARCH_PG_CONN_STR"
	// AuditAuthTokenEnv environment variable
	AuditAuthTokenEnv = "LOGSEARCH_AUDIT_AUTH_TOKEN"
	// DiskCapacityEnv environment variable
	DiskCapacityEnv = "LOGSEARCH_DISK_CAPACITY_GB"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Name            string         `json:"name,omitempty"`
	AccessKey       string         `json:"accessKey,omitempty"`
	Bucket          string         `json:"bucket,omitempty"`
	Object          string         `json:"object,omitempty"`
	Status          string         `json:"status,omitempty"`
	StatusCode      int            `json:"statusCode,omitempty"`
	TimeToFirstByte *time.Duration `json:"timeToFirstByte,omitempty"`
	TimeToResponse  time.Duration  `json:"timeToResponse,omitempty"`
}

API is struct with same info an Entry.API, but with more strong types.

type DBClient

type DBClient struct {
	*sql.DB
}

DBClient is a client object that makes requests to the DB.

func NewDBClient

func NewDBClient(ctx context.Context, connStr string) (*DBClient, error)

NewDBClient creates a new DBClient.

func (*DBClient) CreateIndices

func (c *DBClient) CreateIndices(ctx context.Context) error

CreateIndices creates table indexes for audit_log_events and request_info tables. See auditLogIndices, reqInfoIndices functions for actual indices details.

func (*DBClient) CreateParentIndices

func (c *DBClient) CreateParentIndices(ctx context.Context, optses []indexOpts) error

CreateParentIndices creates all indices specified by optses on the parent table.

func (*DBClient) CreatePartitionIndices

func (c *DBClient) CreatePartitionIndices(ctx context.Context, optses []indexOpts, partition string) (indexed bool, err error)

CreatePartitionIndices creates all indices described by optses on partition. It returns true if a new index was created on this partition. Note: this function ignores the index already exists error.

func (*DBClient) InitDBTables

func (c *DBClient) InitDBTables(ctx context.Context) error

InitDBTables Creates tables in the DB.

func (*DBClient) InsertEvent

func (c *DBClient) InsertEvent(ctx context.Context, eventBytes []byte) (err error)

InsertEvent inserts audit event in the DB.

func (*DBClient) Search

func (c *DBClient) Search(ctx context.Context, s *SearchQuery, w io.Writer) error

Search executes a search query on the db.

type Entry

type Entry struct {
	Version      string `json:"version"`
	DeploymentID string `json:"deploymentid,omitempty"`
	Time         string `json:"time"`
	Trigger      string `json:"trigger"`
	API          struct {
		Name            string `json:"name,omitempty"`
		AccessKey       string `json:"accessKey,omitempty"`
		Bucket          string `json:"bucket,omitempty"`
		Object          string `json:"object,omitempty"`
		Status          string `json:"status,omitempty"`
		StatusCode      int    `json:"statusCode,omitempty"`
		TimeToFirstByte string `json:"timeToFirstByte,omitempty"`
		TimeToResponse  string `json:"timeToResponse,omitempty"`
	} `json:"api"`
	RemoteHost string                 `json:"remotehost,omitempty"`
	RequestID  string                 `json:"requestID,omitempty"`
	UserAgent  string                 `json:"userAgent,omitempty"`
	ReqClaims  map[string]interface{} `json:"requestClaims,omitempty"`
	ReqQuery   map[string]string      `json:"requestQuery,omitempty"`
	ReqHeader  map[string]string      `json:"requestHeader,omitempty"`
	RespHeader map[string]string      `json:"responseHeader,omitempty"`
	Tags       map[string]interface{} `json:"tags,omitempty"`
}

Entry - audit entry logs.

type Event

type Event struct {
	Version      string                 `json:"version"`
	DeploymentID string                 `json:"deploymentid,omitempty"`
	Time         time.Time              `json:"time"`
	API          API                    `json:"api"`
	RemoteHost   string                 `json:"remotehost,omitempty"`
	RequestID    string                 `json:"requestID,omitempty"`
	UserAgent    string                 `json:"userAgent,omitempty"`
	ReqClaims    map[string]interface{} `json:"requestClaims,omitempty"`
	ReqQuery     map[string]string      `json:"requestQuery,omitempty"`
	ReqHeader    map[string]string      `json:"requestHeader,omitempty"`
	RespHeader   map[string]string      `json:"responseHeader,omitempty"`
}

Event is the same as Entry but with more typed values.

func EventFromEntry

func EventFromEntry(e *Entry) (*Event, error)

EventFromEntry performs a type conversion

type LogEventRow

type LogEventRow struct {
	EventTime time.Time              `json:"event_time"`
	Log       map[string]interface{} `json:"log"`
}

LogEventRow holds a raw log record

type LogSearch

type LogSearch struct {
	// Configuration
	PGConnStr                      string
	AuditAuthToken, QueryAuthToken string
	DiskCapacityGBs                int

	// Runtime
	DBClient *DBClient
	*http.ServeMux
}

LogSearch represents the Log Search API server

func LoadEnv

func LoadEnv() (*LogSearch, error)

LoadEnv loads environment variables and returns a new LogSearch.

func NewLogSearch

func NewLogSearch(pgConnStr, auditAuthToken string, queryAuthToken string, diskCapacity int) (ls *LogSearch, err error)

NewLogSearch creates a LogSearch

func (*LogSearch) StartServer

func (ls *LogSearch) StartServer()

StartServer starts the webserver.

type QTemplate

type QTemplate string

QTemplate is used to represent queries that involve string substitution as well as SQL positional argument substitution.

type ReqInfoRow

type ReqInfoRow struct {
	Time                  time.Time `json:"time"`
	APIName               string    `json:"api_name"`
	AccessKey             string    `json:"access_key"`
	Bucket                string    `json:"bucket"`
	Object                string    `json:"object"`
	TimeToResponseNs      uint64    `json:"time_to_response_ns"`
	RemoteHost            string    `json:"remote_host"`
	RequestID             string    `json:"request_id"`
	UserAgent             string    `json:"user_agent"`
	ResponseStatus        string    `json:"response_status"`
	ResponseStatusCode    int       `json:"response_status_code"`
	RequestContentLength  *uint64   `json:"request_content_length"`
	ResponseContentLength *uint64   `json:"response_content_length"`
}

ReqInfoRow holds a structured log record

type SearchQuery

type SearchQuery struct {
	Query         qType
	TimeStart     *time.Time
	TimeEnd       *time.Time
	LastDuration  *time.Duration
	TimeAscending bool
	PageNumber    int
	PageSize      int
	ExportFormat  string
	FParams       map[fParam]string
}

SearchQuery represents a search query.

type Table

type Table struct {
	Name            string
	CreateStatement QTemplate
}

Table a database table

Jump to

Keyboard shortcuts

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