Documentation
¶
Overview ¶
Inventory tasks defined in this file provide a framework for discovering and merging inventory data from various sources.
In many inspection scenarios, it's necessary to associate information across different log sources. For example, a log might contain an IP address, while another log maps that IP to a specific VM or container name.
This framework introduces a demand-driven approach:
- Discovery Tasks: Extract inventory data from individual sources and publish it via coretask.ProvidesTag(tag).
- Inventory Tasks: Demand-driven aggregators created via DefineInventoryTask, which use tag references (coretask.FromActiveFeatures) to pull in and merge data only from producers whose prerequisite data sources are active.
Index ¶
- Variables
- func DefineCachedTask[T any](taskID taskid.TaskImplementationID[T], ...) coretask.Task[T]
- func DefineGroupedLogIngesterTask[T any](taskID taskid.TaskImplementationID[struct{}], ...) coretask.Task[struct{}]
- func DefineInspectionTask[T any](id taskid.TaskImplementationID[T], ...) coretask.Task[T]
- func DefineInventoryTask[T any, R any](id taskid.TaskImplementationID[R], tag coretask.Tag[T], ...) coretask.Task[R]
- func DefineLogFilterTask(taskID taskid.TaskImplementationID[[]*log.Log], ...) coretask.Task[[]*log.Log]
- func DefineLogGrouperTask(taskID taskid.TaskImplementationID[LogGroupMap], ...) coretask.Task[LogGroupMap]
- func DefineLogIngesterTask(taskID taskid.TaskImplementationID[struct{}], ...) coretask.Task[struct{}]
- func DefineLogToTimelineMapperTask[T any](tid taskid.TaskImplementationID[struct{}], inputs TimelineMapperInputs, ...) coretask.Task[struct{}]
- type CacheScope
- type CachedTaskSpec
- type GroupedLogIngester
- type InspectionTaskFunc
- type LogFilterFunc
- type LogGroup
- type LogGroupMap
- type LogGrouperFunc
- type LogIngesterFunc
- type SinglePassGroupedIngesterBase
- type SinglePassMapperBase
- type StatelessMapperBase
- type TimelineMapper
- type TimelineMapperInputs
Constants ¶
This section is empty.
Variables ¶
var ( // TagLogIngester is the tag provided by tasks that ingest logs into KHI v6 format. TagLogIngester = coretask.NewTag[struct{}]("khi.google.com/task/inspection/log-ingester") // TagTimelineMapper is the tag provided by tasks that map logs to timeline elements. TagTimelineMapper = coretask.NewTag[struct{}]("khi.google.com/task/inspection/timeline-mapper") )
Functions ¶
func DefineCachedTask ¶ added in v0.60.1
func DefineCachedTask[T any](taskID taskid.TaskImplementationID[T], bind func(b *coretask.Binder) CachedTaskSpec[T], labelOpts ...coretask.LabelOpt) coretask.Task[T]
DefineCachedTask defines a task with a Binder that reuses the previously computed value while the digest of its inputs is unchanged. bind declares the inputs on the Binder and returns the spec whose functions read them. Only the latest value is kept.
func DefineGroupedLogIngesterTask ¶ added in v0.60.1
func DefineGroupedLogIngesterTask[T any](taskID taskid.TaskImplementationID[struct{}], groupedLogTask taskid.TaskReference[LogGroupMap], bind func(b *coretask.Binder) GroupedLogIngester[T], labelOpts ...coretask.LabelOpt) coretask.Task[struct{}]
DefineGroupedLogIngesterTask returns a task that ingests metadata of the logs grouped by groupedLogTask into the KHI v6 builder using group-sequential processing.
The task registers groupedLogTask on the Binder before calling bind. bind is called once at task definition time to declare additional inputs and return the GroupedLogIngester[T] instance. Because the returned GroupedLogIngester[T] is shared across inspections and concurrent worker goroutines, any per-group mutable state must be stored in T rather than on the ingester struct.
func DefineInspectionTask ¶ added in v0.60.1
func DefineInspectionTask[T any](id taskid.TaskImplementationID[T], bind func(b *coretask.Binder) InspectionTaskFunc[T], labelOpts ...coretask.LabelOpt) coretask.Task[T]
DefineInspectionTask creates an inspection task whose inputs are declared through a coretask.Binder. bind declares the inputs with coretask.Use and related functions and returns the task function that receives the task mode from the context.
func DefineInventoryTask ¶ added in v0.60.1
func DefineInventoryTask[T any, R any]( id taskid.TaskImplementationID[R], tag coretask.Tag[T], mergeFunc func(results []T) (R, error), labelOpts ...coretask.LabelOpt, ) coretask.Task[R]
DefineInventoryTask defines an inventory task that dynamically discovers and aggregates outputs from all producer tasks that provide the specified tag within active features. The tag input is declared on a Binder.
func DefineLogFilterTask ¶ added in v0.60.1
func DefineLogFilterTask(taskID taskid.TaskImplementationID[[]*log.Log], sourceLogs taskid.TaskReference[[]*log.Log], bind func(b *coretask.Binder) LogFilterFunc, labelOpts ...coretask.LabelOpt) coretask.Task[[]*log.Log]
DefineLogFilterTask creates a task that returns only the logs provided by sourceLogs that the filter function returned by bind keeps. bind declares the additional inputs the filter reads, and the task declares sourceLogs itself.
func DefineLogGrouperTask ¶ added in v0.60.1
func DefineLogGrouperTask(taskID taskid.TaskImplementationID[LogGroupMap], logTask taskid.TaskReference[[]*log.Log], bind func(b *coretask.Binder) LogGrouperFunc, labelOpts ...coretask.LabelOpt) coretask.Task[LogGroupMap]
DefineLogGrouperTask creates a task that groups the logs provided by logTask with the grouper function returned by bind. bind declares the additional inputs the grouper reads, and the task declares logTask itself.
func DefineLogIngesterTask ¶ added in v0.60.1
func DefineLogIngesterTask(taskID taskid.TaskImplementationID[struct{}], rawLogTask taskid.TaskReference[[]*log.Log], bind func(b *coretask.Binder) LogIngesterFunc, labelOpts ...coretask.LabelOpt) coretask.Task[struct{}]
DefineLogIngesterTask returns a task that ingests metadata of the logs provided by rawLogTask into the KHI v6 builder.
The task registers rawLogTask on the Binder before calling bind. bind is called once at task definition time to declare additional inputs and return the LogIngesterFunc that processes each log concurrently across worker goroutines.
func DefineLogToTimelineMapperTask ¶ added in v0.60.1
func DefineLogToTimelineMapperTask[T any](tid taskid.TaskImplementationID[struct{}], inputs TimelineMapperInputs, bind func(b *coretask.Binder) TimelineMapper[T], labelOpts ...coretask.LabelOpt) coretask.Task[struct{}]
DefineLogToTimelineMapperTask creates a task that modifies the KHI v6 TimelineRegistry based on the logs grouped by inputs.GroupedLogs.
inputs specifies the log ingester the mapper waits for and the grouped log task it reads; DefineLogToTimelineMapperTask registers both on the Binder before calling bind. bind is called once at task definition time to declare additional inputs and return the TimelineMapper[T] instance. Because the returned TimelineMapper[T] is shared across inspections and concurrent worker goroutines, any per-group mutable state must be stored in T rather than on the mapper struct.
Types ¶
type CacheScope ¶ added in v0.60.1
type CacheScope int
CacheScope is the lifetime of the value cached by a task defined with DefineCachedTask.
const ( // CacheScopeInspection keeps the cached value in InspectionSharedMap, so it is reused across dry runs and the run of the same inspection. // This is the zero value and the default. // To release resources when the inspection finishes, register a cleanup callback on khictx.MustGetValue(ctx, inspectioncore.InspectionContext) using context.AfterFunc inside Compute. CacheScopeInspection CacheScope = iota // CacheScopeGlobal keeps the cached value in GlobalSharedMap, so it is reused across inspections. CacheScopeGlobal )
type CachedTaskSpec ¶ added in v0.60.1
type CachedTaskSpec[T any] struct { // Scope is the lifetime of the cached value. The zero value caches the value per inspection. Scope CacheScope // InputDigest returns a string that identifies the inputs. Compute runs only when it differs from the digest of the cached value. InputDigest func(ctx context.Context) string // Compute computes the value from the inputs. An error is returned from the task and is not cached. Compute func(ctx context.Context) (T, error) }
CachedTaskSpec holds the cache scope and the functions of a task defined with DefineCachedTask.
type GroupedLogIngester ¶ added in v0.56.7
type GroupedLogIngester[T any] interface { // PassCount returns the number of pre-processing passes to perform on each group. PassCount() int // PreProcessLogByGroup is called during a pre-processing pass for each log in a group. // The passIndex is 0-indexed and ranges from 0 to PassCount()-1. PreProcessLogByGroup(ctx context.Context, passIndex int, l *log.Log, prevGroupData T) (T, error) // ProcessLogByGroup is called for each log entry in a group to customize log metadata. // The prevGroupData is the returned value from the last processed log in the same group. ProcessLogByGroup(ctx context.Context, l *log.Log, prevGroupData T) (*khifilev6.LogChangeSet, T, error) }
GroupedLogIngester defines the interface for ingesting log metadata into KHI v6 format using group-sequential processing.
type InspectionTaskFunc ¶
type InspectionTaskFunc[T any] = func(ctx context.Context, taskMode inspectioncore.InspectionTaskModeType) (T, error)
InspectionTaskFunc is a type for inspection task functions.
type LogFilterFunc ¶
LogFilterFunc defines the function signature for filtering logs. It returns true if the log should be kept.
type LogGroupMap ¶
LogGroupMap is a map of log groups, where the key is the group identifier.
type LogGrouperFunc ¶ added in v0.50.0
LogGrouperFunc defines a function that returns a group key for a given log.
type LogIngesterFunc ¶ added in v0.60.1
LogIngesterFunc converts a log into the change set of its metadata, such as summary, severity, and timestamp. It returns a nil change set to skip the log.
type SinglePassGroupedIngesterBase ¶ added in v0.56.0
type SinglePassGroupedIngesterBase[T any] struct{}
SinglePassGroupedIngesterBase provides a base implementation of GroupedLogIngester for ingesters that only require a single pass over the logs.
func (SinglePassGroupedIngesterBase[T]) PassCount ¶ added in v0.56.0
func (SinglePassGroupedIngesterBase[T]) PassCount() int
PassCount returns 0 as no pre-processing pass is required.
func (SinglePassGroupedIngesterBase[T]) PreProcessLogByGroup ¶ added in v0.56.0
func (SinglePassGroupedIngesterBase[T]) PreProcessLogByGroup(ctx context.Context, passIndex int, l *log.Log, prevGroupData T) (T, error)
PreProcessLogByGroup is a no-op pre-processor that returns the state as-is.
type SinglePassMapperBase ¶ added in v0.56.0
type SinglePassMapperBase[T any] struct{}
SinglePassMapperBase provides a base implementation of TimelineMapper for mappers that only require a single pass over the logs.
func (SinglePassMapperBase[T]) PassCount ¶ added in v0.56.0
func (SinglePassMapperBase[T]) PassCount() int
PassCount returns 0 as no pre-processing pass is required.
func (SinglePassMapperBase[T]) PreProcessLogByGroup ¶ added in v0.56.0
func (SinglePassMapperBase[T]) PreProcessLogByGroup(ctx context.Context, passIndex int, l *log.Log, prevGroupData T) (T, error)
PreProcessLogByGroup is a no-op pre-processor that returns the state as-is.
type StatelessMapperBase ¶ added in v0.56.0
type StatelessMapperBase struct{}
StatelessMapperBase provides a base implementation of TimelineMapper for mappers that are both stateless and only require a single pass.
func (StatelessMapperBase) PassCount ¶ added in v0.56.0
func (StatelessMapperBase) PassCount() int
PassCount returns 0 as no pre-processing pass is required.
func (StatelessMapperBase) PreProcessLogByGroup ¶ added in v0.56.0
func (StatelessMapperBase) PreProcessLogByGroup(ctx context.Context, passIndex int, l *log.Log, prevGroupData struct{}) (struct{}, error)
PreProcessLogByGroup is a no-op pre-processor that returns an empty struct.
type TimelineMapper ¶ added in v0.60.1
type TimelineMapper[T any] interface { // PassCount returns the number of pre-processing passes to perform on each group. PassCount() int // PreProcessLogByGroup is called during a pre-processing pass for each log in a group. // The passIndex is 0-indexed and ranges from 0 to PassCount()-1. PreProcessLogByGroup(ctx context.Context, passIndex int, l *log.Log, prevGroupData T) (T, error) // ProcessLogByGroup is called for each log entry to stage mutations via TimelineChangeSet. // The prevGroupData is the returned value from the last processed log in the same group. ProcessLogByGroup(ctx context.Context, l *log.Log, prevGroupData T) (*khifilev6.TimelineChangeSet, T, error) }
TimelineMapper maps the logs of each log group to timeline elements (events or revisions) in KHI file v6 format. T is the state passed from one log to the next log in the same group.
type TimelineMapperInputs ¶ added in v0.60.1
type TimelineMapperInputs struct {
// LogIngester is the task that must ingest the log metadata before the mapper runs. The mapper does not read its value.
LogIngester taskid.TaskReference[struct{}]
// GroupedLogs is the task that provides the logs to map, grouped by the unit processed sequentially.
GroupedLogs taskid.TaskReference[LogGroupMap]
}
TimelineMapperInputs specifies the log ingester the mapper waits for and the grouped log task it reads. DefineLogToTimelineMapperTask registers both on the Binder before calling bind.