report

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package report captures PPDM backup history into a durable store for assurance reporting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID                    string `json:"id"`
	Name                  string `json:"name"`
	Type                  string `json:"type"`
	ProtectionStatus      string `json:"protectionStatus"`
	LastAvailableCopyTime string `json:"lastAvailableCopyTime"`
	ProtectionPolicy      struct {
		Name string `json:"name"`
	} `json:"protectionPolicy"`
}

Asset is one /api/v2/assets record (current protection state; 20.1.0 Asset, ADR-0010).

type CapturedPolicy

type CapturedPolicy struct {
	Name       string
	Objectives []byte
}

CapturedPolicy is a stored protection policy: its name plus the raw objectives JSON.

type Capturer

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

Capturer pulls authoritative PPDM records for one server and persists them.

func NewCapturer

func NewCapturer(store *Store, version string, retention config.Retention, compliance config.Compliance) *Capturer

NewCapturer wires a capturer to a store. retention drives per-tenant prune + backfill; compliance drives post-capture SLA target resolution.

func (*Capturer) CaptureServer

func (c *Capturer) CaptureServer(ctx context.Context, tenant string, client ppdmclient.Client) error

CaptureServer captures jobs/copies (incremental) + assets/policies (full) for one server, upserts them tagged with tenant, and records a capture_runs provenance row.

func (*Capturer) ResolveTargets

func (c *Capturer) ResolveTargets(ctx context.Context, tenant string, cfg config.Compliance) error

ResolveTargets computes the effective SLA targets for a tenant and upserts them into sla_targets. It writes three layers of rows that the compliance view picks the most specific of: the per-tenant default, one per captured protection policy (derived from objectives), and one per matching config override. It never blocks capture — a missing objective just falls back to the configured default.

func (*Capturer) Run

func (c *Capturer) Run(ctx context.Context, servers []ServerClient, interval, timeout time.Duration)

Run loops RunOnce on interval until ctx is cancelled.

func (*Capturer) RunOnce

func (c *Capturer) RunOnce(ctx context.Context, servers []ServerClient, timeout time.Duration)

RunOnce captures every server once (in parallel) and prunes beyond retention.

type ComplianceRow

type ComplianceRow struct {
	AssetID, AssetName, AssetType, PolicyName string
	RPOOk, RetentionOk, CopiesOk, Compliant   bool
	Reasons                                   string
}

ComplianceRow is one asset's SLA verdict from the compliance view.

type Copy

type Copy struct {
	ID              string  `json:"id"`
	AssetID         string  `json:"assetId"`
	CopyType        string  `json:"copyType"`
	CreateTime      string  `json:"createTime"`
	RetentionTime   string  `json:"retentionTime"`
	RetentionLock   string  `json:"retentionLock"` // enum ALL_COPIES_UNLOCKED|ALL_COPIES_LOCKED|PARTIAL_COPIES_LOCKED
	StorageSystemID string  `json:"storageSystemId"`
	Location        string  `json:"location"`
	Size            float64 `json:"size"`
}

Copy is one /api/v2/latest-copies record (20.1.0 Copy, ADR-0010). policyName and expirationTime have no 20.1.0 source and are not captured (columns remain, NULL).

type Job

