Top.Mail.Ru
package bucket — KubFly SDK for Go

KubFly SDK for Go / output/bucket

package bucket

import "kubfly.io/sdk/output/bucket"

Package bucket is the output of a stand bucket: it writes the process into an object bucket in the KubFly format (sdk/spec/format.md) — the kubfly-sdk-output-bucket module of the Java SDK, an output of the pipeline (kubfly.io/sdk/pipeline). Linking the package in registers it:

import _ "kubfly.io/sdk/output/bucket"

It is on when KUBFLY_OUTPUT_BUCKET_KIND is set (KUBFLY_OUTPUT_BUCKET: ON, OFF, AUTO). It needs the names of the stand — KUBFLY_NAMESPACE, KUBFLY_SERVICE, KUBFLY_POD, KUBFLY_CONTAINER, each a DNS-1123 label — and a bucket (KUBFLY_OUTPUT_BUCKET_KIND, KUBFLY_OUTPUT_BUCKET_ROOT; KUBFLY_OUTPUT_BUCKET_PREFIX puts the stand under a prefix of a shared bucket); on without them it panics when the collectors load: the process does not start.

The streams (format.md §2): events (the start and the finish, frames, events, changes of health, losses — encrypted), metrics (encrypted), alerts and health (open), traffic (the links with the peers — encrypted; KUBFLY_OUTPUT_BUCKET_TRAFFIC_ENCRYPT=OFF leaves it open), profiles (encrypted), layout (the tree of the stand and the hourly pulse). Environments and usage snapshots are entities of entities.tsv.

The lanes, the window and the drain are of the pipeline (KUBFLY_PIPELINE_*); the segments are written by the drain and put by a goroutine of the output, so a slow bucket never holds the drain. Call api.Collectors.Finish at the end of main: Go has no hook at the exit of a process, and the last segment is written there.

Constants

const Name = "bucket"

Name is the name of the output: bucket.

const System = "bucket"

System is the system of the metrics of the output and of its check of the bucket: sdk/output-bucket/output/bucket.

Variables

var Config = registerConfig(loadConfig(api.Config.Vars, identity{namespace: api.Config.Namespace.Value(),
	service: api.Config.Service.Value(), pod: api.Config.Pod.Value(), container: api.Config.Container.Value()}))

Config is the configuration of the collector.

Types

type Collector

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

Collector is a collector of a bucket alone: a pipeline.Collector with the output of the bucket as its only output, for reading what it writes in the same process (kubflytest: a bucket in memory and reflector) and for tests and tools. Not registered — an application finds the bucket as an output of the pipeline; whoever makes it gives it its records: a collector of its own that delegates to it, or api.Collectors.Install.

func New

func New(pipelineSettings pipeline.Settings, settings Settings) (*Collector, error)

New is a collector with given settings of the pipeline and of the bucket, its goroutines started; nothing is printed. An error for settings it cannot work with. For tests and tools of other packages and modules (reflector, Navigator): Java keeps its constructor to the package, its tests reach it from the same package (TestBucket) — Go has no such way across modules.

func Of

func Of(store bucket.Bucket, namespace, service, pod, container string, level api.Level) (*Collector, error)

Of is a collector of a given bucket and stand: the instance is that of the process (api.Config.Instance), the other settings are of Config and pipeline.Config, without a cipher and without a spool. An error for names it cannot work with.

func (*Collector) Alert

func (c *Collector) Alert(id int64, begin int64, end int64, metric *api.Metric, severity alert.Severity, warnings int64,
	criticals int64, unassessed int64)

Alert is the state of a metric with thresholds.

func (*Collector) Begin

func (c *Collector) Begin(id int64, time int64, frame *api.Frame)

Begin is a frame that begins.

func (*Collector) Bridge

func (c *Collector) Bridge() bool

Bridge is false: the collector is not a bridge to another logging system.

func (*Collector) Enabled

func (c *Collector) Enabled() bool

Enabled is true.

func (*Collector) End

func (c *Collector) End(id int64, time int64, duration int64, threadID int64, threadName string, frame *api.Frame,
	err error)

