testvariantbranch

package
v0.0.0-...-1c50ca4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testvariantbranch handles test variant branch of change point analysis.

Index

Constants

View Source
const (

	// StatisticsRetentionDays is the number of days to keep statistics about
	// evicted verdicts. See Statistics proto for more.
	//
	// This is a minimum period driven by functional and operational requirements,
	// our deletion logic will tend to keep retain data for longer (but this is
	// OK as it is not user data).
	StatisticsRetentionDays = 11
)

Variables

This section is empty.

Functions

func AddCounts

func AddCounts(count1 *cpb.Counts, count2 *cpb.Counts) *cpb.Counts

AddCounts returns the sum of 2 statistics counts.

func DecodeProtoMessage

func DecodeProtoMessage(bytes []byte, m proto.Message) error

DecodeProtoMessage decodes a byte slice into a proto message. It is the inverse of EncodeProtoMessage.

func DecodeSegment

func DecodeSegment(bytes []byte) (*cpb.Segment, error)

DecodeSegment decodes []byte in to Segment.

func DecodeSegments

func DecodeSegments(bytes []byte) (*cpb.Segments, error)

DecodeSegments decodes []byte in to Segments.

func DecodeSourceRef

func DecodeSourceRef(bytes []byte) (*pb.SourceRef, error)

DecodeSourceRef decodes []byte in to SourceRef.

func DecodeStatistics

func DecodeStatistics(bytes []byte) (*cpb.Statistics, error)

DecodeStatistics decodes []byte into a Statistics proto.

func EncodeProtoMessage

func EncodeProtoMessage(m proto.Message) ([]byte, error)

EncodeProtoMessage uses zstd to encode a proto message into []byte.

func EncodeSegment

func EncodeSegment(seg *cpb.Segment) ([]byte, error)

func EncodeSegments

func EncodeSegments(segs *cpb.Segments) ([]byte, error)

func EncodeSourceRef

func EncodeSourceRef(sourceRef *pb.SourceRef) ([]byte, error)

func EncodeStatistics

func EncodeStatistics(stats *cpb.Statistics) ([]byte, error)

func ReadF

func ReadF(ctx context.Context, ks []Key, f func(i int, e *Entry) error) error

ReadF fetches rows from TestVariantBranch spanner table and calls the specified callback function for each row.

Important: The caller must not retain a reference to the provided *Entry after each call, as the object may be re-used for in the next call. If an entry must be retained, it should be copied.

The callback function will be passed the read row and the corresponding index in the key list that was read. If an item does not exist, the provided callback function will be called with the value 'nil'. Absent any errors, the callback function will be called exactly once for each key. The callback function may not be called in order of keys, as Spanner does not return items in order.

This function assumes that it is running inside a transaction.

func ToPositionVerdict

func ToPositionVerdict(tv *rdbpb.TestVariant, payload *taskspb.IngestTestVerdicts, duplicateMap map[string]bool, src *pb.Sources) (inputbuffer.PositionVerdict, error)

Types

type Entry

type Entry struct {
	// IsNew is a boolean to denote if the TestVariantBranch is new or already
	// existed in Spanner.
	// It is used for reducing the number of mutations. For example, the Variant
	// field is only inserted once.
	IsNew       bool
	Project     string
	TestID      string
	VariantHash string
	Variant     *pb.Variant
	RefHash     []byte
	SourceRef   *pb.SourceRef
	InputBuffer *inputbuffer.Buffer
	// If this is true, it means we should trigger a write of FinalizingSegment
	// to Spanner.
	IsFinalizingSegmentDirty bool
	// The finalizing segment, if any.
	// The count for the finalizing segment should only include the verdicts
	// that are not in the input buffer anymore.
	FinalizingSegment *cpb.Segment
	// If this is true, it means we should trigger a write of FinalizedSegments
	// to Spanner.
	IsFinalizedSegmentsDirty bool
	// The finalized segments for the test variant branch.
	FinalizedSegments *cpb.Segments
	// If true, it means we should trigger a write of Statistics to Spanner.
	IsStatisticsDirty bool
	// Statistics about verdicts which have been evicted from the input buffer.
	Statistics *cpb.Statistics
}

Entry represents one row in the TestVariantBranch spanner table. See go/luci-test-variant-analysis-design for details.

func New

func New() *Entry

New creates a new empty test variant branch entry, with a preallocated input buffer.

func Read

func Read(ctx context.Context, ks []Key) ([]*Entry, error)

Read fetches rows from TestVariantBranch spanner table and returns the objects fetched. The returned slice will have the same length and order as the TestVariantBranchKey slices. If a record is not found, the corresponding element will be set to nil. This function assumes that it is running inside a transaction.

func (*Entry) ApplyRetentionPolicyForFinalizedSegments

func (tvb *Entry) ApplyRetentionPolicyForFinalizedSegments(fromTime time.Time)

ApplyRetentionPolicyForFinalizedSegments applies retention policy to finalized segments. The following retention policy applies to finalized segments:

  • At most 100 finalized segments can be stored.
  • Finalized segments are retained for 5 years from when they closed.

fromTime is the time when the 5 year period is calculated from.

The retention policy to delete test variant branches without test results in 90 days will be enforced separately with a cron job.

func (*Entry) Clear

func (tvb *Entry) Clear()

Clear resets a test variant branch entry to an empty state, similar to after a call to New().

func (*Entry) Copy

func (tvb *Entry) Copy() *Entry

Copy makes a deep copy of a test variant branch entry.

func (*Entry) InsertFinalizedSegment

func (tvb *Entry) InsertFinalizedSegment(segment *cpb.Segment)

InsertFinalizedSegment inserts a segment to the end of finalized segments.

func (*Entry) InsertToInputBuffer

func (tvb *Entry) InsertToInputBuffer(pv inputbuffer.PositionVerdict)

InsertToInputBuffer inserts data of a new test variant into the input buffer.

func (*Entry) MergedStatistics

func (tvb *Entry) MergedStatistics() *cpb.Statistics

MergedStatistics returns statistics about the verdicts ingested for given test variant branch. Statistics comprise data from both the input buffer and the output buffer.

func (*Entry) PopulateFromSpannerRow

func (tvb *Entry) PopulateFromSpannerRow(row *spanner.Row, hs *inputbuffer.HistorySerializer) error

func (*Entry) ToMutation

func (tvb *Entry) ToMutation(hs *inputbuffer.HistorySerializer) (*spanner.Mutation, error)

ToMutation returns a spanner Mutation to insert a TestVariantBranch to Spanner table.

func (*Entry) UpdateOutputBuffer

func (tvb *Entry) UpdateOutputBuffer(evictedSegments []inputbuffer.EvictedSegment)

UpdateOutputBuffer updates the output buffer with the evicted segments from the input buffer. evictedSegments should contain only finalized segments, except for the last segment (if any), which must be a finalizing segment. evictedSegments is sorted in ascending order of commit position (oldest segment first).

type Key

type Key struct {
	Project     string
	TestID      string
	VariantHash string
	// Make this as a string here so it can be used as key in map.
	// Note that it is a sequence of bytes, not a sequence of characters.
	RefHash RefHash
}

Key denotes the primary key for the TestVariantBranch table.

type RefHash

type RefHash string

RefHash is used for RefHash field in TestVariantBranchKey.

Jump to

Keyboard shortcuts

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