Documentation
¶
Overview ¶
Package util offers helpers and building blocks to easily generate payloads for the inventory product.
Usage: When creating a new payload for the inventory product, one should only embed the 'InventoryPayload' struct and provide it with a callback to generate a payload.
Example:
type customPayload struct {
InventoryPayload
}
type dependencies struct {
fx.In
Log log.Component
Config config.Component
Serializer serializer.MetricSerializer
}
type provides struct {
fx.Out
Comp Component
Provider runner.Provider
FlareProvider flaretypes.Provider
}
func newCustomPayload(deps dependencies) provides {
cp := &customPayload{
InventoryPayload: CreateInventoryPayload(
deps.Config,
deps.Log,
deps.Serializer,
cp.getPayload,
"custom.json",
),
}
return provides{
Comp: cp,
Provider: cp.MetadataProvider(),
FlareProvider: cp.FlareProvider(),
}
}
func (cp *customPayload) getPayload() marshaler.JSONMarshaler { ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InventoryEnabled ¶
InventoryEnabled returs true if 'enable_metadata_collection' and 'inventories_enabled' are set to true in the configuration.
Types ¶
type InventoryPayload ¶
type InventoryPayload struct {
Enabled bool
LastCollect time.Time
MinInterval time.Duration
MaxInterval time.Duration
FlareFileName string
// contains filtered or unexported fields
}
InventoryPayload offers helpers for all inventory payloads providing all the common part to create a new payload. InventoryPayload will handle the common configuration as well as refresh rates and flare. This type is meant to be embedded.
Embedding type need to provide a PayloadGetter callback when calling Init. This callback will be called each time a new payload need to be generated.
Scrubbing responsibility ¶
InventoryPayload owns flare scrubbing: FlareProvider applies ScrubJSON (structured JSON scrubbing by key name) before writing the payload file. Callers do not need to scrub simple scalar fields.
Exception: callers that store YAML content as JSON string values (e.g. check init_config or instance_config) must pre-scrub those strings with scrubber.ScrubYamlString before storing them, because ScrubJSON operates on JSON key names and cannot reach inside opaque string values.
func CreateInventoryPayload ¶
func CreateInventoryPayload(conf config.Component, l log.Component, s serializer.MetricSerializer, getPayload PayloadGetter, flareFileName string) InventoryPayload
CreateInventoryPayload returns an initialized InventoryPayload. 'getPayload' will be called each time a new payload needs to be generated.
func (*InventoryPayload) FlareProvider ¶
func (i *InventoryPayload) FlareProvider() flaretypes.Provider
FlareProvider returns a flare providers to add the current inventory payload to each flares.
func (*InventoryPayload) GetAsJSON ¶
func (i *InventoryPayload) GetAsJSON() ([]byte, error)
GetAsJSON returns the payload as a JSON string. Useful to be displayed in the CLI or added to a flare.
func (*InventoryPayload) MetadataProvider ¶
func (i *InventoryPayload) MetadataProvider() runnerdef.Provider
MetadataProvider returns a metadata 'runner.Provider' for the current inventory payload (taking into account if invnetory is enabled or not).
func (*InventoryPayload) Refresh ¶
func (i *InventoryPayload) Refresh()
Refresh trigger a new payload to be send while still respecting the minimal interval between two updates.
func (*InventoryPayload) RefreshTriggered ¶
func (i *InventoryPayload) RefreshTriggered() bool
RefreshTriggered returns true if a refresh was trigger but not yet done.
type PayloadGetter ¶
type PayloadGetter func() marshaler.JSONMarshaler
PayloadGetter is the callback to generate a new payload exposed by each inventory payload to InventoryPayload utils