End is a frame that ends.

func (*Collector) Event

func (c *Collector) Event(id int64, time int64, threadID int64, threadName string, frame *api.Frame, event *api.Event,
	message string, arg1 api.Arg, arg2 api.Arg, err error)

Event is an event.

func (*Collector) EventArgs

func (c *Collector) EventArgs(id int64, time int64, threadID int64, threadName string, frame *api.Frame,
	event *api.Event, message string, args []api.Arg, err error)

EventArgs is an event of three to api.MaxArguments arguments.

func (*Collector) Finish

func (c *Collector) Finish(id int64, time int64, environment *environment.Environment)

Finish is the finish: everything is written — the lanes, the window, the last segments, the layout.

func (*Collector) Flush

func (c *Collector) Flush()

Flush writes into the bucket now everything received so far and returns when it is there: both halves of the lanes, the whole ordering window, the open segment of every stream, the tree of the stand and the pulse if due (pipeline.Collector.Flush).

func (*Collector) Frames

func (c *Collector) Frames(project, module, area, system, component string) bool

Frames is as the pipeline says.

func (*Collector) Health

func (c *Collector) Health(id int64, time int64, duration int64, check *api.HealthCheck, health api.Health)

Health is a result of a health check.

func (*Collector) Lost

func (c *Collector) Lost() int64

Lost is the count of the records lost because every lane was full.

func (*Collector) Metrics

func (c *Collector) Metrics(id int64, begin int64, end int64, snapshots []*api.Snapshot)

Metrics are the aggregates of an interval.

func (*Collector) Profile

func (c *Collector) Profile(id int64, begin int64, end int64, p *profile.Profile)

Profile is the profile of one kind over an interval.

func (*Collector) Start

func (c *Collector) Start(id int64, time int64, environment *environment.Environment)

Start is the start.

func (*Collector) Threshold

func (c *Collector) Threshold(project, module, area, system string) api.Level

Threshold is the level of the bucket.

func (*Collector) Track

func (c *Collector) Track(id int64, time int64, kubfly *api.KubFly, point util.TrackPoint)

Track is a point of a track (api.TrackCollector).

func (*Collector) Traffic

func (c *Collector) Traffic(id int64, begin int64, end int64, edges []traffic.Edge)

Traffic is the links of an interval.

func (*Collector) Usage

func (c *Collector) Usage(id int64, time int64, usage *usage.Usage)

Usage is a usage snapshot.

type Configuration

