s3-orchestrator

accounting

import "github.com/afreidah/s3-orchestrator/internal/proxy/accounting"

Index

type OperationRecordFunc

OperationRecordFunc is the per-operation metric callback. Wraps the existing Prometheus operation histogram so the Recorder does not have to import the metrics package directly.

type OperationRecordFunc func(operation, backend string, start time.Time, err error)

type Recorder

Recorder centralizes the per-backend accounting rules. Safe for concurrent use: all state lives on the underlying UsageTracker and OperationRecordFunc, which are themselves safe.

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

func New

func New(usage *counter.UsageTracker, recordOp OperationRecordFunc) *Recorder

New constructs a Recorder. usage credits the per-backend API call and ingress/egress byte counters; recordOp emits the per-operation Prometheus histogram observation.

func (*Recorder) APICall

func (r *Recorder) APICall(backend string)

APICall credits one API call against the backend’s usage counter. Call after every attempt that contacted the backend, regardless of outcome: the HTTP call was made either way.

func (*Recorder) APICalls

func (r *Recorder) APICalls(backend string, n int64)

APICalls credits n API calls against the backend’s usage counter. For paginated lists, multipart completes that touch many part objects, and other multi-call operations.

func (*Recorder) Egress

func (r *Recorder) Egress(backend string, sizeBytes int64)

Egress credits one API call + sizeBytes of egress on the backend. Use after a successful GET-like operation (the bytes left the backend toward the client).

func (*Recorder) GetSuccess

func (r *Recorder) GetSuccess(operation, backend string, sizeBytes int64, start time.Time)

GetSuccess is the canonical “GET succeeded” pair: emit the per-op metric with a nil error and credit one API call + egress bytes.

func (*Recorder) Ingress

func (r *Recorder) Ingress(backend string, sizeBytes int64)

Ingress credits one API call + sizeBytes of ingress on the backend. Use after a successful PUT-like operation (the bytes arrived at the backend from the client).

func (*Recorder) Operation

func (r *Recorder) Operation(operation, backend string, start time.Time, err error)

Operation emits the per-operation Prometheus histogram observation. Pair with APICall / Egress / Ingress for the usage-counter side; the two surfaces are deliberately separate so callers can record the API-call charge on failure paths without also emitting a fake success observation.

func (*Recorder) OperationFailed

func (r *Recorder) OperationFailed(operation, backend string, start time.Time, err error)

OperationFailed is the canonical “the call reached the backend and failed” pair: emit the per-op metric with the err and credit one API call (no bytes, since nothing transferred).

func (*Recorder) PutSuccess

func (r *Recorder) PutSuccess(operation, backend string, sizeBytes int64, start time.Time)

PutSuccess is the canonical “PUT succeeded” pair: emit the per-op metric with a nil error and credit one API call + ingress bytes.

Generated by gomarkdoc