history

package
v0.0.0-...-9f7285a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorSortSkipped = errors.New("skipping this sorter for the given resource chunk")

Functions

This section is empty.

Types

type Builder

type Builder struct {
	ClusterResource *resourceinfo.Cluster
	// contains filtered or unexported fields
}

Builder builds History from ChangeSet obtained from parsers.

func NewBuilder

func NewBuilder(ioConfig *ioconfig.IOConfig) *Builder

func (*Builder) Finalize

func (builder *Builder) Finalize(ctx context.Context, serializedMetadata map[string]interface{}, writer io.Writer, progress *progress.TaskProgress) (int, error)

Finalize flushes the binary chunk data and serialized metadata to the given io.Writer. Returns the written data size in bytes and error.

func (*Builder) GetChildResources

func (builder *Builder) GetChildResources(parentResourcePath string) []*Resource

GetChildResources returns the list of ResourceTimeline filtered with the prefix of resource path.

func (*Builder) GetLog

func (builder *Builder) GetLog(logId string) (*SerializableLog, error)

GetLog returns a copy of SerializableLog. Returns an error when the specified logId wasn't found from the list of consumed logs.

func (*Builder) GetTimelineBuilder

func (builder *Builder) GetTimelineBuilder(resourcePath string) *TimelineBuilder

func (*Builder) ParseLogsByGroups

func (builder *Builder) ParseLogsByGroups(ctx context.Context, groupedLogs []*log.LogEntity, logWalker BuilderLogWalker) error

func (*Builder) PrepareParseLogs

func (builder *Builder) PrepareParseLogs(ctx context.Context, entireLogs []*log.LogEntity, onLogPorcessed func()) error

PrepareParseLogs will prepare this builder to be ready to handle parsing logs by groups.

type BuilderLogWalker

type BuilderLogWalker = func(logIndex int, l *log.LogEntity) *ChangeSet

type ChangeSet

type ChangeSet struct {
	// contains filtered or unexported fields
}

history.ChangeSet is set of changes applicable to history. A parser ingest a log.LogEntry and returns a ChangeSet. ChangeSet contains multiple changes against the history. This change is applied atomically, when the parser returns an error, no partial changes would be written.

func NewChangeSet

func NewChangeSet(l *log.LogEntity) *ChangeSet

func (*ChangeSet) FlushToHistory

func (cs *ChangeSet) FlushToHistory(builder *Builder) ([]string, error)

FlushToHistory writes the recorded changeset to the history and returns resource paths where the resource modified.

func (*ChangeSet) GetAllResourcePaths

func (cs *ChangeSet) GetAllResourcePaths() []string

GetAllResourcePaths returns the all of resource paths included in this ChangeSet.

func (*ChangeSet) GetEvents

func (cs *ChangeSet) GetEvents(resourcePath resourcepath.ResourcePath) []*ResourceEvent

GetEvents returns every ResourceEvents at the specified resource path.

func (*ChangeSet) GetLogSummary

func (cs *ChangeSet) GetLogSummary() string

GetLogSummary returns the summary of log to be written with the log.

func (*ChangeSet) GetRevisions

func (cs *ChangeSet) GetRevisions(resourcePath resourcepath.ResourcePath) []*StagingResourceRevision

GetRevisions returns every StagingResourceRevisions at the specified resource path.

func (*ChangeSet) RecordEvent

func (cs *ChangeSet) RecordEvent(resourcePath resourcepath.ResourcePath)

func (*ChangeSet) RecordLogSeverity

func (cs *ChangeSet) RecordLogSeverity(severity enum.Severity)

func (*ChangeSet) RecordLogSummary

func (cs *ChangeSet) RecordLogSummary(summary string)

func (*ChangeSet) RecordResourceAlias

func (cs *ChangeSet) RecordResourceAlias(sourceResourcePath resourcepath.ResourcePath, destResourcePath resourcepath.ResourcePath)

func (*ChangeSet) RecordRevision

func (cs *ChangeSet) RecordRevision(resourcePath resourcepath.ResourcePath, revision *StagingResourceRevision)

type FirstRevisionTimeSortStrategy

type FirstRevisionTimeSortStrategy struct {
	TargetRelationship enum.ParentRelationship
}

func (*FirstRevisionTimeSortStrategy) SortChunk

func (b *FirstRevisionTimeSortStrategy) SortChunk(builder *Builder, parents []*Resource, groupedRelationship enum.ParentRelationship, chunk []*Resource) ([]*Resource, error)

SortChunk implements ResourceChunkSortStrategy.

type History

type History struct {
	Version   string                 `json:"version"`
	Metadata  map[string]interface{} `json:"metadata"`
	Logs      []*SerializableLog     `json:"logs"`
	Timelines []*ResourceTimeline    `json:"timelines"`
	Resources []*Resource            `json:"resources"`
}

The entire inspection data.

func NewHistory

func NewHistory() *History

type LogAnnotation

type LogAnnotation interface {
	Priority() int
	Serialize(builder *binarychunk.Builder) (any, error)
}

type NameSortStrategy

type NameSortStrategy struct {
	PrioritizedKeys []string
	Layer           int
}

func NewNameSortStrategy

