Documentation
¶
Overview ¶
Package network is the offline half of `fft network`: the snapshot format a crawl writes, and the resolver that answers "which facilities does this connection reach, for this kind of order?" from it.
Nothing here reaches the tenant except Crawl, and Crawl only reads: every operation it sends is listed in CrawlOperations, and a spec holds each of them to the read-only classification in internal/api. Everything else works on a Snapshot on disk, so a check can run in CI, on a laptop on a train, or a hundred times against the same data while a rule is being tuned.
The semantics the resolver implements — how `context` entries combine, which facility FACILITY and FACILITY_GROUP match, what a missing tag does — were settled against real networks and are recorded in the consultant skill's connections-semantics.md. They are not configurable: they are what the router does, and a linter that disagreed with the router would be worse than none.
Index ¶
- Constants
- Variables
- func BundleReason(why string) string
- func IsNotExist(err error) bool
- func ParseScope(s string) (string, error)
- func RenderReport(v View) ([]byte, error)
- func ReportCSP() string
- func RuleIDs() []string
- func Save(path string, s *Snapshot) error
- func ValidCountry(s string) bool
- func ValidDiffField(key string) bool
- type Baseline
- type BaselineCounts
- type BaselineError
- type Bitset
- type Bundle
- type Category
- type CategoryList
- type Cell
- type ComparedFinding
- type Comparison
- type Config
- type ConfigError
- type ConfigItem
- type ConnectionDiff
- type ConnectionEnd
- type ConnectionMatch
- type ConnectionSide
- type ContextEntry
- type Cost
- type Coverage
- type CoverageMatrix
- type CoverageQuery
- type CoverageRow
- type CoverageTable
- type CrawlError
- type CrawlOptions
- type Date
- type DecisionLog
- type DeclaredProfile
- type DiffOptions
- type DiffSide
- type Edge
- type ExpectFor
- type ExpectFrom
- type Expectation
- type Facility
- type FacilityDiff
- type Fallback
- type FieldDiff
- type File
- type Finding
- type Group
- type Header
- type HubSetAside
- type ItemCategory
- type Kind
- type LoadedFile
- func (lf *LoadedFile) Expired(now time.Time) []Problem
- func (lf *LoadedFile) ResolveCategories(n *Network) []Problem
- func (lf *LoadedFile) Settings(now time.Time) Config
- func (lf *LoadedFile) Unmatched(n *Network) []Problem
- func (lf *LoadedFile) UsesTenantCategories() bool
- func (lf *LoadedFile) Validate() []Problem
- type Neighbourhood
- type Network
- func (n *Network) Applies(e *Edge, p Profile) (Verdict, int)
- func (n *Network) Check(cfg Config) Report
- func (n *Network) Explain(e *Edge, i int, p Profile) Reason
- func (n *Network) Facility(i int) *Facility
- func (n *Network) HasGroup(id string) bool
- func (n *Network) InferFile(now time.Time) []byte
- func (n *Network) InferPeers(cfg Config, roles Roles) []PeerGroup
- func (n *Network) InferProfiles(cfg Config) []ProfileCount
- func (n *Network) InferRoles(cfg Config) Roles
- func (n *Network) Len() int
- func (n *Network) Locate(ref string) (int, bool)
- func (n *Network) Lookup(ref string) (int, bool)
- func (n *Network) MeasureCoverage(cfg Config, q CoverageQuery) (CoverageTable, error)
- func (n *Network) Reach(e *Edge, p Profile) Reach
- func (n *Network) ReachTo(i int, p Profile, roles Roles) []ReachRow
- func (n *Network) Select(sel *Selector) Bitset
- func (n *Network) Snapshot() *Snapshot
- func (n *Network) StaticTargets(e *Edge) Bitset
- func (n *Network) Unread() Bitset
- func (n *Network) Values(c ContextEntry) []string
- func (n *Network) View(cfg Config, opts ViewOptions) View
- type NodeConfig
- type OfflineSettings
- type OneOrMany
- type OrderProfile
- type PeerGroup
- type PeerSettings
- type PortableEntry
- type Predicate
- type Problem
- type Profile
- type ProfileCount
- type ProfileMatcher
- type ProfileSource
- type Reach
- type ReachDiff
- type ReachRow
- type Reason
- type Recipient
- type Report
- type RoleSelectors
- type Roles
- type Selector
- type SetDiff
- type Skipped
- type Snapshot
- type SnapshotDiff
- type SnapshotError
- type Source
- type SourceDiff
- type Stats
- type Strategy
- type StrategyCondition
- type StrategyNode
- type Suppression
- type Tag
- type TagValue
- type Target
- type TimeFrame
- type Transit
- type Verdict
- type View
- type ViewCounts
- type ViewDecided
- type ViewFacility
- type ViewOptions
- type ViewPeer
- type ViewProfile
Constants ¶
const ( // BaselineNew marks a finding the baseline does not hold. BaselineNew = "new" // BaselineUnchanged marks a finding the baseline already held. BaselineUnchanged = "unchanged" // BaselineResolved marks a finding of the baseline the check no longer makes. BaselineResolved = "resolved" )
const ( RuleNoSource = "no-source" RulePeerCoverage = "peer-coverage" RuleDanglingRef = "dangling-ref" RuleOfflineRef = "offline-ref" RuleDuplicateEdge = "duplicate-edge" // RuleExpect reports a declared expectation a facility does not meet. RuleExpect = "expect" // RuleConfigDrift reports a config file the network has moved away from. RuleConfigDrift = "config-drift" )
The rule ids. They are part of the output contract: a CI job suppresses a finding by its rule id, and an agent branches on it.
const ( // StateClosed: the facility's closing date is today or has passed. StateClosed = "closed" // StateTemporary: the closing date lies ahead. StateTemporary = "temporary" // StateUnknown: closedSince is configured and the facility carries no date. StateUnknown = "unknown" )
The states of an offline-ref finding.
const ( ProfilesFromDecisionLogs = "decision-logs" ProfilesDeclared = "declared" )
The profile sources.
const ( // RuleConnectionNeverDelivers reports a connection whose recurring // non-delivery weekdays for some country cover all seven days. RuleConnectionNeverDelivers = "connection-never-delivers" // RuleConnectionNoCutoff reports a connection with no cut-off time on any // day, where nearly all of its peers have one. RuleConnectionNoCutoff = "connection-no-cutoff" // RuleConnectionCostOutlier reports a fallback cost of zero, or one far // outside its peers'. RuleConnectionCostOutlier = "connection-cost-outlier" )
The rules about what a connection says beyond where it leads.
const ( // DefaultConcurrency is how many facilities' connections are walked at once. // A production gateway throttled a crawl of three parallel walks about every // two thousand requests; more would only be throttled sooner. DefaultConcurrency = 3 // MaxConcurrency caps --concurrency. The crawl shares the tenant with the // people running it. MaxConcurrency = 8 // DefaultPause is the first back-off after a throttled request. Gateways that // throttle recover in about a minute; a few seconds would only be throttled // again. DefaultPause = time.Minute // DefaultMaxPauses is how often one walk may be paused for before the crawl // gives up on it and keeps the journal for --resume. A walk, not a request: // a throttled page starts its walk again from the first page, and every // pause of that walk draws on this one budget. DefaultMaxPauses = 5 )
The crawl's defaults.
const ( DiffOnlyBase = "only-base" DiffOnlyOther = "only-other" DiffChanged = "changed" )
What a difference is: present on one side only, or on both and not the same.
const ( ResultApplies = "applies" ResultConditional = "conditional" ResultExcluded = "excluded" )
The results a reach row can have.
const ( // ScopeAll reads every facility's connections. ScopeAll = "all" // ScopeManaged reads every facility, but only the connections of managed // facilities: suppliers are most of a large network's facilities, and a check // of what the hubs cover does not need theirs. ScopeManaged = "managed" )
The scopes a crawl can read. A snapshot stores ScopeAll as an empty Scope, so that every snapshot from before scopes existed reads as the complete one it is.
const ( TypeManaged = "MANAGED_FACILITY" TypeSupplier = "SUPPLIER" TypeCustomer = "CUSTOMER" StatusOnline = "ONLINE" )
The facility and target types and the status the resolver needs to tell apart.
const ( ContextFacility = "FACILITY" ContextFacilityGroup = "FACILITY_GROUP" ContextTag = "TAG_REFERENCE" ContextCategory = "CATEGORY" ContextTargetPostcode = "TARGET_POSTALCODE" ContextTargetCountry = "TARGET_COUNTRY" OperatorNot = "NOT" )
The context entry types and the one operator the API defines. An entry without an operator is positive: one of its values must match.
const ( RuleStrategyInUse = "strategy-in-use" RuleStrategyCategory = "strategy-category" RuleStrategyInactive = "strategy-inactive" RuleStrategyExpired = "strategy-expired" RuleStrategyFallback = "strategy-fallback" RuleStrategyNoRating = "strategy-no-rating" RuleToolkitHardcodeID = "toolkit-hardcoded-id" )
The strategy rule ids.
const BaselineFormat = 1
BaselineFormat is the version of the document `check --baseline -o json` prints. Any change to how a finding is keyed (baselineKeys, keysOf) must bump it, and must give a bare array, which cannot carry a version, a structural tell, or this fft would compare an old array under the new key and call everything new and everything old resolved.
const ConfigVersion = 1
ConfigVersion is the config file format this fft reads and writes.
const DefaultConfigFile = "fft-network.yaml"
DefaultConfigFile is the file `fft network check` reads when --config names none: the one next to the code that is checked into the team's repository.
const DefaultMaxFacilities = 500
DefaultMaxFacilities is how many neighbourhoods a view explains unless told otherwise. Each is a few kilobytes, and a report is one file a browser loads.
const JournalSuffix = ".partial.jsonl"
JournalSuffix is appended to a snapshot's path to name the journal of the crawl writing it.
const MaxBundleSources = 20
MaxBundleSources is how many sources a bundle names.
const MaxMissing = 200
MaxMissing is how many unreached stores a coverage cell names. A country a hub misses entirely would otherwise put thousands of labels in every cell of its row, and a report is opened in a browser, not paged through.
const OutDegreeRelative = "relative"
OutDegreeRelative is the one OutDegree a selector may name.
const RuleFacilityUngrouped = "facility-ungrouped"
RuleFacilityUngrouped reports an online store that is in no facility group while most of its peers are. A connection that targets a group never reaches such a store, which peer-coverage shows only indirectly, as "no hub reaches it"; this states the cause. The id lives here, with the rule, as the connection rules' and the strategy rules' do.
const SchemaVersion = 3
SchemaVersion is the snapshot format this fft writes. Load reads it and every version below it, and refuses one above it: a newer fft may have changed what a field means, and a check that silently misread its input would report gaps that are not there, or miss ones that are.
Version 2 added the connection details a check reads beyond routing: cut-off times, costs, non-delivery days and packaging units (Snapshot.Schedules, Edge.Costs). A version 1 snapshot loads with those absent, which Snapshot.HasConnectionDetails tells apart from a connection that has none.
Version 3 added Snapshot.Scope. It is a bump, not just a new field, because a scoped snapshot lacks connections a full one has: an fft that does not know about scopes would check it as if it were complete, and report a supplier's missing connections as gaps, or their problems as clean. It refuses it instead.
const TenantCategoryPrefix = "tenant:"
TenantCategoryPrefix marks a category written by its tenantCategoryId rather than its platform id: tenant:books-general. The platform id differs on every tenant, so a config that names categories by it cannot be shared between a test and a production tenant; the tenant's own id is the same on both.
The prefix cannot be mistaken for an id: the API allows a tenantCategoryId only letters, digits, - and _, and a platform id is a UUID, so neither holds a colon.
Variables ¶
var ConfigSchema []byte
ConfigSchema is the JSON Schema of fft-network.yaml, for editors and agents. A spec holds it to the decoder: every example and every file `fft network infer` writes validates against both.
var CrawlOperations = []string{
"searchFacility",
"getFacilityConnections",
"searchFacilityGroup",
"getTags",
"getRoutingStrategies",
"getRoutingStrategyNodeConfigCategories",
"getCategories",
"getRoutingDecisionLogs",
"getOrder",
}
CrawlOperations are the operationIds a crawl sends, and the only ones. A spec holds every one of them to the read-only classification: `fft network snapshot` is a single command that sends nine kinds of request, and the read-only gate, which reads one annotation per command, cannot see eight of them.
var DefaultDiffFields = []string{"status", "type", "address.country"}
DefaultDiffFields are the facility fields Diff compares unless told otherwise: the ones whose change alters what a facility can do.
var ErrBadQuery = errors.New("bad coverage query")
ErrBadQuery wraps every error MeasureCoverage returns for a query it cannot run, so a caller can tell a mistake in what was asked (a usage error) from a failure to read the network.
var Scopes = []string{ScopeAll, ScopeManaged}
Scopes are the values --scope takes, in the order help lists them.
Functions ¶
func BundleReason ¶ added in v0.12.0
BundleReason is a reach reason as a bundle states it.
func IsNotExist ¶
IsNotExist reports whether err is a config file that is not there.
func ParseScope ¶ added in v0.15.0
ParseScope checks a --scope value and returns it as a snapshot stores it.
func RenderReport ¶ added in v0.12.0
RenderReport writes the view as one self-contained HTML page: the data, the script that draws it and its styles, inline. It needs no server and makes no request.
func ReportCSP ¶ added in v0.12.0
func ReportCSP() string
ReportCSP is the page's Content-Security-Policy: nothing may load, connect or submit anywhere, and the only script and style that run are the ones fft embedded, by hash.
A report holds the tenant's network and is opened in a browser, where anything that slipped into a facility's name could try to run. The policy is the second wall behind the page writing tenant text only as text: even then, nothing in the page can send the data anywhere. It also lets whoever opens the file see for themselves that it works offline.
func RuleIDs ¶
func RuleIDs() []string
RuleIDs are the rules a check runs, in the order it reports them.
func Save ¶
Save writes s to path, gzipped, readable by its owner only: a snapshot is the tenant's whole network, and it is nobody else's business on a shared machine.
func ValidCountry ¶ added in v0.12.0
ValidCountry reports whether s is a country code a profile can declare: two upper-case ASCII letters, an ISO 3166 alpha-2 code as the API writes one.
func ValidDiffField ¶ added in v0.15.0
ValidDiffField reports whether key names a facility field Diff can compare.
Types ¶
type Baseline ¶ added in v0.15.0
Baseline is an earlier check, read to be compared with.
func ReadBaseline ¶ added in v0.15.0
ReadBaseline reads what `fft network check -o json` printed, or what `check --baseline -o json` printed, so one comparison can be the next run's baseline. A file whose findings cannot be matched reliably is refused rather than compared: a comparison that quietly calls everything new, or everything resolved, is worse than none.
type BaselineCounts ¶ added in v0.15.0
type BaselineCounts struct {
New int `json:"new" yaml:"new"`
Unchanged int `json:"unchanged" yaml:"unchanged"`
Resolved int `json:"resolved" yaml:"resolved"`
}
BaselineCounts is how many findings fell in each group.
type BaselineError ¶ added in v0.15.0
BaselineError is a baseline that cannot be compared with. It exits 3, like a snapshot that cannot be read: the command was fine, its input is not.
func (*BaselineError) Error ¶ added in v0.15.0
func (e *BaselineError) Error() string
func (*BaselineError) ExitCode ¶ added in v0.15.0
func (e *BaselineError) ExitCode() int
ExitCode is 3: the input is unusable.
func (*BaselineError) Hint ¶ added in v0.15.0
func (e *BaselineError) Hint() string
Hint says what to do about it.
func (*BaselineError) Unwrap ¶ added in v0.15.0
func (e *BaselineError) Unwrap() error
Unwrap returns the cause.
type Bitset ¶
type Bitset []uint64
Bitset is a set of facility indices. A production network has tens of thousands of facilities and well over a hundred thousand connections, and the resolver intersects a target set with a context's set for every connection and every order profile; a map per set would not fit, and would not be fast.
A nil Bitset is the empty set for every read.
type Bundle ¶ added in v0.12.0
type Bundle struct {
Kind Kind `json:"kind"`
Result string `json:"result"`
// Reason is ReachTo's reason without the context entry's position, which
// differs from connection to connection while the reason does not.
Reason string `json:"reason"`
Count int `json:"count"`
// Sources names up to MaxBundleSources of the sources, SourceCount counts
// them all. The connections themselves stay with [Network.ReachTo].
Sources []string `json:"sources"`
SourceCount int `json:"sourceCount"`
// Transit is the shortest and longest fallback transit time among the
// connections that have one.
Transit *Transit `json:"transit,omitempty"`
}
Bundle is the connections from one kind of source that do the same thing for a facility, for the same reason: what Network.ReachTo lists row by row, counted. On a real network one context entry excludes thousands of connections, and the bundle is that sentence once.
type Category ¶
type Category struct {
ID string `json:"id"`
}
Category is a routing node config category.
type CategoryList ¶ added in v0.15.0
type CategoryList []string
CategoryList is a list of categories as a config file writes them: each a platform id, tenant:<tenantCategoryId>, or {tenantCategoryId: <id>}. The object form is kept as the tenant: string, so everything downstream handles one spelling; LoadedFile.ResolveCategories turns it into the platform id before the config is used.
func (*CategoryList) UnmarshalJSON ¶ added in v0.15.0
func (l *CategoryList) UnmarshalJSON(b []byte) error
UnmarshalJSON reads each entry in either form.
func (*CategoryList) UnmarshalYAML ¶ added in v0.15.0
func (l *CategoryList) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML reads each entry in either form.
type Cell ¶ added in v0.12.0
type Cell struct {
// Have is how many of the group's stores a source reaches whatever the
// order's items and recipient; Conditional how many more one reaches only
// for some.
Have int `json:"have"`
Conditional int `json:"conditional,omitempty"`
// Missing names the stores Have leaves out, up to MaxMissing; More counts
// the rest.
Missing []string `json:"missing,omitempty"`
More int `json:"more,omitempty"`
// Flagged is how many of the missing stores the check reported for this
// kind of source and order. A cell can miss stores no finding names: a gap
// most of a group shares is no outlier, and the matrix is what shows it.
Flagged int `json:"flagged,omitempty"`
}
Cell is one peer group and one kind of order.
type ComparedFinding ¶ added in v0.15.0
type ComparedFinding struct {
Finding `yaml:",inline"`
Baseline string `json:"baseline" yaml:"baseline"`
}
ComparedFinding is a current finding and what the baseline says of it.
type Comparison ¶ added in v0.15.0
type Comparison struct {
Format int `json:"baselineFormat" yaml:"baselineFormat"`
// Findings are every current finding, new and unchanged, in the report's order.
Findings []ComparedFinding `json:"findings" yaml:"findings"`
// Resolved are the baseline's own findings that the check no longer makes.
Resolved []Finding `json:"resolved" yaml:"resolved"`
Counts BaselineCounts `json:"counts" yaml:"counts"`
// NotCompared is how many findings of the baseline were left out because
// their rule did not run over the whole network this time, and NowSuppressed
// how many the config now accepts. Neither is resolved; stderr says so.
NotCompared int `json:"-" yaml:"-"`
NowSuppressed int `json:"-" yaml:"-"`
}
Comparison is a check set against a baseline.
func Compare ¶ added in v0.15.0
func Compare(r Report, cfg Config, b *Baseline) Comparison
Compare sets the report against the baseline.
A baseline finding is resolved only if its rule ran in full: one the config did not select, one the snapshot could not run (skipped), one that ran on part of the network, or the drift rule without a config file would otherwise make every finding of it look fixed. A rule that did not run found nothing, and that is not the same as clean.
type Config ¶
type Config struct {
// HubRatio is how far a hub must stand out: the facilities above the largest
// jump in reach between consecutive facilities that both reach somebody are
// hubs, if that jump is at least this factor. (The drop to facilities that
// reach nobody counts only when no such jump does, as for a lone hub over
// stores that supply nothing.) A fixed count would not survive the move from a
// pre-production network of a few dozen stores to a production one of
// thousands. A facility whose reach all comes through one connection much
// slower than the hubs' is then set aside and the ranking taken again without
// it (see [Roles.HubsSetAside]).
HubRatio float64
// PeerBy is the facility field stores are grouped by.
PeerBy string
// PeerMinSize is the smallest peer group a store is compared with. Below it,
// "most of its peers" is one or two facilities, and an outlier is noise.
PeerMinSize int
// store without one is reported.
PeerShare float64
// Rules selects the rules to run; empty runs all of them.
Rules []string
// FromFile says the settings came from a config file, which is what makes
// config-drift worth checking: without one there is nothing pinned to drift
// from.
FromFile bool
// Hub, Store and Supplier pick the roles; nil is the default for each.
Hub, Store, Supplier *Selector
// Custom are the user-defined roles, by name. They are only ever named by an
// expectation: the heuristics see the three built-in roles.
Custom map[string]*Selector
// Declared replaces the inferred order profiles, when set.
Declared []Profile
Expect []Expectation
// Suppress are the suppressions still in force.
Suppress []Suppression
// OfflineClosedSince is the facility field holding the day an offline
// facility closed; empty means offline-ref does not tell closed from
// temporarily offline. Now is the day it is judged against.
OfflineClosedSince string
Now time.Time
}
Config is what a check assumes about the network's shape, and what the team has declared about it. Every field has a default that worked on real networks; a config file (LoadedFile.Settings) is how a team pins them.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig is what a check assumes when nobody has said otherwise.
type ConfigError ¶
ConfigError is a config file that cannot be used. It exits 3, like any config fft cannot use.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
func (*ConfigError) ExitCode ¶
func (e *ConfigError) ExitCode() int
ExitCode is 3: the config is unusable.
type ConfigItem ¶
type ConfigItem struct {
Type string `json:"type"`
Implementation string `json:"implementation"`
ReferenceID string `json:"referenceId"`
Name string `json:"name"`
Active bool `json:"active"`
}
ConfigItem is one fence or rating.
type ConnectionDiff ¶ added in v0.15.0
type ConnectionDiff struct {
TargetType string `json:"targetType"`
// Target is the target facility's tenant id, or "*" for a wildcard.
Target string `json:"target"`
// Context is the connection's shape: its entries' types and operators,
// sorted. Two connections of one source are the same connection when their
// target and shape are.
Context []string `json:"context"`
Change string `json:"change"`
Base *ConnectionSide `json:"base"`
Other *ConnectionSide `json:"other"`
// Differs names what differs in a changed connection: "transit",
// "context FACILITY", "excludedFacilities", "excludedGroups".
Differs []string `json:"differs,omitempty"`
Sets []SetDiff `json:"sets,omitempty"`
}
ConnectionDiff is one connection, matched by what it is rather than by its id, which is per tenant. Base or Other is nil on the side that has no such connection.
type ConnectionEnd ¶ added in v0.14.0
type ConnectionEnd struct {
Role string `yaml:"role,omitempty" json:"role,omitempty"`
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Facilities []string `yaml:"facilities,omitempty" json:"facilities,omitempty"`
Where map[string]string `yaml:"where,omitempty" json:"where,omitempty"`
}
ConnectionEnd names facilities the way an expectation's reachableFrom does: a role, or the selector fields, flat. The two forms exclude each other.
type ConnectionMatch ¶ added in v0.14.0
type ConnectionMatch struct {
From *ConnectionEnd `yaml:"from,omitempty" json:"from,omitempty"`
// To matches a connection only when it leads to a facility the end names
// and every online facility it can lead to is one the end names; a closed
// facility the end leaves out is not one it can lead to. See
// [Network.StaticTargets].
To *ConnectionEnd `yaml:"to,omitempty" json:"to,omitempty"`
// Categories matches a connection whose context has a CATEGORY entry, not
// a NOT one, naming at least one of them.
Categories CategoryList `yaml:"categories,omitempty" json:"categories,omitempty"`
}
ConnectionMatch describes connections. Its fields combine with AND, and a field left out matches every connection.
type ConnectionSide ¶ added in v0.15.0
type ConnectionSide struct {
ID string `json:"id"`
Transit *Transit `json:"transit,omitempty"`
Context []PortableEntry `json:"context"`
ExcludedFacilities []string `json:"excludedFacilities,omitempty"`
ExcludedGroups []string `json:"excludedGroups,omitempty"`
}
ConnectionSide is a connection as one side has it, its references in tenant ids so that the two sides can be read against one another.
type ContextEntry ¶
type ContextEntry struct {
Type string `json:"type"`
Operator string `json:"operator,omitempty"`
Values int `json:"values"`
}
ContextEntry is one entry of a connection's context. Values indexes Snapshot.ValueSets.
type Cost ¶ added in v0.12.0
type Cost struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
// Unit is the measurement unit of the cost's coefficient when the cost is
// charged per unit (per kilogram, say), empty for a flat cost. A per-unit
// price and a flat one are not comparable.
Unit string `json:"unit,omitempty"`
}
Cost is one of a connection's fallback costs, in major units: the API stores the smallest subunit (cents) with the currency's decimal places, and a check compares amounts, not cents.
type Coverage ¶
type Coverage struct {
Kind Kind `json:"kind"`
Group string `json:"group"`
Have int `json:"have"`
Size int `json:"size"`
Profile string `json:"profile"`
}
Coverage is how many of a peer group's stores some source of one kind reaches, for the profile where the fewest are.
type CoverageMatrix ¶ added in v0.12.0
CoverageMatrix is how many of each peer group's stores one kind of source reaches, for each kind of order. Cells is indexed [peer][profile], in the order of View.Peers and View.Profiles.
type CoverageQuery ¶ added in v0.15.0
type CoverageQuery struct {
// From names the sources the way reachableFrom does: a Role, or the selector
// fields Type, Facilities and Where. The two forms exclude each other.
From ConnectionEnd
// For is the facilities whose reach is counted. An empty Role means "store".
For ExpectFor
// By is the facility field the targets are grouped by; empty means the
// config's peers.by.
By string
// Profiles narrows the order profiles, as an expectation's profiles does:
// any matcher matching one picks it. Empty evaluates all of them.
Profiles []ProfileMatcher
// MaxTransitDays, when set, counts only connections whose fallback transit
// time is at most this many days, as reachableFrom's maxTransitDays does.
MaxTransitDays *float64
// Missing fills [CoverageRow.Missing]. It is opt-in because the lists are as
// long as the groups are large, for every source and profile.
Missing bool
}
CoverageQuery is what Network.MeasureCoverage measures. Its fields mean what the same-named fields of an expectation mean, so that a row is one expectation's numbers without writing the expectation: From is reachableFrom's sources, For and Profiles are the expectation's own, and MaxTransitDays is reachableFrom's.
type CoverageRow ¶ added in v0.15.0
type CoverageRow struct {
Source string `json:"source"`
Group string `json:"group"`
// Profile is Profile.String(): what suppressions and findings name a profile
// by. Name is the alias the config gives a declared profile, for display.
Profile string `json:"profile"`
Name string `json:"name,omitempty"`
Reached int `json:"reached"`
Size int `json:"size"`
// Transit is, over the reached stores, the smallest and the largest
// maxTransitDays at which the source still reaches them. It is nil when none
// of them is reached through a connection that has a transit time.
Transit *Transit `json:"transit,omitempty"`
// Untimed counts the reached stores whose only connections have no transit
// time: maxTransitDays would not count them, and Transit has no number for
// them.
Untimed int `json:"untimed,omitempty"`
Missing []string `json:"missing,omitempty"`
}
CoverageRow is the reach of one source into one group of targets, for one order profile. It equals the findings of the expectation
for: {role: R, where: {<by>: Group}}
profiles: [Profile]
reachableFrom: {facilities: [Source], atLeast: 1, maxTransitDays: D}
as Size-Reached findings, whose subjects are Missing. One difference: a source in the group is left out of Size, while the expectation reports it as a target that nothing else in the set reaches, so it has one more finding than the row has missing stores.
func (CoverageRow) Key ¶ added in v0.15.0
func (r CoverageRow) Key() string
Key identifies a row across two measurements of the same network, which is what comparing them (before and after a change) joins on.
type CoverageTable ¶ added in v0.15.0
type CoverageTable struct {
Roles Roles
// By is the field the targets are grouped by.
By string
// Sources are the labels that have rows, sorted.
Sources []string
// Offline are the selected sources that are offline: an offline facility
// supplies nothing, so they have no rows, as in reachableFrom.
Offline []string
// Unread says why some sources have no rows, when the snapshot's scope left
// their connections unread: a row for them would say "reaches nothing".
Unread string
// Groups are the targets' groups, largest first, as [Network.InferPeers]
// orders them.
Groups []PeerGroup
// Profiles are the profiles evaluated, in the order a check lists them.
Profiles []ProfileCount
// Rows are by Sources, then Groups, then Profiles.
Rows []CoverageRow
}
CoverageTable is a measurement: the rows, and what they were measured over.
type CrawlError ¶
CrawlError is a crawl that stopped part-way. Its exit code is the cause's — an expired session exits 4, a gateway that never recovered exits 9 — and its hint says that the work done so far is not lost.
func (*CrawlError) Error ¶
func (e *CrawlError) Error() string
type CrawlOptions ¶
type CrawlOptions struct {
// Source names the tenant. It is written into the snapshot and the journal,
// and a journal from another source is never resumed.
Source Source
FFTVersion string
// Out is where the snapshot goes; the journal is Out + [JournalSuffix].
Out string
Resume bool
// Scope is whose connections to read, as [ParseScope] returns it: empty
// reads everyone's.
Scope string
Concurrency int
// DecisionLogs is how many recent routing decision logs to read: one page,
// because the endpoint cannot be paged (#318). Zero skips them, and the
// orders with them.
DecisionLogs int
// Orders reads the orders the decision logs name, for the tags that make up
// the order profiles.
Orders bool
Pause time.Duration
MaxPauses int
// Sleep waits, or returns the context's error. Nil is a real sleep; specs
// replace it so that a minute's back-off does not take a minute.
Sleep func(ctx context.Context, d time.Duration) error
// Progress receives what the crawl is doing: stderr, never stdout.
Progress io.Writer
Now func() time.Time
}
CrawlOptions configures Crawl.
type Date ¶
Date is a calendar day, written 2027-01-15.
func (Date) MarshalJSON ¶
MarshalJSON writes the date as YYYY-MM-DD.
func (Date) MarshalYAML ¶
MarshalYAML writes the date as YYYY-MM-DD.
func (Date) Passed ¶
Passed reports whether the day after d has begun on now's calendar, in now's own location. d is parsed as UTC midnight, so comparing it with the instant now would end a suppression at 16:00 on its last day west of UTC and an hour into the next day east of it; "through that day" is a calendar statement, and the caller's calendar is the one that counts.
type DecisionLog ¶
type DecisionLog struct {
ID string `json:"id"`
Created string `json:"created,omitempty"`
OrderRef string `json:"orderRef,omitempty"`
// Evaluation is the log's routingStrategyEvaluationResult, as the API gave it.
Evaluation json.RawMessage `json:"evaluation,omitempty"`
// Connections are the facilityConnectionRefs of the transfers it chose.
Connections []string `json:"connections,omitempty"`
}
DecisionLog is the part of a routing decision log a check reads: which branch of the strategy the router took, and which connections it used.
type DeclaredProfile ¶ added in v0.12.0
type DeclaredProfile struct {
// Name is nil when the profile is not named, and non-nil but empty for
// `name: ""`, which Validate rejects. It labels the profile and nothing
// more: findings and suppressions still tell profiles apart by
// [Profile.String], which a rename must not change.
Name *string
Tags map[string]string
// Categories is nil when the profile does not declare any, and non-nil but
// empty for an explicit empty list, which Validate rejects: it would not say
// what the writer meant.
Categories []string
Recipient *Recipient
}
DeclaredProfile is one declared kind of order: the tags it carries and, when it says so, the categories of its items and where its recipient lives, which is what lets a CATEGORY or TARGET_COUNTRY context entry be evaluated instead of left conditional. It may also carry a name, for the report and the check's output to show in place of the tags.
A file writes it in either of two forms:
declared:
- { orderType: restock } # the plain map: tags only
- name: Hazmat restock # the structured form
tags: { orderType: restock }
categories: [HAZMAT]
recipient: { country: DE }
The two are told apart by shape, never by guessing at intent: an entry is the structured form only when every key is one of name, tags, categories or recipient, each has the shape that form gives it (name a scalar, tags and recipient a mapping, categories a list), and at least one key is not name. A tag genuinely named "tags" with a scalar value, or an entry whose only key is a tag named "name", is then still a plain map, so no file written for the plain form changes meaning. A value may be a YAML alias of an anchored one, so a long list of profiles can share one category list; the shape is judged on what the alias stands for.
func (DeclaredProfile) MarshalJSON ¶ added in v0.12.0
func (d DeclaredProfile) MarshalJSON() ([]byte, error)
MarshalJSON writes the form the profile was declared in, so that each form round-trips.
func (DeclaredProfile) MarshalYAML ¶ added in v0.15.0
func (d DeclaredProfile) MarshalYAML() (any, error)
MarshalYAML writes the form the profile was declared in, as MarshalJSON does.
func (DeclaredProfile) Profile ¶ added in v0.12.0
func (d DeclaredProfile) Profile() Profile
Profile is the order profile the declaration stands for.
func (*DeclaredProfile) UnmarshalJSON ¶ added in v0.12.0
func (d *DeclaredProfile) UnmarshalJSON(b []byte) error
UnmarshalJSON reads either form, by the same shape rule as the YAML.
func (*DeclaredProfile) UnmarshalYAML ¶ added in v0.12.0
func (d *DeclaredProfile) UnmarshalYAML(entry *yaml.Node) error
UnmarshalYAML reads either form; see DeclaredProfile for how it tells them apart.
type DiffOptions ¶ added in v0.15.0
type DiffOptions struct {
// Fields are the facility fields compared; nil is [DefaultDiffFields].
Fields []string
// From names the sources whose reach is compared, as coverage's --from does.
// The zero value is the role "hub".
From ConnectionEnd
}
DiffOptions say what Diff compares.
type DiffSide ¶ added in v0.15.0
type DiffSide struct {
Path string `json:"path"`
Project string `json:"project"`
SnapshotAt time.Time `json:"snapshotAt"`
Scope string `json:"scope,omitempty"`
}
DiffSide says which snapshot a side of the diff is. The command fills Path.
type Edge ¶
type Edge struct {
ID string `json:"id"`
// Source is the platform id of the facility whose connection list it came
// from — authoritative, because that is where the crawl found it.
Source string `json:"source"`
Target Target `json:"target"`
Context []ContextEntry `json:"context,omitempty"`
// Transit is the connection's fallbackTransitTime, when it has one.
Transit *Transit `json:"transit,omitempty"`
// Costs are the connection's fallbackCosts. Unlike the tables below they are
// a few numbers, so they stay on the edge.
Costs []Cost `json:"costs,omitempty"`
// Cutoffs, NonDelivery and Packaging index [Snapshot.Schedules]: the
// connection's cutoffTimes, nonDeliveryDays and packagingUnitsByContexts. nil
// means the connection has none (or, on a version 1 snapshot, that it was
// not read: see [Snapshot.HasConnectionDetails]).
Cutoffs *int `json:"cutoffs,omitempty"`
NonDelivery *int `json:"nonDelivery,omitempty"`
Packaging *int `json:"packaging,omitempty"`
}
Edge is one interfacility connection.
type ExpectFor ¶
type ExpectFor struct {
Role string `yaml:"role" json:"role"`
Where map[string]string `yaml:"where,omitempty" json:"where,omitempty"`
}
ExpectFor is which facilities an expectation is about.
type ExpectFrom ¶
type ExpectFrom struct {
Role string `yaml:"role,omitempty" json:"role,omitempty"`
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Facilities []string `yaml:"facilities,omitempty" json:"facilities,omitempty"`
Where map[string]string `yaml:"where,omitempty" json:"where,omitempty"`
// AtLeast is the lower bound, counted within the role or, with a selector,
// within the named set: with facilities: [HUB-01, HUB-02], 2 means both. It
// may be left out when AtMost is set, which leaves the expectation with no
// lower bound.
AtLeast int `yaml:"atLeast,omitempty" json:"atLeast,omitempty"`
// AtMost is the upper bound, for an invariant that is an exclusion: a
// facility that must not be reachable. A pointer, because atMost: 0 is the
// main use and must be told apart from "not set".
AtMost *int `yaml:"atMost,omitempty" json:"atMost,omitempty"`
// MaxTransitDays, when set, counts only connections whose fallback transit
// time is at most this many days. A connection without one does not count.
MaxTransitDays *float64 `yaml:"maxTransitDays,omitempty" json:"maxTransitDays,omitempty"`
// MaxCost, when set, counts only connections with a flat fallback cost of
// at most this much, in major units (4.50, not 450 cents). A connection
// without one does not count. The number has no currency, so it is only read
// where the snapshot's costs are all in one.
MaxCost *float64 `yaml:"maxCost,omitempty" json:"maxCost,omitempty"`
}
ExpectFrom is what must reach them: the facilities of a role, or the ones a selector names (Type, Facilities, Where, the fields a role selector has). The two forms exclude each other. The selector fields are flat, not a nested selector, so that the file reads `reachableFrom: {facilities: [HUB-01], atLeast: 1}`.
type Expectation ¶
type Expectation struct {
Name string `yaml:"name" json:"name"`
For ExpectFor `yaml:"for" json:"for"`
// Profiles scopes the expectation to the order profiles any of its entries
// matches. Without it every profile is evaluated.
Profiles []ProfileMatcher `yaml:"profiles,omitempty" json:"profiles,omitempty"`
// ReachableFrom is the reach each facility must have; nil when the file
// leaves it out. A pointer, so that the file's `reachableFrom: {}` or
// `atLeast: 0` is told apart from it being left out: a written reach is
// validated as written, never silently dropped beside a has.
ReachableFrom *ExpectFrom `yaml:"reachableFrom,omitempty" json:"reachableFrom,omitempty"`
// Has is what each facility's own fields must hold, by field path; see
// [Predicate]. It reads the snapshot's facilities and sends no request.
Has map[string]Predicate `yaml:"has,omitempty" json:"has,omitempty"`
}
Expectation is an invariant the team declares about the facilities a selector picks: each is reachable from at least AtLeast, and at most AtMost, sources of a role, or of a set of facilities the expectation names (ReachableFrom), and/or each carries the data Has says. It names at least one of the two; with both, a facility must meet both.
type Facility ¶
type Facility struct {
ID string `json:"id"`
TenantFacilityID string `json:"tenantFacilityId,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type"`
Status string `json:"status"`
Country string `json:"country,omitempty"`
PostalCode string `json:"postalCode,omitempty"`
CustomAttributes json.RawMessage `json:"customAttributes,omitempty"`
}
Facility is the part of a facility a check reads.
type FacilityDiff ¶ added in v0.15.0
type FacilityDiff struct {
Facility string `json:"facility"`
Change string `json:"change"`
Fields []FieldDiff `json:"fields,omitempty"`
}
FacilityDiff is a facility only one side has, or one whose compared fields differ.
type Fallback ¶
type Fallback struct {
Active bool `json:"active"`
Facilities []string `json:"facilityRefs"`
After string `json:"fallbackAfterTime"`
}
Fallback is a node's fallback facility.
type FieldDiff ¶ added in v0.15.0
type FieldDiff struct {
Field string `json:"field"`
Base string `json:"base"`
Other string `json:"other"`
}
FieldDiff is one facility field's value on each side; "" is a field the facility does not have.
type File ¶
type File struct {
Version int `yaml:"version" json:"version"`
Rules []string `yaml:"rules,omitempty" json:"rules,omitempty"`
Roles RoleSelectors `yaml:"roles,omitempty" json:"roles,omitzero"`
Peers *PeerSettings `yaml:"peers,omitempty" json:"peers,omitempty"`
Profiles *ProfileSource `yaml:"profiles,omitempty" json:"profiles,omitempty"`
Offline *OfflineSettings `yaml:"offline,omitempty" json:"offline,omitempty"`
Expect []Expectation `yaml:"expect,omitempty" json:"expect,omitempty"`
Suppress []Suppression `yaml:"suppress,omitempty" json:"suppress,omitempty"`
}
File is fft-network.yaml: what a team has pinned about its network's shape, what it expects of it, and which findings it has accepted for now.
Every field is optional. What the file does not say, the check infers, and says on stderr that it did.
type Finding ¶
type Finding struct {
Rule string `json:"rule"`
// Subject is what the finding is about: a facility's tenant id, a reference
// that resolves to nothing, or a connection's source.
Subject string `json:"subject"`
// Facilities are the facilities involved, by tenant id where they have one.
Facilities []string `json:"facilities,omitempty"`
// Profiles are the order profiles the finding holds for, when it depends on
// the order at all.
Profiles []string `json:"profiles,omitempty"`
Detail string `json:"detail"`
// Evidence is what the finding was concluded from: counts, shares, the ids
// of the connections involved.
Evidence map[string]any `json:"evidence,omitempty"`
// Next is what a person, or an agent, should look at first.
Next string `json:"next"`
// State is the kind of case a finding is, for a rule that tells them apart: an
// offline-ref finding is "closed", "temporary" or "unknown" once offline.closedSince
// names a field, and has none without it. Other rules leave it empty. It is also
// in Evidence["state"], where the other facts are.
State string `json:"state,omitempty"`
// contains filtered or unexported fields
}
Finding is one problem a check found.
type Group ¶
type Group struct {
ID string `json:"id"`
TenantID string `json:"tenantFacilityGroupId,omitempty"`
Name string `json:"name,omitempty"`
Members []string `json:"facilityRefs"`
}
Group is a facility group and its members.
type Header ¶ added in v0.15.0
type Header struct {
SchemaVersion int `json:"schemaVersion"`
FFTVersion string `json:"fftVersion"`
CreatedAt time.Time `json:"createdAt"`
Source Source `json:"source"`
Scope string `json:"scope,omitempty"`
Stats Stats `json:"stats"`
}
Header is the part of a snapshot that says what it is, without its network.
func ReadHeader ¶ added in v0.15.0
ReadHeader reads a snapshot's Header and stops at its first data field, so that `fft network status`, which a terminal UI runs on every refresh, does not decode a production network to say when it was taken. The header fields come first because Snapshot declares them first, and encoding/json writes fields in declaration order.
type HubSetAside ¶ added in v0.15.0
type HubSetAside struct {
Index int
// Reach is how many online facilities the one connection reaches.
Reach int
// Connection is the id of that connection.
Connection string
// Reason says it in one line: "one connection to group G, 9-12 days, ...".
Reason string
}
HubSetAside is a facility that reached as far as a hub, and was not taken for one: all of its reach came through one connection, more than twice as slow as the hubs' median. A fallback catch-all to a whole facility group looks like this, wide by reach and nobody's supply hub.
type ItemCategory ¶ added in v0.15.0
type ItemCategory struct {
ID string `json:"id"`
TenantID string `json:"tenantCategoryId,omitempty"`
}
ItemCategory is a category an item is in: GET /api/categories, not the routing node config categories of Category.
type Kind ¶
type Kind string
Kind is the role a facility plays as a source.
const KindAny Kind = "any"
KindAny is a coverage matrix's column for every kind of source at once: the view of the no-source rule, where the others are the view of peer-coverage.
type LoadedFile ¶
type LoadedFile struct {
File
Path string
// Base is the file Path extends, as a path fft can open, or "" when it
// extends none. The File is then the two merged.
Base string
// contains filtered or unexported fields
}
LoadedFile is a config file and the YAML tree it was read from, which is what lets a problem found after decoding still name its line.
func ParseConfig ¶
func ParseConfig(data []byte, path string) (*LoadedFile, error)
ParseConfig decodes a config file strictly and checks what it says. path names it in errors. It reads one file: a file that extends another is read with ReadConfig, which can open the base.
func ReadConfig ¶
func ReadConfig(path string) (*LoadedFile, error)
ReadConfig reads and checks a config file, and the base it extends if it extends one. A missing file is fs.ErrNotExist, so a caller can tell "there is no config" from "the config is wrong".
func (*LoadedFile) Expired ¶
func (lf *LoadedFile) Expired(now time.Time) []Problem
Expired is every suppression whose date has passed on now: they no longer suppress anything, and validate reports them so they are renewed or removed.
func (*LoadedFile) ResolveCategories ¶ added in v0.15.0
func (lf *LoadedFile) ResolveCategories(n *Network) []Problem
ResolveCategories turns every category the file names by tenantCategoryId into the platform id the snapshot's item categories give it, in place, so that what the check matches, and the profile string findings and suppressions are keyed on, are exactly what a file naming the id would give. A reference that matches no category, or more than one, is a problem at its line, as is one in a snapshot that never read the categories at all.
It is the config's last check against the snapshot before anything uses it: every caller that runs a check with the file runs it first.
func (*LoadedFile) Settings ¶
func (lf *LoadedFile) Settings(now time.Time) Config
Settings turns the file into what a check runs with, over the defaults.
func (*LoadedFile) Unmatched ¶
func (lf *LoadedFile) Unmatched(n *Network) []Problem
Unmatched is every selector, pinned facility and suppression that names nothing in the snapshot: almost always a typo, or a facility since retired.
func (*LoadedFile) UsesTenantCategories ¶ added in v0.15.0
func (lf *LoadedFile) UsesTenantCategories() bool
UsesTenantCategories reports whether the file names any category by its tenantCategoryId, which only a snapshot can resolve.
func (*LoadedFile) Validate ¶
func (lf *LoadedFile) Validate() []Problem
Validate reports what is wrong with the file on its own, without a snapshot: values out of range, names that clash, a suppression with no reason. Expired suppressions are not among them — see LoadedFile.Expired.
type Neighbourhood ¶ added in v0.12.0
type Neighbourhood struct {
// Role is the facility's own role as a source, empty when it is none.
Role Kind `json:"role,omitempty"`
Sets [][]Bundle `json:"sets"`
Profiles []int `json:"profiles"`
}
Neighbourhood is every connection that could lead to one facility, counted into bundles: Sets[Profiles[k]] for the kind of order View.Profiles[k].
Kinds of order differ in tags only some connections read, so most of a facility's kinds of order get the same bundles; each distinct list is carried once. On a real network that was three quarters of them, and a report's size is what a browser has to load.
func (Neighbourhood) Bundles ¶ added in v0.12.0
func (nb Neighbourhood) Bundles(k int) []Bundle
Bundles is the bundles for the kind of order View.Profiles[k].
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network is a Snapshot indexed for resolving. Building one is linear in the snapshot; every answer after that works on bitsets.
It memoises the facility set of each context value list it has resolved, so it is not safe for concurrent use.
func (*Network) Applies ¶
Applies is the half of Network.Reach that depends on the order: whether e applies to p at all, and if not, or only conditionally, because of which context entry (-1 for none).
func (*Network) Explain ¶
Explain says why e does or does not lead to the facility at index i for p. It names the first thing that rules the facility out, in the order the router would meet it: the target, its exclusions, then each context entry.
func (*Network) InferFile ¶
InferFile writes a starter config file: every value a check would infer from the network, each with the reason it was chosen, as a comment above it.
The point is to turn guesses into decisions. A value left in the file is pinned — a check follows it, and reports config-drift when the network moves away from it — and a value deleted is inferred again on every run, as it is without a file.
func (*Network) InferPeers ¶
InferPeers groups the stores by cfg.PeerBy, largest group first.
func (*Network) InferProfiles ¶
func (n *Network) InferProfiles(cfg Config) []ProfileCount
InferProfiles is the kinds of order a check compares, most common first.
They come from the orders the snapshot's decision logs routed, reduced to the tag values some connection's context mentions: a tag no connection reads cannot change where an order may go, and keeping it would split one kind of order into many. A snapshot without routed orders falls back to one profile per tag value a positive context entry asks for.
func (*Network) InferRoles ¶
InferRoles decides which online facilities are hubs, stores and suppliers.
Unless the config pins them, a hub is a managed facility whose connections reach far more facilities than anybody else's. "Far more" is relative: the facilities are sorted by reach, and the cut goes at the largest jump between neighbours that both reach somebody, provided it is at least cfg.HubRatio. The drop to the facilities that reach nobody counts only when no such jump does. Reach counts facilities, not connections, because a wildcard target is one connection that reaches thousands. How the reach comes matters too: a facility above the cut that has a single connection, much slower than the hubs', is a fallback catch-all and not a supply hub, and is set aside before the cut is taken again (see [Network.inferHubs]).
func (*Network) MeasureCoverage ¶ added in v0.15.0
func (n *Network) MeasureCoverage(cfg Config, q CoverageQuery) (CoverageTable, error)
MeasureCoverage counts, per source, group of targets and order profile, how many targets the source reaches, over which transit times.
It walks connections exactly as reachableFrom does, through the same eachSourceReach, so a row never disagrees with the expectation it stands in for. Connections that depend on an item's category or the recipient's address do not count, as there.
func (*Network) Reach ¶
Reach resolves e for p: which facilities it leads to, if it applies at all.
The rules are the router's, as connections-semantics.md records them: entries combine with AND and the values of one entry with OR; FACILITY and FACILITY_GROUP match the receiving facility; NOT means none of the values may match; a tag the order lacks passes NOT and fails a positive entry.
func (*Network) ReachTo ¶
ReachTo lists every connection from an online source whose target could be the facility at i — it names it, or it is a wildcard of its type — and whether it leads there for p, with the reason. It is the question behind every no-source and peer-coverage finding: which connection should reach this store, and which context entry stops it?
func (*Network) Select ¶
Select is the facilities a selector picks, online or not. OutDegree is the check's business, not the selector's: it is ignored here.
func (*Network) StaticTargets ¶
StaticTargets is the half of Network.Reach that does not depend on the order: the facilities e leads to whenever it applies. It is nil for a CUSTOMER target. A check resolves it once per connection and reuses it for every order profile.
func (*Network) Unread ¶ added in v0.15.0
Unread is the facilities whose connections the snapshot does not hold, because its scope left them out. It is empty for a complete snapshot.
func (*Network) Values ¶
func (n *Network) Values(c ContextEntry) []string
Values is the value list a context entry points at.
type NodeConfig ¶
type NodeConfig struct {
Fences []ConfigItem
Ratings []ConfigItem
PriorityRatings []ConfigItem
Fallback *Fallback
// contains filtered or unexported fields
}
NodeConfig is the part of a node's configuration a check reads.
func Merge ¶
func Merge(path []*StrategyNode) NodeConfig
Merge is the configuration in force at the end of a path: each node's fences and ratings override the ones above it with the same key and add the rest, because "all settings from a previous node are inherited by the next one".
type OfflineSettings ¶ added in v0.12.0
type OfflineSettings struct {
// ClosedSince is the facility field holding the day it closed:
// customAttributes.<key>. A date that has passed is a closed facility, one
// that lies ahead a temporarily offline one.
ClosedSince string `yaml:"closedSince,omitempty" json:"closedSince,omitempty"`
}
OfflineSettings say how offline-ref tells a facility that is gone for good from one that is offline for a while.
type OneOrMany ¶ added in v0.12.0
type OneOrMany []string
OneOrMany is a list of strings that may be written as a single scalar: `orderType: restock` and `orderType: [restock, transfer]` are the same shape.
func (OneOrMany) MarshalJSON ¶ added in v0.12.0
MarshalJSON writes a single value as a string and several as an array, the two forms the file accepts.
func (OneOrMany) MarshalYAML ¶ added in v0.12.0
MarshalYAML writes a single value as a scalar and several as a sequence.
func (*OneOrMany) UnmarshalJSON ¶ added in v0.13.0
UnmarshalJSON reads a string or an array of strings, the two forms OneOrMany.MarshalJSON writes.
type OrderProfile ¶
OrderProfile is a combination of tags that real orders carried, and how many of the sampled orders carried it. It is what "for this kind of order" means.
type PeerGroup ¶
type PeerGroup struct {
Key string `json:"key"`
Size int `json:"size"`
// contains filtered or unexported fields
}
PeerGroup is stores compared with one another: those with one value of the peer field, by default the country.
type PeerSettings ¶
type PeerSettings struct {
// By is a facility field: address.country (the default), address.postalCode
// or customAttributes.<key>.
By string `yaml:"by,omitempty" json:"by,omitempty"`
// MinSize and Share are pointers so that an explicit 0 can be told from
// "not set": a 0 silently replaced by the default would answer a question
// the writer did not ask.
MinSize *int `yaml:"minSize,omitempty" json:"minSize,omitempty"`
}
PeerSettings say which stores are compared with each other.
type PortableEntry ¶ added in v0.15.0
type PortableEntry struct {
Type string `json:"type"`
Operator string `json:"operator,omitempty"`
Values []string `json:"values"`
}
PortableEntry is a context entry with its values in tenant ids, sorted.
type Predicate ¶ added in v0.15.0
type Predicate struct {
// Equals is the one value the field holds: the field has a value, and every
// value it has is this.
Equals *string `yaml:"equals,omitempty" json:"equals,omitempty"`
// Contains is a value the field holds among others. On a scalar it is plain
// equality, never a substring match.
Contains *string `yaml:"contains,omitempty" json:"contains,omitempty"`
// In is the values the field may hold: it has a value, and every value it
// has is listed.
In []string `yaml:"in,omitempty" json:"in,omitempty"`
// Exists says the field has a value. A pointer, so that the file's
// `exists: false`, which the validator refuses, is told apart from the
// predicate being left out.
Exists *bool `yaml:"exists,omitempty" json:"exists,omitempty"`
// NotExists says the field has no value.
NotExists *bool `yaml:"notExists,omitempty" json:"notExists,omitempty"`
}
Predicate is what a facility field must hold, for the `has` of an expectation. Exactly one of its fields is set: the file says what the field must hold, and a second condition on the same field is a second expectation.
The predicates read the field as a list of values, which is what a path with [] yields and what a scalar is a one-element case of. Equals and In say every value is the one named, so they also need a value to be there; Contains says some value is.
func (*Predicate) UnmarshalYAML ¶ added in v0.15.0
UnmarshalYAML reads a predicate and refuses a key it does not know. A custom unmarshaler is outside the decoder's KnownFields, and a misspelt `includes:` would otherwise decode to an empty predicate, which reads as "no predicate".
type Problem ¶
type Problem struct {
// File is the base file the problem is in, when the config extends one, and
// empty for a problem in the config file itself.
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Path string `json:"path,omitempty"`
Message string `json:"message"`
}
Problem is one thing wrong with a config file.
type Profile ¶
type Profile struct {
Tags []TagValue
// Categories are the category ids the order's items are in. Empty means the
// profile does not say, which leaves a CATEGORY entry conditional.
Categories []string
// Recipient is where the order is going. Nil means the profile does not say,
// which leaves the recipient's address entries conditional.
Recipient *Recipient
// Alias is the name the config gives a declared profile, for output to show
// in place of String. It is a label only: String and TagKey leave it out,
// because findings, suppressions and drift tell profiles apart by those, and
// renaming a profile must not turn into a different one.
Alias string
// contains filtered or unexported fields
}
Profile is a kind of order, as far as connections can tell orders apart: the tags it carries and, when the profile declares them, the categories of its items and its recipient's country.
func NewProfile ¶
NewProfile is the profile of an order carrying tags.
func (Profile) String ¶
String is the profile as id=value pairs, the form `fft network reach --tag` takes them in, followed by the categories and the recipient when it declares them: orderType=restock category=A,B recipient.country=DE. Findings, suppressions and report columns tell profiles apart by this string, so it names everything that can change a verdict.
func (Profile) TagKey ¶ added in v0.12.0
TagKey is the profile's tags alone, as Profile.String spells a profile without categories or a recipient. The decision logs only ever record tags, so this is the form a declared profile is compared with a routed one in.
type ProfileCount ¶
ProfileCount is an order profile and how many sampled orders carried it.
type ProfileMatcher ¶ added in v0.12.0
type ProfileMatcher struct {
Tags map[string]OneOrMany
// Categories is nil when the matcher does not name any, and non-nil but empty
// for an explicit empty list, which Validate rejects.
Categories []string
Recipient *Recipient
// contains filtered or unexported fields
}
ProfileMatcher picks order profiles for an expectation: by the tags they carry and, when it says so, by the categories of their items and where their recipient lives. A profile matches when it carries, for every tag the matcher lists, one of the listed values, and carries every listed category, and has the listed recipient country.
A file writes it in either of two forms, the shape DeclaredProfile uses with a list of values allowed per tag:
profiles:
- { orderType: restock } # the plain map: tags only
- tags: { orderType: restock } # the structured form
categories: [CROSSDOCK]
recipient: { country: DE }
The two are told apart by shape, never by guessing at intent, and never so that a file written for the plain form changes meaning. A plain map has only scalar and list values, so a mapping under tags or recipient cannot be a tag value: an entry is the structured form only when every key is one of tags, categories or recipient, each has the shape the form gives it (tags and recipient a mapping, categories a list) and at least one of tags and recipient is present. The last condition is what keeps {categories: [A, B]} a plain matcher on a tag that is literally named "categories", as it was before this form existed. A matcher on categories alone is therefore written with an empty tags, which names no tag and so constrains none:
- tags: {} categories: [CROSSDOCK]
An entry of the structured form that mixes in a key of the plain form is an error that says so. YAML aliases work as a whole entry or as the value of tags, categories or recipient, the shape being judged on what the alias stands for; a merge key (<<) works only in the plain form, which it makes the entry.
func (ProfileMatcher) MarshalJSON ¶ added in v0.13.0
func (m ProfileMatcher) MarshalJSON() ([]byte, error)
MarshalJSON writes the form the matcher was written in.
func (ProfileMatcher) MarshalYAML ¶ added in v0.13.0
func (m ProfileMatcher) MarshalYAML() (any, error)
MarshalYAML writes the form the matcher was written in, so that each form round-trips.
func (ProfileMatcher) Matches ¶ added in v0.12.0
func (m ProfileMatcher) Matches(p Profile) bool
Matches reports whether p carries, for every tag m lists, one of its values, carries every category m lists, and has the recipient country m names.
The tag is matched by id here, unlike a connection's context entry (see [Profile.matches]): the file's author names the tag, and `orderType=restock` must not also select a profile whose `channel` happens to be "restock". Categories and the recipient are properties a profile only has when it declares them, so a profile that does not say matches no matcher that names them: guessing it would put the expectation on a profile it was not written for. An empty matcher matches nothing; validation rejects it.
func (*ProfileMatcher) UnmarshalJSON ¶ added in v0.13.0
func (m *ProfileMatcher) UnmarshalJSON(b []byte) error
UnmarshalJSON reads either form, by the same shape rule as the YAML.
func (*ProfileMatcher) UnmarshalYAML ¶ added in v0.13.0
func (m *ProfileMatcher) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML reads either form; see ProfileMatcher for how it tells them apart.
type ProfileSource ¶
type ProfileSource struct {
// From is "decision-logs" (the default: the tags of the orders the
// snapshot's decision logs routed) or "declared".
From string `yaml:"from,omitempty" json:"from,omitempty"`
// Declared are the profiles, each a map of tag id to value or, to say more
// about the order, an object with tags, categories and recipient, when From
// is "declared".
Declared []DeclaredProfile `yaml:"declared,omitempty" json:"declared,omitempty"`
}
ProfileSource says where the kinds of order come from.
type Reach ¶
type Reach struct {
// Targets are the facilities the connection leads to. Nil for a CUSTOMER
// target, which leads to no facility.
Targets Bitset
Verdict Verdict
// Entry is the index of the context entry that excluded the profile or made
// the connection conditional, or -1.
Entry int
}
Reach is what a connection does for one order profile.
type ReachDiff ¶ added in v0.15.0
type ReachDiff struct {
Source string `json:"source"`
Group string `json:"group"`
Profile string `json:"profile"`
Change string `json:"change"`
// Base and Other carry each side's own Profile string: a declared profile
// names a category by its id, which differs between tenants.
Base *CoverageRow `json:"base"`
Other *CoverageRow `json:"other"`
// OnlyBase are the stores the base reaches and the other does not.
OnlyBase []string `json:"onlyBase"`
OnlyOther []string `json:"onlyOther"`
}
ReachDiff is how one source's reach into one group of stores differs for one kind of order. Base and Other are the coverage rows of each side (without their store lists, which are OnlyBase and OnlyOther), nil on a side that has no such row.
type ReachRow ¶
type ReachRow struct {
Connection string `json:"connection"`
Source string `json:"source"`
Kind Kind `json:"kind"`
Result string `json:"result"`
Entry int `json:"entry"`
Reason string `json:"reason"`
Transit *Transit `json:"transit,omitempty"`
}
ReachRow is one connection that could lead to a facility, and what it does for one order profile.
type Reason ¶
type Reason struct {
Applies bool
Conditional bool
// Entry is the context entry the reason is about, or -1 when it is the
// target's own definition.
Entry int
Why string
}
Reason is why a connection does or does not lead to one facility for one order profile.
type Recipient ¶ added in v0.12.0
type Recipient struct {
Country string `yaml:"country,omitempty" json:"country,omitempty"`
}
Recipient is the part of the final recipient's address a profile declares.
Only the country is here. A TARGET_COUNTRY entry holds country codes, which a profile can state exactly. A TARGET_POSTALCODE entry's values are not documented as exact codes, prefixes or ranges, so fft does not guess: such an entry stays conditional.
type Report ¶
type Report struct {
Roles Roles
Peers []PeerGroup
Profiles []ProfileCount
// Coverage is reported because the outlier rule cannot see a gap most of a
// peer group shares: 20% coverage is no outlier, and is a finding for a
// person to judge.
Coverage []Coverage
Findings []Finding
// Suppressed are the findings a suppression in force accepted. They are
// counted on stderr, so a suppression can never hide that it is hiding.
Suppressed []Finding
// Skipped are the rules, and the expectations, the check could not run, or
// ran on part of the network only, because the snapshot predates what they
// read or its scope left it out. They are named on stderr: a rule that did not
// run found nothing, and the two must not look alike.
Skipped []Skipped
}
Report is a check's result: what it decided about the network, and what it found.
type RoleSelectors ¶
type RoleSelectors struct {
Hub *Selector `yaml:"hub,omitempty" json:"hub,omitempty"`
Store *Selector `yaml:"store,omitempty" json:"store,omitempty"`
Supplier *Selector `yaml:"supplier,omitempty" json:"supplier,omitempty"`
// Custom are the roles a team names itself, such as a webshop. They can be
// the subject of an expectation or the source it asks for, and nothing else:
// the heuristic rules know only the three built-in roles, so a custom role
// never changes what they report.
//
// The inline map is also where a mistyped built-in (stroe:) lands instead of
// failing as an unknown field; Validate and Unmatched catch that.
Custom map[string]*Selector `yaml:",inline" json:"-"`
}
RoleSelectors say which facilities are hubs, stores and suppliers. A nil selector means the default: hubs by relative reach, stores are the other online managed facilities, suppliers the online SUPPLIER facilities.
func (RoleSelectors) IsZero ¶ added in v0.12.0
func (r RoleSelectors) IsZero() bool
IsZero is what makes the JSON tag's omitzero drop an empty roles block.
func (RoleSelectors) MarshalJSON ¶ added in v0.12.0
func (r RoleSelectors) MarshalJSON() ([]byte, error)
MarshalJSON writes the custom roles beside the built-in ones, as the YAML does; encoding/json has no inline maps. A built-in wins a name clash, as it does when the YAML is decoded.
func (*RoleSelectors) UnmarshalJSON ¶ added in v0.12.0
func (r *RoleSelectors) UnmarshalJSON(data []byte) error
UnmarshalJSON reads the flat form MarshalJSON writes.
type Roles ¶
type Roles struct {
Hubs, Stores, Suppliers Bitset
// HubCut is the reach a facility needed to count as a hub, and HubJump the
// factor between it and the next facility down; both zero when the network
// has no hub tier.
HubCut int
HubJump float64
// HubsSetAside are the facilities that reached as far as the hubs and were
// not taken for hubs, because all of that reach came through one slow
// connection. Only an inferred hub tier sets any aside: a pinned one is the
// team's word.
HubsSetAside []HubSetAside
// Custom are the online members of each user-defined role. A facility may be
// in several of them and in a built-in role too. kind ignores them on
// purpose: a custom role must not change what the heuristics report.
Custom map[string]Bitset
}
Roles is what a check decided each facility is.
func (Roles) CustomNames ¶ added in v0.12.0
CustomNames are the user-defined roles in name order.
type Selector ¶
type Selector struct {
// Type is MANAGED_FACILITY or SUPPLIER.
Type string `yaml:"type,omitempty" json:"type,omitempty"`
// Facilities pins the selection to these facilities, by tenant id or
// platform id.
Facilities []string `yaml:"facilities,omitempty" json:"facilities,omitempty"`
// Where matches facility fields: address.country, address.postalCode,
// group (a facility group's id it belongs to), customAttributes.<key>.
Where map[string]string `yaml:"where,omitempty" json:"where,omitempty"`
// OutDegree "relative" selects hubs the way the heuristics do: those whose
// connections reach MinJump times more facilities than the next one's. Only
// a hub selector may say it.
OutDegree string `yaml:"outDegree,omitempty" json:"outDegree,omitempty"`
// MinJump is the ratio the reach heuristic uses: how many times more
// facilities a hub must reach than the next one. With outDegree: relative it
// picks the hubs; with pinned facilities it is the ratio config-drift holds
// the pins against. Only a hub selector may say it.
MinJump float64 `yaml:"minJump,omitempty" json:"minJump,omitempty"`
// NotHubs are facilities reviewed and found not to be hubs, although their
// connections reach as many facilities as a hub's do (one wide connection with
// a long transit time, say). They are never reported as an unpinned hub and
// never counted as one. Only a hub selector may say it.
NotHubs []string `yaml:"notHubs,omitempty" json:"notHubs,omitempty"`
}
Selector picks facilities. Its fields combine with AND; an empty selector picks every facility.
type SetDiff ¶ added in v0.15.0
type SetDiff struct {
Field string `json:"field"`
OnlyBase []string `json:"onlyBase"`
OnlyOther []string `json:"onlyOther"`
}
SetDiff is how one list of a connection differs: the values only one side lists, which is what a reader wants in place of two id dumps.
type Skipped ¶ added in v0.12.0
type Skipped struct {
// Rule is a rule id, or the name of an expectation.
Rule string `json:"rule"`
Reason string `json:"reason"`
// Partial says the rule did run, but not over everything: its findings are
// true, and the part Reason names it never saw.
Partial bool `json:"partial,omitempty"`
}
Skipped is a rule, or an expectation, a check did not run, and why. A rule that cannot run says so: staying silent would read as "nothing found".
type Snapshot ¶
type Snapshot struct {
SchemaVersion int `json:"schemaVersion"`
FFTVersion string `json:"fftVersion"`
CreatedAt time.Time `json:"createdAt"`
Source Source `json:"source"`
// Scope says whose connections the crawl read; empty is everyone's
// ([ScopeAll]). Ask [Snapshot.ConnectionsRead], not this field. It sits with
// the other header fields, ahead of the data, because [ReadHeader] stops at the
// first field that is not one.
Scope string `json:"scope,omitempty"`
Stats Stats `json:"stats"`
Facilities []Facility `json:"facilities"`
Edges []Edge `json:"edges"`
// ValueSets holds every distinct context value list once; a [ContextEntry]
// points into it. A large network repeats the same list of a few hundred
// facility ids on thousands of connections, and interning is what turns
// gigabytes of raw connections into a file that loads in seconds.
ValueSets [][]string `json:"valueSets"`
// Schedules holds every distinct cut-off table, non-delivery table and
// packaging-unit list once, as canonical JSON; an [Edge] points into it. The
// connections of one carrier repeat the same tables by the thousand, so, like
// ValueSets, interning is what keeps the file small.
Schedules []json.RawMessage `json:"schedules,omitempty"`
Groups []Group `json:"groups"`
Tags []Tag `json:"tags"`
// Strategies are the routing strategies as the API returned them. They are
// kept whole, because a strategy's tree is read by rules fft has not written
// yet, and a projection would have to guess which fields those need.
Strategies []json.RawMessage `json:"strategies"`
// Categories are the routing node config categories a strategy's nodes may
// reference. CategoriesRead says the crawl read them, so that an empty list
// is told apart from a snapshot taken before fft read them at all.
Categories []Category `json:"categories,omitempty"`
CategoriesRead bool `json:"categoriesRead,omitempty"`
// ItemCategories are the categories an item is in, which is what a
// connection's CATEGORY entry names, by platform id. The config names one by
// its tenantCategoryId to stay portable between tenants, and these resolve it.
// ItemCategoriesRead says the crawl read them: it is false for a snapshot
// taken before fft did, and for one whose user may not read categories.
ItemCategories []ItemCategory `json:"itemCategories,omitempty"`
ItemCategoriesRead bool `json:"itemCategoriesRead,omitempty"`
DecisionLogs []DecisionLog `json:"decisionLogs"`
OrderProfiles []OrderProfile `json:"orderProfiles"`
}
Snapshot is a network as a crawl found it: every facility, every connection, and what the router needs to explain itself. It is everything `fft network check` reads, so a check never needs the tenant.
func Crawl ¶
Crawl reads the network from the tenant and writes it to o.Out as a snapshot. It only reads; see CrawlOperations.
func (*Snapshot) ConnectionsRead ¶ added in v0.15.0
ConnectionsRead reports whether the crawl read f's connections. Where it did not, the snapshot holds none for f, and that says nothing about the tenant: a rule must not read it as "f has no connections".
func (*Snapshot) HasConnectionDetails ¶ added in v0.12.0
HasConnectionDetails reports whether the crawl read each connection's cut-off times, costs and non-delivery days. A snapshot of format 1 did not, so its connections look as if they had none, and a rule about them must not read that as a finding.
func (*Snapshot) ScopeName ¶ added in v0.15.0
ScopeName is the scope as a person reads it: ScopeAll for a complete snapshot.
type SnapshotDiff ¶ added in v0.15.0
type SnapshotDiff struct {
Base DiffSide `json:"base"`
Other DiffSide `json:"other"`
Facilities []FacilityDiff `json:"facilities"`
Connections []SourceDiff `json:"connections"`
Reach []ReachDiff `json:"reach"`
// Profiles are the kinds of order reach was compared on, by the name a row
// gives them. It is how many a row can be folded over, not part of the
// document.
Profiles []string `json:"-"`
// ReachOnlyBase and ReachOnlyOther are the sources measured on one side only:
// they have no reach row at all on the other. A source that differs in one
// group, or in a group the other side has no stores in, is not one of them.
ReachOnlyBase []string `json:"-"`
ReachOnlyOther []string `json:"-"`
// Skipped is what was not compared, and why. Like a check's, it is for stderr.
Skipped []Skipped `json:"-"`
// Warnings are what made the comparison less certain than it looks, such as
// two facilities of one side sharing a tenant id.
Warnings []string `json:"-"`
}
SnapshotDiff is what differs between two networks, matched by tenant ids: the platform ids of a test tenant and a production tenant have nothing in common, and the tenant's own ids are what its people call things.
func Diff ¶ added in v0.15.0
func Diff(base, other *Network, baseCfg, otherCfg Config, opts DiffOptions) (SnapshotDiff, error)
Diff compares two networks, each read with its own config: roles and declared profiles are resolved against the snapshot they are applied to, which is what lets one file describe two tenants.
A facility is the same facility on both sides when its tenant id is, a group when its tenant group id is, a category when its tenantCategoryId is. A facility with no tenant id is matched by its platform id, which is how one tenant's snapshots, taken at different times, still line up.
func (SnapshotDiff) Empty ¶ added in v0.15.0
func (d SnapshotDiff) Empty() bool
Empty reports whether the two networks do not differ in anything compared.
type SnapshotError ¶
SnapshotError is a snapshot that cannot be read. It exits 3, like a config that cannot be: the command was fine, its input is not.
func (*SnapshotError) Error ¶
func (e *SnapshotError) Error() string
func (*SnapshotError) ExitCode ¶
func (e *SnapshotError) ExitCode() int
ExitCode is 3: the input is unusable.
type Source ¶
Source says which tenant a snapshot came from, so that `--resume` cannot stitch two tenants into one network, and a reader can tell two snapshots apart.
type SourceDiff ¶ added in v0.15.0
type SourceDiff struct {
Source string `json:"source"`
Base int `json:"base"`
Other int `json:"other"`
Connections []ConnectionDiff `json:"connections"`
}
SourceDiff is how one facility's connections differ: how many each side has, and the connections that have no counterpart or differ from it.
type Stats ¶
type Stats struct {
// Duration is the wall-clock time of the run that finished the snapshot; a
// resumed crawl's earlier runs are not in it.
Duration time.Duration `json:"duration"`
// Resumed is how many facilities' connections came from an earlier run.
Resumed int `json:"resumed"`
// Pauses is how often the crawl backed off a throttling gateway.
Pauses int `json:"pauses"`
}
Stats is how the crawl went.
type Strategy ¶
type Strategy struct {
ID string
Name string
InUse bool
Revision int64
Root *StrategyNode
}
Strategy is a routing strategy's tree, decoded for walking. The API writes it as a linked list: a node's children are its nextCondition, that condition's nextCondition, and so on, each leading to its child through nextNode. Strategy turns that into ordered children, keeping the order, because the router takes the first condition that holds.
func ParseStrategy ¶
func ParseStrategy(raw json.RawMessage) (*Strategy, error)
ParseStrategy decodes a strategy as GET /api/routing/strategies answers it.
func (*Strategy) Paths ¶
func (s *Strategy) Paths(fn func(path []*StrategyNode))
Paths calls fn with every path from the root to a node the router can reach at all: through active conditions and active nodes only.
type StrategyCondition ¶
type StrategyCondition struct {
ID string
Name string
Active bool
Frames []TimeFrame
Rule json.RawMessage
Next *StrategyNode
}
StrategyCondition leads from one node to the next when its rule holds.
type StrategyNode ¶
type StrategyNode struct {
ID string
Name string
Active bool
CategoryRef string
Frames []TimeFrame
Config NodeConfig
Conditions []*StrategyCondition
}
StrategyNode is one node: where the router stops when none of its conditions holds, and what configuration it adds on the way.
func (*StrategyNode) Count ¶
func (n *StrategyNode) Count() int
Count is the number of nodes in the subtree under n, n included.
type Suppression ¶
type Suppression struct {
// Rule is a rule id, or the name of an expectation.
Rule string `yaml:"rule" json:"rule"`
// Facility is the finding's subject: a facility's tenant id, the reference
// a dangling-ref finding names, or, for config-drift, an order profile
// such as orderType=express.
Facility string `yaml:"facility,omitempty" json:"facility,omitempty"`
// Where accepts the findings of every facility whose fields match, instead of
// one named facility: customAttributes.kind: technical. Only a rule whose
// subject is a facility can match.
Where map[string]string `yaml:"where,omitempty" json:"where,omitempty"`
// Connection accepts the findings of the connections it describes, for the
// connection-* rules. Their subject is the source, and a decision about a
// kind of connection (every leg into a crossdock is free) is not a decision
// about each source: naming the sources would take one entry per source and
// hide the source's other connections too. Exactly one of Facility, Where and
// Connection is set.
Connection *ConnectionMatch `yaml:"connection,omitempty" json:"connection,omitempty"`
Reason string `yaml:"reason" json:"reason"`
Until Date `yaml:"until" json:"until"`
}
Suppression accepts one finding until a date. It needs a reason, so the next person can judge whether it still holds, and an expiry, so that it is judged.
type Target ¶
type Target struct {
Type string `json:"type"`
FacilityRef string `json:"facilityRef,omitempty"`
ExcludedFacilities []string `json:"excludedFacilityRefs,omitempty"`
ExcludedGroups []string `json:"excludedFacilityGroupRefs,omitempty"`
}
Target is where a connection leads. A MANAGED_FACILITY or SUPPLIER target without a FacilityRef is a wildcard: every facility of that type, narrowed by the exclusions and by the connection's context.
type TimeFrame ¶
type TimeFrame struct {
From string `json:"activeFrom"`
Until string `json:"activeUntil"`
Recurrence string `json:"recurrence"`
}
TimeFrame is an activation time frame. A node or condition applies only within one of its frames, when it has any.
type Verdict ¶
type Verdict uint8
Verdict is whether a connection applies to an order profile.
const ( // Applies: the connection is usable for the profile, to the facilities in // [Reach.Targets]. Applies Verdict = iota // Excluded: a context entry rules the profile out, whatever the facility. Excluded // Conditional: the connection applies only to some orders of the profile — // it depends on an item's category or the recipient's address, which the // profile does not say. It is never counted as coverage, and never as a gap. Conditional )
type View ¶ added in v0.12.0
type View struct {
Project string `json:"project"`
SnapshotAt time.Time `json:"snapshotAt"`
FFTVersion string `json:"fftVersion"`
// Scope is the snapshot's --scope when it left some connections unread.
Scope string `json:"scope,omitempty"`
Counts ViewCounts `json:"counts"`
Decided ViewDecided `json:"decided"`
// Peers are the matrix's rows and Profiles its columns, in the order the
// check uses: largest group first, most common kind of order first.
Peers []ViewPeer `json:"peers"`
Profiles []ViewProfile `json:"profiles"`
// Coverage is one matrix per kind of source, hubs first.
Coverage []CoverageMatrix `json:"coverage"`
// Findings counts the check's findings by rule; Suppressed is how many a
// suppression accepted, shown so that a report cannot hide them either.
Findings map[string]int `json:"findings"`
Suppressed int `json:"suppressed"`
// Skipped are the rules the check could not run on this snapshot, or ran on
// part of it only, whose zero in Findings is not "found nothing".
Skipped []Skipped `json:"skipped,omitempty"`
// Facilities describes every facility the view names, by label.
Facilities map[string]ViewFacility `json:"facilities"`
// Neighbourhoods explains, for the facilities a reader is likely to ask
// about, which connections lead there and why the others do not: the
// --facility ones, every finding's subject, then the stores the coverage
// cells name. Omitted counts the ones MaxFacilities left out; 'fft network
// reach' explains any of them.
Neighbourhoods map[string]Neighbourhood `json:"neighbourhoods"`
Omitted int `json:"omitted,omitempty"`
}
View is what `fft network report` draws, worked out in full here: the page only lays it out, so the picture cannot disagree with the check that the same snapshot and config give.
It holds no wall-clock time. The same snapshot and config give the same view, byte for byte, so two reports can be diffed.
type ViewCounts ¶ added in v0.12.0
type ViewCounts struct {
Facilities int `json:"facilities"`
Online int `json:"online"`
Connections int `json:"connections"`
Hubs int `json:"hubs"`
Stores int `json:"stores"`
Suppliers int `json:"suppliers"`
}
ViewCounts is the size of the network, and of each role in it.
type ViewDecided ¶ added in v0.12.0
type ViewDecided struct {
// Hubs names the hubs, up to MaxMissing of them.
Hubs []string `json:"hubs"`
HubCut int `json:"hubCut,omitempty"`
HubJump float64 `json:"hubJump,omitempty"`
PeerBy string `json:"peerBy"`
// FromFile says a config file decided some of it, rather than inference
// alone.
FromFile bool `json:"fromFile"`
}
ViewDecided is what the check assumed, which every number in the view rests on: which facilities are hubs, how stores are grouped, which kinds of order there are.
type ViewFacility ¶ added in v0.12.0
type ViewFacility struct {
Name string `json:"name,omitempty"`
Type string `json:"type"`
Status string `json:"status"`
Country string `json:"country,omitempty"`
// Rules are the rules with a finding about it, in the check's rule order.
Rules []string `json:"rules,omitempty"`
// ReachArg is the label as 'fft network reach --to' takes it, shell-quoted
// for the line the page offers to paste: a facility id is tenant text.
// Unportable is set when no quoting keeps it intact in every shell.
ReachArg string `json:"reachArg"`
Unportable bool `json:"unportable,omitempty"`
}
ViewFacility describes one facility the view names.
type ViewOptions ¶ added in v0.12.0
type ViewOptions struct {
// FFTVersion is the version of fft that draws the report.
FFTVersion string
// Facilities are explained first, whatever the check found: the ones the
// reader asked for, by index.
Facilities []int
// MaxFacilities caps the neighbourhoods; zero or less is
// DefaultMaxFacilities.
MaxFacilities int
}
ViewOptions is what a view needs that the network does not hold.
type ViewPeer ¶ added in v0.12.0
ViewPeer is one row of the coverage matrix: a peer group of stores.
type ViewProfile ¶ added in v0.12.0
type ViewProfile struct {
Name string `json:"name"`
// Alias is the name the config gives a declared profile, which the page
// shows in place of Name. Name stays the profile's identity: it is the
// string findings and suppressions name it by.
Alias string `json:"alias,omitempty"`
Tags []TagValue `json:"tags"`
// Categories and Recipient are what a declared profile says about its items
// and recipient. They are data here because Name spells them in a string
// that is ambiguous for a category id containing a comma or a space.
Categories []string `json:"categories,omitempty"`
Recipient *Recipient `json:"recipient,omitempty"`
Orders int `json:"orders"`
// ReachFlags is the flags (--tag, --category, --recipient-country) that put
// this kind of order to 'fft network reach', shell-quoted: a tag value is tenant text, and the page shows this
// line for a user to paste. Unportable is set when no quoting keeps a value
// intact in every shell.
ReachFlags string `json:"reachFlags"`
Unportable bool `json:"unportable,omitempty"`
}
ViewProfile is one column of the coverage matrix: a kind of order, and how many routed orders in the snapshot carried it.