type Job struct {
	ID          string `json:"id"`
	Category    string `json:"category"`
	Subcategory string `json:"subcategory"`
	State       string `json:"state"`
	CreateTime  string `json:"createTime"`
	EndTime     string `json:"endTime"`
	Result      struct {
		Status           string  `json:"status"`
		BytesTransferred float64 `json:"bytesTransferred"`
	} `json:"result"`
	Asset struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"asset"`
	ProtectionPolicy struct {
		Name string `json:"name"`
	} `json:"protectionPolicy"`
}

Job is one /api/v2/activities record (a backup/restore job — immutable event).

type Policy

type Policy struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Objectives any    `json:"objectives"` // stored as jsonb
}

Policy is one /api/v3/protection-policies record. Objectives kept as raw JSON.

type Rule321Row

type Rule321Row struct {
	AssetID, AssetName, AssetType                       string
	CopiesOk, MediaOk, OffsiteOk, ImmutableOk, ErrorsOk bool
	RulePass                                            bool
	CopiesCount, DistinctMedia, DistinctLocations       int
}

Rule321Row is one asset's 3-2-1-1-0 evaluation from the rule_321110 view.

type SLATarget

type SLATarget struct {
	Tenant        string
	AssetType     string
	PolicyName    string
	RPOSeconds    int64
	RetentionDays int
	MinCopies     int
	GraceSeconds  int64
	Source        string // policy | override | default
}

SLATarget is a resolved per-asset SLA target row (the only materialized Phase 2 state).

type ServerClient

type ServerClient struct {
	Tenant string
	Client ppdmclient.Client
}

ServerClient pairs a tenant with its PPDM client (built by main from config).

func NewServerClient

func NewServerClient(tenant string, client ppdmclient.Client) ServerClient

NewServerClient pairs a tenant with a PPDM client for RunOnce/Run.

type Store

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

Store is the PostgreSQL backup-history store.

func New

func New(ctx context.Context, dsn string) (*Store, error)

New opens a connection pool to dsn.

func (*Store) CapturedPolicies

func (s *Store) CapturedPolicies(ctx context.Context, tenant string) ([]CapturedPolicy, error)

CapturedPolicies returns a tenant's stored protection policies (across servers) for target resolution. Targets are tenant-scoped (assets join by tenant+policy_name, not server).

func (*Store) Close

func (s *Store) Close()

Close releases the pool.

func (*Store) ComplianceRows

func (s *Store) ComplianceRows(ctx context.Context, tenant string) ([]ComplianceRow, error)

ComplianceRows returns a tenant's per-asset SLA verdicts (non-compliant first).

func (*Store) CopyWatermark

func (s *Store) CopyWatermark(ctx context.Context, server string) (time.Time, error)

CopyWatermark returns the newest create_time for a server's copies, or zero time if none.

func (*Store) DeliveryExists added in v1.1.0

func (s *Store) DeliveryExists(ctx context.Context, tenant, period string) (bool, error)

DeliveryExists reports whether a SUCCESSFUL report delivery is already recorded for the (tenant, period) occurrence. Failed attempts return false so the scheduler retries them.

func (*Store) FinishRun

func (s *Store) FinishRun(ctx context.Context, id int64, ok bool, errMsg string, counts map[string]int) error

FinishRun closes a capture_runs row with outcome + per-resource counts.

func (*Store) JobWatermark

func (s *Store) JobWatermark(ctx context.Context, server string) (time.Time, error)

JobWatermark returns the newest created_at for a server's jobs, or zero time if none.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate applies the idempotent schema (CREATE TABLE IF NOT EXISTS).

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, defaultDays int, overrides map[string]int) error

Prune deletes append-only event rows (backup_jobs, copies) older than each tenant's retention window: per-tenant for override tenants, then a default sweep for every other tenant. assets and protection_policies hold current upsert-latest state and are intentionally not pruned.

func (*Store) RecordDelivery added in v1.1.0

func (s *Store) RecordDelivery(ctx context.Context, tenant, period string, ok bool, errMsg string, recipients []string) error

RecordDelivery idempotently upserts the outcome of a delivery attempt for (tenant, period); a later success overwrites an earlier failure.

func (*Store) ReportSummary

func (s *Store) ReportSummary(ctx context.Context, tenant string) (Summary, error)

ReportSummary computes the headline counts for a tenant in one round-trip.

func (*Store) Rule321Rows

func (s *Store) Rule321Rows(ctx context.Context, tenant string) ([]Rule321Row, error)

Rule321Rows returns a tenant's per-asset 3-2-1-1-0 verdicts.

func (*Store) StartRun

func (s *Store) StartRun(ctx context.Context, server, version string) (int64, error)

StartRun opens a capture_runs row and returns its id.

func (*Store) UpsertAssets

func (s *Store) UpsertAssets(ctx context.Context, tenant, server string, assets []Asset, capturedAt time.Time) error

UpsertAssets upserts current asset protection state by id.

func (*Store) UpsertCopies

func (s *Store) UpsertCopies(ctx context.Context, tenant, server string, copies []Copy, capturedAt time.Time) error

UpsertCopies inserts/updates copies by id.

func (*Store) UpsertJobs

func (s *Store) UpsertJobs(ctx context.Context, tenant, server string, jobs []Job, capturedAt time.Time) error

UpsertJobs inserts/updates backup_jobs by id (append-only events; re-capture is a no-op update).

func (*Store) UpsertPolicies

func (s *Store) UpsertPolicies(ctx context.Context, tenant, server string, policies []Policy, capturedAt time.Time) error

UpsertPolicies upserts protection policies by id, objectives as jsonb.

func (*Store) UpsertSLATargets

func (s *Store) UpsertSLATargets(ctx context.Context, targets []SLATarget) error

UpsertSLATargets idempotently writes resolved targets, keyed by (tenant, asset_type, policy_name).

type Summary

type Summary struct {
	TotalAssets, CompliantAssets                   int
	RPOFailures, RetentionFailures, CopiesFailures int
	BadgePass                                      bool // every asset passes 3-2-1-1-0
}

Summary is the report's headline tally for a tenant.

Directories

Path Synopsis
Package delivery sends rendered reports to recipients.
Package delivery sends rendered reports to recipients.
Package render builds and renders per-tenant backup-assurance reports (HTML + PDF) over the report store's compliance and rule_321110 views.
Package render builds and renders per-tenant backup-assurance reports (HTML + PDF) over the report store's compliance and rule_321110 views.
Package reporttest spins up a migrated report.Store backed by a real (throwaway) Postgres via testcontainers, for use by tests in sibling packages (e.g.
Package reporttest spins up a migrated report.Store backed by a real (throwaway) Postgres via testcontainers, for use by tests in sibling packages (e.g.
Package schedule computes per-tenant report due-ness (pure cadence functions) and runs the scheduled generate+deliver loop.
Package schedule computes per-tenant report due-ness (pure cadence functions) and runs the scheduled generate+deliver loop.

Jump to

Keyboard shortcuts

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