func NewNameSortStrategy(layer int, prioritizedKeys []string) *NameSortStrategy

func (*NameSortStrategy) SortChunk

func (n *NameSortStrategy) SortChunk(builder *Builder, parents []*Resource, groupedRelationship enum.ParentRelationship, chunk []*Resource) ([]*Resource, error)

SortChunk implements ResourceChunkSortStrategy.

type Resource

type Resource struct {
	ResourceName     string                  `json:"name"`
	Timeline         string                  `json:"timeline"`
	Relationship     enum.ParentRelationship `json:"relationship"`
	Children         []*Resource             `json:"children"`
	FullResourcePath string                  `json:"path"`
}

type ResourceChunkSortStrategy

type ResourceChunkSortStrategy interface {
	SortChunk(builder *Builder, parents []*Resource, groupedRelationship enum.ParentRelationship, chunk []*Resource) ([]*Resource, error)
}

type ResourceEvent

type ResourceEvent struct {
	Log string `json:"log"`
}

type ResourceReferenceAnnotation

type ResourceReferenceAnnotation struct {
	Path string
}

func NewResourceReferenceAnnotation

func NewResourceReferenceAnnotation(resourcePath string) *ResourceReferenceAnnotation

func (*ResourceReferenceAnnotation) Priority

func (a *ResourceReferenceAnnotation) Priority() int

func (*ResourceReferenceAnnotation) Serialize

func (a *ResourceReferenceAnnotation) Serialize(builder *binarychunk.Builder) (any, error)

type ResourceRevision

type ResourceRevision struct {
	Log        string                       `json:"log"`
	Verb       enum.RevisionVerb            `json:"verb"`
	Requestor  *binarychunk.BinaryReference `json:"requestor"`
	Body       *binarychunk.BinaryReference `json:"body"`
	ChangeTime time.Time                    `json:"changeTime"`
	State      enum.RevisionState           `json:"state"`

	// DEPRECATED: This field is no longer used. Will be removed in near future.
	Partial bool `json:"partial"`
}

type ResourceSorter

type ResourceSorter struct {
	Strategies []ResourceChunkSortStrategy
}

func NewResourceSorter

func NewResourceSorter(strategy ...ResourceChunkSortStrategy) *ResourceSorter

func (*ResourceSorter) SortAll

func (r *ResourceSorter) SortAll(builder *Builder, resources []*Resource) ([]*Resource, error)

type ResourceTimeline

type ResourceTimeline struct {
	ID        string              `json:"id"`
	Revisions []*ResourceRevision `json:"revisions"`
	Events    []*ResourceEvent    `json:"events"`
}

type SerializableLog

type SerializableLog struct {
	// Common fields assigned by log entity
	Timestamp time.Time `json:"ts"`
	// ID is an actual unique ID of this log. This field must be unique. KHI uses `insertId`-`timestamp` for GCP log.
	ID string `json:"id"`
	// Display ID is a log ID directly visible to user. This field no need to be unique. KHI uses `insertId` for GCP log.
	DisplayId string                       `json:"displayId"`
	Body      *binarychunk.BinaryReference `json:"body"`

	// These fields are managed by each parsers
	Type        enum.LogType                 `json:"type"`
	Summary     *binarychunk.BinaryReference `json:"summary"`
	Severity    enum.Severity                `json:"severity"`
	Annotations []any                        `json:"annotations"`
}

type SerializableResourceReferenceAnnotation

type SerializableResourceReferenceAnnotation struct {
	Type string                       `json:"type"`
	Path *binarychunk.BinaryReference `json:"path"`
}

type StagingResourceRevision

type StagingResourceRevision struct {
	Verb      enum.RevisionVerb
	Body      string
	Requestor string
	Partial   bool
	// If this resource existence is inferred from another logs later.
	Inferred   bool
	ChangeTime time.Time
	State      enum.RevisionState
}

type TimelineBuilder

type TimelineBuilder struct {
	// contains filtered or unexported fields
}

An utility class to modify specific resource timeline obtained from history.

func (*TimelineBuilder) AddEvent

func (b *TimelineBuilder) AddEvent(event *ResourceEvent)

func (*TimelineBuilder) AddRevision

func (b *TimelineBuilder) AddRevision(revision *ResourceRevision)

func (*TimelineBuilder) GetLatestRevision

func (b *TimelineBuilder) GetLatestRevision() *ResourceRevision

Get the latest revision stored in a specific ResourceHistory. Returns nil when specified resource was nil or no any revisions recorded.

func (*TimelineBuilder) GetLatestRevisionBody

func (b *TimelineBuilder) GetLatestRevisionBody() (string, error)

func (*TimelineBuilder) Sort

func (b *TimelineBuilder) Sort()

type UnreachableSortStrategy

type UnreachableSortStrategy struct {
}

UnreachableSortStrategy is the default sort strategy catches all. Hitting this sorter is unexpected but implemented not to crush because of bad output from parsers.

func (*UnreachableSortStrategy) SortChunk

func (u *UnreachableSortStrategy) SortChunk(builder *Builder, parents []*Resource, groupedRelationship enum.ParentRelationship, chunk []*Resource) ([]*Resource, error)

SortChunk implements ResourceChunkSortStrategy.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL