pbutil

package
v0.0.0-...-8ff35f7 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 28 Imported by: 5

Documentation

Overview

Package pbutil implements utility functions for ResultDB protobuf messages.

TODO(nodir): many of these functions are not hardly useful for clients, e.g. ones involved in request validation. The request validation functions themselves are not in this package. Ideally all symbols in this package are useful for others. Otherwise pbutil should be in internal/.

Index

Constants

View Source
const (
	MaxSizeInvocationExtendedPropertyValue = 20 * 1024  // 20 KB
	MaxSizeInvocationExtendedProperties    = 100 * 1024 // 100 KB

)
View Source
const EmptyJSON = "{}"

EmptyJSON corresponds to a serialized, empty JSON object.

View Source
const MaxDependencyBuildIDSize = 100
View Source
const MaxDependencyStepNameSize = 1024
View Source
const MaxDependencyStepTagKeySize = 256
View Source
const MaxDependencyStepTagValSize = 1024
View Source
const MaxInstructionNameSize = 100
View Source
const MaxInstructionSize = 10 * 1024 // 10 KB
View Source
const MaxInstructionsSize = 1024 * 1024 // 1 MB
View Source
const MaxSizeInvocationProperties = 16 * 1024 // 16 KB
View Source
const MaxSizeTestMetadataProperties = 4 * 1024 // 4 KB
View Source
const MaxSizeTestResultProperties = 8 * 1024 // 8 KB

MaxSizeTestResultProperties is the maximum size of the test result properties.

CAVEAT: before increasing the size limit, verify if it will break downstream services. Notably the test verdict exports. BigQuery has a 10 MB AppendRows request size limit1. Each verdict can have a maximum of 100 test results2 as of 2024-04-11.

Variables

This section is empty.

Functions

func CombineVariant

func CombineVariant(baseVariant *pb.Variant, additionalVariant *pb.Variant) *pb.Variant

CombineVariant combines base variant and additional variant. The additional variant will overwrite the base variant if there is a duplicate key.

func FromStrpairMap

func FromStrpairMap(m strpair.Map) []*pb.StringPair

FromStrpairMap converts a strpair.Map to []*pb.StringPair.

func InvocationArtifactName

func InvocationArtifactName(invocationID, artifactID string) string

InvocationArtifactName synthesizes a name of an invocation-level artifact. Does not validate IDs, use ValidateInvocationID and ValidateArtifactID.

func InvocationName

func InvocationName(id string) string

InvocationName synthesizes an invocation name from an id. Does not validate id, use ValidateInvocationID.

func IsTextArtifact

func IsTextArtifact(contentType string) bool

IsTextArtifact returns true if the content type represents a text-based artifact. Note: As the artifact content type field is optional, it is possible that a text artifact was uploaded to ResultDB without a content type. In such case, this function will return false.

We rather miss some text artifact than wrongly classify a non-text artifact as text artifact.

func MustDuration

func MustDuration(du *durationpb.Duration) time.Duration

MustDuration converts a *durationpb.Duration to a time.Duration and panics on failure.

func MustMarshal

func MustMarshal(m protoreflect.ProtoMessage) []byte

MustMarshal marshals a protobuf message and panics on failure.

func MustTimestamp

func MustTimestamp(ts *timestamppb.Timestamp) time.Time

MustTimestamp converts a *timestamppb.Timestamp to a time.Time and panics on failure.

func MustTimestampProto

func MustTimestampProto(t time.Time) *timestamppb.Timestamp

MustTimestampProto converts a time.Time to a *timestamppb.Timestamp and panics on failure.

func NormalizeInvocation

func NormalizeInvocation(inv *pb.Invocation)

NormalizeInvocation converts inv to the canonical form.

func NormalizeTestResult

func NormalizeTestResult(tr *pb.TestResult)

NormalizeTestResult converts inv to the canonical form.

func NormalizeTestResultSlice

func NormalizeTestResultSlice(trs []*pb.TestResult)

NormalizeTestResultSlice converts trs to the canonical form.

func ParseArtifactName

func ParseArtifactName(name string) (invocationID, testID, resultID, artifactID string, err error)

ParseArtifactName extracts the invocation ID, unescaped test id, result ID and artifact ID. The testID and resultID are empty if this is an invocation-level artifact.

func ParseBaselineName

func ParseBaselineName(name string) (project, baselineID string, err error)

ParseBaselineName extracts the project and baselineID.

func ParseInstructionName

