impact

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package impact answers "who is affected" by a policy change (ADR-0030): for every member of a population (the enrolled fleet, or a policy-only estimate), it resolves ring, experiment variants and effective settings under the base policy and under the new one, and counts who changes, per member kind and per org unit. Rings and variants resolve through policy.ResolveRing and Experiment.ResolveVariant, so internal/assign stays the only hashing.

Index

Constants

View Source
const (
	KindUser   = "user"
	KindDevice = "device"
	KindAgent  = "agent"  // a workload rule's subject (ADR-0023)
	KindGroup  = "group"  // policy estimate: one member of a group policy names
	KindSample = "sample" // policy estimate: an anonymous user in no listed group
)

Member kinds.

Variables

This section is empty.

Functions

func CheckoutAt

func CheckoutAt(ctx context.Context, dir, base string) (string, func(), error)

CheckoutAt writes the policy dir as it is at git ref base into a new temp dir (git archive: the working tree, index and HEAD are never touched) and returns it with a cleanup func.

Types

type Counts

type Counts struct {
	Total    int `json:"total"`
	Ring     int `json:"ring"`
	Variant  int `json:"variant"`
	Settings int `json:"settings"`
	Any      int `json:"any"`
}

Counts is how many members of a set change, by what.

type Example

type Example struct {
	ID         string   `json:"id"`
	Kind       string   `json:"kind"`
	Unit       string   `json:"unit,omitempty"`
	RingBefore string   `json:"ringBefore"`
	RingAfter  string   `json:"ringAfter"`
	Before     []string `json:"variantsBefore,omitempty"` // experiment=variant
	After      []string `json:"variantsAfter,omitempty"`
	Settings   bool     `json:"settingsChanged"`
}

Example is one affected member.

type FleetDevice

type FleetDevice struct {
	ID     string   `json:"id"`
	UserID string   `json:"userID"`
	Groups []string `json:"groups,omitempty"`
	// Revoked devices get nothing either way.
	Revoked bool `json:"revoked"`
}

FleetDevice is the part of a halo-server device record impact reads.

type FleetHost

type FleetHost struct {
	Hostname string `json:"hostname"`
	User     string `json:"user"`
	Device   string `json:"device,omitempty"`
}

FleetHost is the part of a halo-server fleet host impact reads.

type Member

type Member struct {
	ID     string   `json:"id"`
	Groups []string `json:"groups,omitempty"`
	Kind   string   `json:"kind"`
	Device string   `json:"device,omitempty"`
}

Member is one subject a change may reach.

func FleetMembers

func FleetMembers(hosts []FleetHost, devices []FleetDevice, orgs ...*policy.Org) []Member

FleetMembers is the enrolled population: each reporting host as a device (groups from its enrollment), each distinct user once (their devices' groups), plus the orgs' workload subjects as agents.

func PolicyMembers

func PolicyMembers(samples int, orgs ...*policy.Org) []Member

PolicyMembers is the population a policy-only estimate uses: every user id the orgs name (ring and unit members), one member of each group they name, each workload rule's subject, and samples anonymous users (hashing places them like any user in no listed group).

type Report

type Report struct {
	// Source is "fleet" (halo-server's enrolled devices) or "policy" (an
	// estimate from the users and groups policy names plus a hashed sample).
	Source   string            `json:"source"`
	ByKind   map[string]Counts `json:"byKind"`
	ByUnit   []UnitImpact      `json:"byUnit"`
	Examples []Example         `json:"examples"`
}

Report is the impact of a change on a population.

func Compute

func Compute(before, after *policy.Org, members []Member, examples int) Report

Compute compares every member under before and after, keeping up to examples affected members (sorted by unit, then id).

func (Report) Text

func (r Report) Text(base string) string

Text renders r for a terminal.

type UnitImpact

type UnitImpact struct {
	Unit string `json:"unit"`
	Counts
}

UnitImpact is the counts of one org unit ("" = in no unit).

Jump to

Keyboard shortcuts

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