Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var InspectionTimeProducer common_task.Task[time.Time] = common_task.NewTask(inspectioncore.InspectionTimeTaskID, []common_task.Dependency{}, func(ctx context.Context) (time.Time, error) { return time.Now(), nil })
InspectionTimeProducer is a provider of inspection time. Tasks shouldn't use time.Now() directly to make test easier.
var JobModeCommandTask = inspectiontaskbase.NewInspectionTask( JobModeCommandTaskID, []coretask.Dependency{}, func(ctx context.Context, taskMode inspectioncore.InspectionTaskModeType) (any, error) { metadataSet := khictx.MustGetValue(ctx, inspectionmetadata.MapContextKey) jobMetadata, found := typedmap.Get(metadataSet, inspectionmetadata.JobModeCommandMetadataKey) if !found { return nil, fmt.Errorf("job command metadata not found") } enabledFeatures, err := khictx.GetValue(ctx, inspectioncore.InspectionTaskEnabledFeatures) if err != nil { return nil, err } inspectionType := khictx.MustGetValue(ctx, inspectioncore.InspectionTaskType) taskInput := khictx.MustGetValue(ctx, inspectioncore.InspectionTaskInput) formFields, found := typedmap.Get(metadataSet, inspectionmetadata.FormFieldSetMetadataKey) if !found { return nil, fmt.Errorf("form field metadata not found") } fileFieldIDs := formFields.GetFileFieldIDs() command, err := GenerateJobModeCommand(inspectionType, enabledFeatures, taskInput, fileFieldIDs) if err != nil { return nil, err } jobMetadata.SetCommand(command) return nil, nil }, )
JobModeCommandTask calculates the job mode command example and populates it into the metadata map.
var JobModeCommandTaskID = taskid.NewDefaultImplementationID[any](inspectioncore.InspectionTaskPrefix + "job-command")
JobModeCommandTaskID defines the unique ID of the JobModeCommandTask.
var SerializeTask = inspectiontaskbase.NewInspectionTask( inspectioncore.SerializerTaskID, []coretask.Dependency{ JobModeCommandTaskID.Ref(), inspectiontaskbase.TagLogIngester.Ref(), inspectiontaskbase.TagTimelineMapper.Ref(), }, func(ctx context.Context, taskMode inspectioncore.InspectionTaskModeType) (*inspectioncore.FileSystemStore, error) { if taskMode == inspectioncore.TaskModeDryRun { slog.DebugContext(ctx, "Skipping because this is in dryrun mode") return nil, nil } inspectionID := khictx.MustGetValue(ctx, inspectioncore.InspectionTaskInspectionID) metadataSet := khictx.MustGetValue(ctx, inspectionmetadata.MapContextKey) ioConfig := khictx.MustGetValue(ctx, inspectioncore.CurrentIOConfig) builder := khictx.MustGetValue(ctx, inspectioncore.Builder) for _, key := range metadataSet.Keys() { metadata, found := typedmap.Get(metadataSet, inspectionmetadata.NewMetadataLabelsKey[inspectionmetadata.Metadata](key)) if !found { return nil, fmt.Errorf("expected metadata not found: %s", key) } if err := builder.MetadataAccumulator.AddMetadata(metadata); err != nil { return nil, err } } store := inspectioncore.NewFileSystemInspectionResultRepository(filepath.Join(ioConfig.DataDestination, inspectionID+".khi")) if err := builder.Build(ctx); err != nil { return nil, err } fileSize, err := store.GetInspectionResultSizeInBytes() if err != nil { return nil, err } header, found := typedmap.Get(metadataSet, inspectionmetadata.HeaderMetadataKey) if found { header.FileSize = fileSize } return store, nil }, coretask.NewTaskResultRetentionLabel(true), coretask.NewRequiredTaskLabel(), )
SerializeTask is a subsequent task that must be included in the task graph after tasks like TimelineMapper and LogIngester. It retrieves the Builder instance populated by its preceding tasks and serializes its accumulated contents into the final KHI file.
var TestInspectionTimeTaskProducer func(timeStr string) common_task.Task[time.Time] = func(timeStr string) common_task.Task[time.Time] { return common_task.NewTask(inspectioncore.InspectionTimeTaskID, []common_task.Dependency{}, func(ctx context.Context) (time.Time, error) { t, err := time.Parse(time.RFC3339, timeStr) if err != nil { return time.Time{}, err } return t, nil }) }
TestInspectionTimeTaskProducer is a function to generate a fake InspectionTimeProducer task with the given time string.
var TimeZoneShiftInputTask = inspectiontaskbase.NewInspectionTask(inspectioncore.TimeZoneShiftInputTaskID, []coretask.Dependency{}, func(ctx context.Context, taskMode inspectioncore.InspectionTaskModeType) (*time.Location, error) { req := khictx.MustGetValue(ctx, inspectioncore.InspectionTaskInput) if tzShiftAny, found := req[inspectioncore.TaskInputKeyTimezoneShiftHours]; found { if tzShiftFloat, convertible := tzShiftAny.(float64); convertible && tzShiftFloat != 0 { return time.FixedZone("Unknown", int(tzShiftFloat*3600)), nil } } return time.UTC, nil })
Functions ¶
func GenerateJobModeCommand ¶ added in v0.56.6
func GenerateJobModeCommand(inspectionType string, enabledFeatures []string, taskInput map[string]any, fileFieldIDs []string) (string, error)
GenerateJobModeCommand formats a copy-pasteable command to execute KHI in job mode.
func Register ¶
func Register(registry coretask.TaskRegistry) error
Types ¶
This section is empty.