func ParseInstructionName(name string) (invocationID, instructionID string, err error)

ParseInstructionName extracts invocationID and instructionID.

func ParseInvocationName

func ParseInvocationName(name string) (id string, err error)

ParseInvocationName extracts the invocation id.

func ParseTestExonerationName

func ParseTestExonerationName(name string) (invocationID, testID, exonerationID string, err error)

ParseTestExonerationName extracts invocation, test id and exoneration IDs from the name.

func ParseTestResultName

func ParseTestResultName(name string) (invID, testID, resultID string, err error)

ParseTestResultName extracts the invocation ID, unescaped test id, and result ID.

func Query

func Query(ctx context.Context, dest chan<- proto.Message, client pb.ResultDBClient, reqs ...proto.Message) error

Query queries for results continuously, sending individual items to dest channel until the paging query is exhausted or the context is canceled. A request must be *pb.QueryTestResultRequest, pb.QueryTestExonerationsRequest or *pb.QueryArtifactsRequest. Messages sent to dest are *pb.TestResult, *pb.TestExoneration or *pb.Artifact respectively.

Does not return the next page token because ctx can be canceled in the middle of a page.

If there are multiple requests in reqs, then runs them all concurrently and sends all of their results to dest. This is useful to query items of different types, e.g. test results and test exonerations. Does not limit concurrency.

func SortGerritChanges

func SortGerritChanges(changes []*pb.GerritChange)

SortGerritChanges sorts in-place the gerrit changes lexicographically.

func SortStringPairs

func SortStringPairs(tags []*pb.StringPair)

SortStringPairs sorts in-place the tags slice lexicographically by key, then value.

func SortedVariantKeys

func SortedVariantKeys(vr *pb.Variant) []string

SortedVariantKeys returns the keys in the variant as a sorted slice.

func SourceRefFromSources

func SourceRefFromSources(srcs *pb.Sources) *pb.SourceRef

SourceRefFromSources extracts a SourceRef from given sources.

func SourceRefHash

func SourceRefHash(sr *pb.SourceRef) []byte

SourceRefHash returns a short hash of the sourceRef.

func StringPair

func StringPair(k, v string) *pb.StringPair

StringPair creates a pb.StringPair with the given strings as key/value field values.

func StringPairFromString

func StringPairFromString(s string) (*pb.StringPair, error)

StringPairFromString creates a pb.StringPair from the given key:val string.

func StringPairFromStringUnvalidated

func StringPairFromStringUnvalidated(s string) *pb.StringPair

StringPairFromStringUnvalidated is like StringPairFromString, but doesn't perform validation.

func StringPairToString

func StringPairToString(pair *pb.StringPair) string

StringPairToString converts a StringPair to a key:val string.

func StringPairs

func StringPairs(pairs ...string) []*pb.StringPair

StringPairs creates a slice of pb.StringPair from a list of strings alternating key/value.

Panics if an odd number of tokens is passed.

func StringPairsContain

func StringPairsContain(pairs []*pb.StringPair, item *pb.StringPair) bool

StringPairsContain checks if item is present in pairs.

func StringPairsToStrings

func StringPairsToStrings(pairs ...*pb.StringPair) []string

StringPairsToStrings converts pairs to a slice of "{key}:{value}" strings in the same order.

func TestExonerationName

func TestExonerationName(invocationID, testID, exonerationID string) string

TestExonerationName synthesizes a test exoneration name. Assumes invocation and exoneration IDs are valid.

func TestMetadataName

func TestMetadataName(project, testID string, refHash []byte) string

TestMetadataName synthesizes a test metadata name. Assumes project, refHash and test IDs are valid.

func TestResultArtifactName

func TestResultArtifactName(invocationID, testID, resulID, artifactID string) string

TestResultArtifactName synthesizes a name of an test-result-level artifact. Does not validate IDs, use ValidateInvocationID, ValidateTestID, ValidateResultID and ValidateArtifactID.

func TestResultName

func TestResultName(invID, testID, resultID string) string

TestResultName synthesizes a test result name from its parts. Does not validate parts; use ValidateTestResultName.

func ValidateArtifactID

func ValidateArtifactID(id string) error

ValidateArtifactID returns a non-nil error if id is invalid.

func ValidateArtifactIDPrefix

func ValidateArtifactIDPrefix(idPrefix string) error

ValidateArtifactIDPrefix returns a non-nil error if prefix is invalid.

func ValidateArtifactName

func ValidateArtifactName(name string) error

ValidateArtifactName returns a non-nil error if name is invalid.

func ValidateArtifactPredicate

func ValidateArtifactPredicate(p *pb.ArtifactPredicate) error

ValidateArtifactPredicate returns a non-nil error if p is determined to be invalid.

func ValidateBaselineID

func ValidateBaselineID(baseline string) error

ValidateBaselineID returns a non-nil error if the id is invalid.

func ValidateBatchRequestCount

func ValidateBatchRequestCount(count int) error

ValidateBatchRequestCount validates the number of requests in a batch request.

func ValidateBigQueryExport

func ValidateBigQueryExport(bqExport *pb.BigQueryExport) error

ValidateBigQueryExport returns a non-nil error if bqExport is determined to be invalid.

func ValidateBugComponent

func ValidateBugComponent(bugComponent *pb.BugComponent) error

ValidateBugComponent returns a non-nil error if bug component is invalid.

func ValidateDependencies

func ValidateDependencies(dependencies []*pb.InstructionDependency) error

func ValidateDependency

func ValidateDependency(dependency *pb.InstructionDependency) error

func ValidateEnum

func ValidateEnum(value int32, validValues map[int32]string) error

ValidateEnum returns a non-nil error if the value is not among valid values.

func ValidateError

func ValidateError(error *pb.FailureReason_Error) error

func ValidateFailureReason

func ValidateFailureReason(fr *pb.FailureReason) error

ValidateFailureReason returns a non-nil error if fr is invalid.

func ValidateFilePath

func ValidateFilePath(path string) error

ValidateFilePath returns a non-nil error if path is invalid.

func ValidateGerritChange

func ValidateGerritChange(change *pb.GerritChange) error

ValidateGerritChange validates a gerrit change.

func ValidateGitilesCommit

func ValidateGitilesCommit(commit *pb.GitilesCommit) error

ValidateGitilesCommit validates a gitiles commit.

func ValidateInstruction

func ValidateInstruction(instruction *pb.Instruction) error

func ValidateInstructionFilter

func ValidateInstructionFilter(filter *pb.InstructionFilter) error

func ValidateInstructions

func ValidateInstructions(instructions *pb.Instructions) error

func ValidateInvocationExtendedProperties

func ValidateInvocationExtendedProperties(extendedProperties map[string]*structpb.Struct) error

ValidateInvocationExtendedProperties returns a non-nil error if extendedProperties is invalid.

func ValidateInvocationExtendedPropertyKey

func ValidateInvocationExtendedPropertyKey(key string) error

ValidateInvocationExtendedPropertyKey returns a non-nil error if key is invalid.

func ValidateInvocationID

func ValidateInvocationID(id string) error

ValidateInvocationID returns a non-nil error if id is invalid.

func ValidateInvocationName

func ValidateInvocationName(name string) error

ValidateInvocationName returns a non-nil error if name is invalid.

func ValidateInvocationProperties

func ValidateInvocationProperties(properties *structpb.Struct) error

ValidateInvocationProperties returns a non-nil error if properties is invalid.

func ValidateProject

func ValidateProject(project string) error

ValidateProject returns a non-nil error if project is invalid.

func ValidatePropertiesSchema

func ValidatePropertiesSchema(propertiesSchema string) error

ValidatePropertiesSchema returns a non-nil error if properties schema is invalid.

func ValidateRequestID

func ValidateRequestID(requestID string) error

ValidateRequestID returns a non-nil error if requestID is invalid. Returns nil if requestID is empty.

func ValidateResultID

func ValidateResultID(resultID string) error

ValidateResultID returns a non-nil error if resultID is invalid.

func ValidateSourceSpec

func ValidateSourceSpec(sourceSpec *pb.SourceSpec) error

ValidateSourceSpec validates a source specification.

func ValidateSources

func ValidateSources(sources *pb.Sources) error

ValidateSources validates a set of sources.

func ValidateStartTimeWithDuration

func ValidateStartTimeWithDuration(now time.Time, startTime *timestamppb.Timestamp, duration *durationpb.Duration) error

ValidateStartTimeWithDuration returns a non-nil error if startTime and duration are invalid.

func ValidateStringPair

func ValidateStringPair(p *pb.StringPair) error

ValidateStringPair returns an error if p is invalid.

func ValidateStringPairs

func ValidateStringPairs(pairs []*pb.StringPair) error

ValidateStringPairs returns an error if any of the pairs is invalid.

func ValidateSummaryHTML

func ValidateSummaryHTML(summary string) error

ValidateSummaryHTML returns a non-nil error if summary is invalid.

func ValidateTargetedInstruction

func ValidateTargetedInstruction(targetedInstruction *pb.TargetedInstruction, targetMap map[pb.InstructionTarget]bool) error

func ValidateTestExonerationName

func ValidateTestExonerationName(name string) error

ValidateTestExonerationName returns a non-nil error if the test exoneration name is invalid.

func ValidateTestExonerationPredicate

func ValidateTestExonerationPredicate(p *pb.TestExonerationPredicate) error

ValidateTestExonerationPredicate returns a non-nil error if p is determined to be invalid.

func ValidateTestID

func ValidateTestID(testID string) error

ValidateTestID returns a non-nil error if testID is invalid.

func ValidateTestLocation

func ValidateTestLocation(loc *pb.TestLocation) error

ValidateTestLocation returns a non-nil error if loc is invalid.

func ValidateTestMetadata

func ValidateTestMetadata(tmd *pb.TestMetadata) error

ValidateTestMetadata returns a non-nil error if tmd is invalid.

func ValidateTestMetadataPredicate

func ValidateTestMetadataPredicate(p *pb.TestMetadataPredicate) error

ValidateTestMetadataPredicate returns a non-nil error if p is determined to be invalid.

func ValidateTestMetadataProperties

func ValidateTestMetadataProperties(properties *structpb.Struct) error

ValidateTestMetadataProperties returns a non-nil error if properties is invalid.

func ValidateTestResult

func ValidateTestResult(now time.Time, msg *pb.TestResult) (err error)

ValidateTestResult returns a non-nil error if msg is invalid.

func ValidateTestResultName

func ValidateTestResultName(name string) error

ValidateTestResultName returns a non-nil error if name is invalid.

func ValidateTestResultPredicate

func ValidateTestResultPredicate(p *pb.TestResultPredicate) error

ValidateTestResultPredicate returns a non-nil error if p is determined to be invalid.

func ValidateTestResultProperties

func ValidateTestResultProperties(properties *structpb.Struct) error

ValidateTestResultProperties returns a non-nil error if properties is invalid.

func ValidateTestResultSkipReason

func ValidateTestResultSkipReason(status pb.TestStatus, reason pb.SkipReason) error

ValidateTestResultSkipReason returns a non-nil error if reason is invalid for a test result with the given status.

func ValidateTestResultStatus

func ValidateTestResultStatus(s pb.TestStatus) error

ValidateTestResultStatus returns a non-nil error if s is invalid for a test result.

func ValidateVariant

func ValidateVariant(vr *pb.Variant) error

ValidateVariant returns an error if vr is invalid.

func ValidateVariantHash

func ValidateVariantHash(variantHash string) error

ValidateVariantHash returns a non-nil error if variantHash is invalid.

func ValidateVariantPredicate

func ValidateVariantPredicate(p *pb.VariantPredicate) error

ValidateVariantPredicate returns a non-nil error if p is determined to be invalid.

func Variant

func Variant(pairs ...string) *pb.Variant

Variant creates a pb.Variant from a list of strings alternating key/value. Does not validate pairs. See also VariantFromStrings.

Panics if an odd number of tokens is passed.

func VariantFromJSON

func VariantFromJSON(variant string) (*pb.Variant, error)

VariantFromJSON convert json string representation of the variant into protocol buffer.

func VariantFromStrings

func VariantFromStrings(pairs []string) (*pb.Variant, error)

VariantFromStrings returns a Variant proto given the key:val string slice of its contents.

If a key appears multiple times, the last pair wins.

func VariantHash

func VariantHash(vr *pb.Variant) string

VariantHash returns a short hash of the variant.

func VariantToJSON

func VariantToJSON(variant *pb.Variant) (string, error)

VariantToJSON returns the JSON equivalent for a variant. Each key in the variant is mapped to a top-level key in the JSON object. e.g. `{"builder":"linux-rel","os":"Ubuntu-18.04"}`

func VariantToStringPairs

func VariantToStringPairs(vr *pb.Variant) []*pb.StringPair

VariantToStringPairs returns a slice of StringPair derived from *pb.Variant.

func VariantToStrings

func VariantToStrings(vr *pb.Variant) []string

VariantToStrings returns a key:val string slice representation of the Variant. Never returns nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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