type Configuration struct {
	// Bucket tells whether the collector is on (KUBFLY_OUTPUT_BUCKET): on — always (a missing bucket is an error),
	// off — never, auto (by default) — when KUBFLY_OUTPUT_BUCKET_KIND is set.
	Bucket *api.Param[bool]
	// Builder is the builder of the bucket (KUBFLY_OUTPUT_BUCKET_KIND, KUBFLY_OUTPUT_BUCKET_…), or nil when it is
	// missing or wrong (then Check fails).
	Builder bucket.Builder
	// EventsFlush is the interval of the segments of events, seconds (KUBFLY_OUTPUT_BUCKET_EVENTS_FLUSH, 60).
	EventsFlush *api.Param[int]
	// MetricsFlush is the interval of the segments of metrics, seconds (KUBFLY_OUTPUT_BUCKET_METRICS_FLUSH, 60).
	MetricsFlush *api.Param[int]
	// AlertsFlush is the interval of the segments of alerts, seconds (KUBFLY_OUTPUT_BUCKET_ALERTS_FLUSH, 60).
	AlertsFlush *api.Param[int]
	// HealthFlush is the interval of the segments of health, seconds (KUBFLY_OUTPUT_BUCKET_HEALTH_FLUSH, 60).
	HealthFlush *api.Param[int]
	// TrafficFlush is the interval of the segments of traffic, seconds (KUBFLY_OUTPUT_BUCKET_TRAFFIC_FLUSH, 60).
	TrafficFlush *api.Param[int]
	// ProfilesFlush is the interval of the segments of profiles, seconds (KUBFLY_OUTPUT_BUCKET_PROFILES_FLUSH, 60);
	// the stream is always encrypted when the keys are set.
	ProfilesFlush *api.Param[int]
	// TracksFlush is the interval of the segments of tracks, seconds (KUBFLY_OUTPUT_BUCKET_TRACKS_FLUSH, 60); the
	// stream is always encrypted when the keys are set: the places of people are personal data.
	TracksFlush *api.Param[int]
	// TrafficEncrypt tells whether the stream traffic is encrypted, as events and metrics, when the keys are set
	// (KUBFLY_OUTPUT_BUCKET_TRAFFIC_ENCRYPT, on): off — open, as alerts.
	TrafficEncrypt *api.Param[bool]
	// Spool is the directory of the spool (KUBFLY_OUTPUT_BUCKET_SPOOL); None — no spool (by default).
	Spool *api.Param[string]
	// SpoolBytes is the most bytes of the spool (KUBFLY_OUTPUT_BUCKET_SPOOL_BYTES, 1 GiB).
	SpoolBytes *api.Param[int64]
	// SpoolFiles is the most segments of the spool (KUBFLY_OUTPUT_BUCKET_SPOOL_FILES, 10 000).
	SpoolFiles *api.Param[int]
	// AttachmentBytes is the buffer of the attachments (KUBFLY_OUTPUT_BUCKET_ATTACHMENT_BYTES, 32 MiB): two halves,
	// each a pack of attachments put by one request; the largest attachment is a half, one without room is lost.
	AttachmentBytes *api.Param[int64]
	// BlockSize is the size of a block, bytes (KUBFLY_OUTPUT_BUCKET_BLOCK_SIZE, 1 MiB).
	BlockSize *api.Param[int]
	// SegmentBlocks is the size of a segment, blocks (KUBFLY_OUTPUT_BUCKET_SEGMENT_BLOCKS, 32).
	SegmentBlocks *api.Param[int64]
	// DeflateLevel is the level of deflate (KUBFLY_OUTPUT_BUCKET_DEFLATE_LEVEL, 1, at most 9).
	DeflateLevel *api.Param[int]
	// Level is the most verbose level taken (KUBFLY_OUTPUT_BUCKET_LEVEL, INFO).
	Level *api.Param[api.Level]
	// EventsUrgent is the level from which an event closes its segment soon (KUBFLY_OUTPUT_BUCKET_EVENTS_URGENT,
	// ERROR); OFF — never.
	EventsUrgent *api.Param[api.Level]
	// AlertsUrgent tells whether a new alert closes its segment soon (KUBFLY_OUTPUT_BUCKET_ALERTS_URGENT, on).
	AlertsUrgent *api.Param[bool]
	// UrgentDelay is how long after an urgent record its segment closes, milliseconds
	// (KUBFLY_OUTPUT_BUCKET_URGENT_DELAY; by default the ordering window).
	UrgentDelay *api.Param[int]
	// UrgentInterval is the least time between urgent closes of a stream, seconds
	// (KUBFLY_OUTPUT_BUCKET_URGENT_INTERVAL, 5).
	UrgentInterval *api.Param[int]
	// Keys are the public keys of the recipients, MLKEM1024-P384 (KUBFLY_OUTPUT_BUCKET_KEYS,
	// KUBFLY_OUTPUT_BUCKET_KEYS_FILE); none — the segments are written without a cipher.
	Keys []*decoder.RecipientPublicKey
	// RecipientKeys are the public keys of the recipients as set (KUBFLY_OUTPUT_BUCKET_KEYS): a secret parameter.
	RecipientKeys *api.Param[string]
	// KeysFile is a file of more public keys of recipients (KUBFLY_OUTPUT_BUCKET_KEYS_FILE).
	KeysFile *api.Param[string]
	// Code are the sources of the build (KUBFLY_OUTPUT_BUCKET_CODE): a directory, or a .zip or .jar of them; with
	// KUBFLY_BUILD the first instance of the build puts its code into the bucket.
	Code *api.Param[string]
	// Store are the parameters of the bucket itself as set (KUBFLY_OUTPUT_BUCKET_KIND, _ROOT, _ENDPOINT…), the
	// access and secret keys secure: the package bucket reads them for Builder.
	Store []*api.Param[string]
	// Problems are the wrong values that fell back to their defaults.
	Problems []string
	// contains filtered or unexported fields
}

Configuration is the configuration of the collector, taken once from api.Config.Vars when the package loads: the bucket, the names of the stand and the limits of the format — the Config class of the Java SDK. Wrong numbers fall back to their defaults and are listed in Problems; a missing or wrong name of the stand or bucket is an error of Check: with the collector on, the process does not start.

func (*Configuration) Check

func (c *Configuration) Check() error

Check fails if the stand or the bucket is not configured: every missing or wrong name in one error.

type Settings

type Settings struct {
	// Bucket is the bucket.
	Bucket bucket.Bucket
	// Namespace is the namespace of the stand.
	Namespace string
	// Service is the service.
	Service string
	// Pod is the pod.
	Pod string
	// Container is the container.
	Container string
	// Instance is the instance of the process.
	Instance uuid.UUID
	// Language is the language of the texts of the process: in the header of every segment and the start object.
	Language language.Language
	// Flush is the interval of the segments of events, ms.
	Flush int64
	// BlockSize is the size of a block, bytes.
	BlockSize int
	// SegmentBlocks is the size of a segment, blocks.
	SegmentBlocks int64
	// DeflateLevel is the level of deflate, 1–9.
	DeflateLevel int
	// Level is the most verbose level taken.
	Level api.Level
	// Keys are the public keys of the recipients, MLKEM1024-P384; none — no cipher.
	Keys []*decoder.RecipientPublicKey
	// RecipientKeys are the public keys of the recipients as set (KUBFLY_OUTPUT_BUCKET_KEYS): a secret parameter.
	RecipientKeys *api.Param[string]
	// KeysFile is a file of more public keys of recipients (KUBFLY_OUTPUT_BUCKET_KEYS_FILE).
	KeysFile *api.Param[string]
	// Store are the parameters of the bucket itself as set (KUBFLY_OUTPUT_BUCKET_KIND, _ROOT, _ENDPOINT…), the
	// access and secret keys secure: the package bucket reads them for Builder.
	Store []*api.Param[string]
	// Flushes are the intervals of metrics, alerts, health, traffic, profiles and tracks, ms.
	Flushes [6]int64
	// Urgent is the level from which an event closes its segment soon; api.LevelOff (the zero value) — never.
	Urgent api.Level
	// AlertsUrgent tells whether a new alert closes its segment soon.
	AlertsUrgent bool
	// UrgentDelay is how long after an urgent record its segment closes, ms.
	UrgentDelay int64
	// UrgentInterval is the least time between urgent closes of a stream, ms.
	UrgentInterval int64
	// Spool is the bucket of the spool, or nil.
	Spool bucket.Bucket
	// SpoolBytes is the most bytes of the spool.
	SpoolBytes int64
	// SpoolFiles is the most segments of the spool.
	SpoolFiles int
	// AttachmentBytes is the buffer of the attachments, both halves; zero — config.DefaultAttachmentBytes.
	AttachmentBytes int64
	// Statuses takes the status of the process for STATUS; nil — status.Take (a fixed one in tests).
	Statuses StatusSource
}

Settings are what one collector works with: the bucket, the names of the stand and the limits — SettingsOf in an application, given directly in tests and tools. Times are milliseconds.

func SettingsOf

func SettingsOf() (Settings, error)

SettingsOf are the settings of the application: Config and the identity of api.Config; the bucket and the spool connected. An error if the stand or the bucket is not configured or does not open.

type StatusSource

type StatusSource func(taken, sequence int64, checks []status.Check, finish util.Option[status.Finish]) *status.Status

StatusSource takes the status of the process for STATUS: status.Take in an application, a fixed one in tests.