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 IsNotExist(err error) bool
- func RuleIDs() []string
- func Save(path string, s *Snapshot) error
- type Bitset
- type Category
- type Config
- type ConfigError
- type ConfigItem
- type ContextEntry
- type Coverage
- type CrawlError
- type CrawlOptions
- type Date
- type DecisionLog
- type Edge
- type ExpectFor
- type ExpectFrom
- type Expectation
- type Facility
- type Fallback
- type File
- type Finding
- type Group
- type Kind
- type LoadedFile
- 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) 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) Values(c ContextEntry) []string
- type NodeConfig
- type OrderProfile
- type PeerGroup
- type PeerSettings
- type Problem
- type Profile
- type ProfileCount
- type ProfileSource
- type Reach
- type ReachRow
- type Reason
- type Report
- type RoleSelectors
- type Roles
- type Selector
- type Snapshot
- type SnapshotError
- type Source
- type Stats
- type Strategy
- type StrategyCondition
- type StrategyNode
- type Suppression
- type Tag
- type TagValue
- type Target
- type TimeFrame
- type Transit
- type Verdict
Constants ¶
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 ( ProfilesFromDecisionLogs = "decision-logs" ProfilesDeclared = "declared" )
The profile sources.
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 ( ResultApplies = "applies" ResultConditional = "conditional" ResultExcluded = "excluded" )
The results a reach row can have.
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 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 JournalSuffix = ".partial.jsonl"
JournalSuffix is appended to a snapshot's path to name the journal of the crawl writing it.
const OutDegreeRelative = "relative"
OutDegreeRelative is the one OutDegree a selector may name.
const SchemaVersion = 1
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.
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",
"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 eight kinds of request, and the read-only gate, which reads one annotation per command, cannot see seven of them.
Functions ¶
func IsNotExist ¶
IsNotExist reports whether err is a config file that is not there.
Types ¶
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 Category ¶
type Category struct {
ID string `json:"id"`
}
Category is a routing node config category.
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.
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
// Declared replaces the inferred order profiles, when set.
Declared [][]TagValue
Expect []Expectation
// Suppress are the suppressions still in force.
Suppress []Suppression
}
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 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 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 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
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 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"`
}
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" json:"role"`
AtLeast int `yaml:"atLeast" json:"atLeast"`
// 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"`
}
ExpectFrom is what must reach them.
type Expectation ¶
type Expectation struct {
Name string `yaml:"name" json:"name"`
For ExpectFor `yaml:"for" json:"for"`
ReachableFrom ExpectFrom `yaml:"reachableFrom" json:"reachableFrom"`
}
Expectation is an invariant the team declares: every store a selector picks is reachable from at least AtLeast sources of a role.
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 Fallback ¶
type Fallback struct {
Active bool `json:"active"`
Facilities []string `json:"facilityRefs"`
After string `json:"fallbackAfterTime"`
}
Fallback is a node's fallback facility.
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"`
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"`
}
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 LoadedFile ¶
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.
func ReadConfig ¶
func ReadConfig(path string) (*LoadedFile, error)
ReadConfig reads and checks a config file. 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) 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) 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 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.
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) 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 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 Problem ¶
type Problem struct {
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
// contains filtered or unexported fields
}
Profile is a kind of order, as far as connections can tell orders apart: the tags it carries.
func NewProfile ¶
NewProfile is the profile of an order carrying tags.
type ProfileCount ¶
ProfileCount is an order profile and how many sampled orders carried it.
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, when From is
// "declared".
Declared []map[string]string `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 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 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
}
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"`
}
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.
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
}
Roles is what a check decided each facility is.
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 float64 `yaml:"minJump,omitempty" json:"minJump,omitempty"`
}
Selector picks facilities. Its fields combine with AND; an empty selector picks every facility.
type Snapshot ¶
type Snapshot struct {
SchemaVersion int `json:"schemaVersion"`
FFTVersion string `json:"fftVersion"`
CreatedAt time.Time `json:"createdAt"`
Source Source `json:"source"`
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"`
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"`
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.
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 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" json:"facility"`
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 a tag // profile does not say. It is never counted as coverage, and never as a gap. Conditional )