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
- func CombineVariant(baseVariant *pb.Variant, additionalVariant *pb.Variant) *pb.Variant
- func FromStrpairMap(m strpair.Map) []*pb.StringPair
- func InvocationArtifactName(invocationID, artifactID string) string
- func InvocationName(id string) string
- func IsTextArtifact(contentType string) bool
- func MustDuration(du *durationpb.Duration) time.Duration
- func MustMarshal(m protoreflect.ProtoMessage) []byte
- func MustTimestamp(ts *timestamppb.Timestamp) time.Time
- func MustTimestampProto(t time.Time) *timestamppb.Timestamp
- func NormalizeInvocation(inv *pb.Invocation)
- func NormalizeTestResult(tr *pb.TestResult)
- func NormalizeTestResultSlice(trs []*pb.TestResult)
- func ParseArtifactName(name string) (invocationID, testID, resultID, artifactID string, err error)
- func ParseBaselineName(name string) (project, baselineID string, err error)
- func ParseInstructionName(name string) (invocationID, instructionID string, err error)
- func ParseInvocationName(name string) (id string, err error)
- func ParseTestExonerationName(name string) (invocationID, testID, exonerationID string, err error)
- func ParseTestResultName(name string) (invID, testID, resultID string, err error)
- func Query(ctx context.Context, dest chan<- proto.Message, client pb.ResultDBClient, ...) error
- func SortGerritChanges(changes []*pb.GerritChange)
- func SortStringPairs(tags []*pb.StringPair)
- func SortedVariantKeys(vr *pb.Variant) []string
- func SourceRefFromSources(srcs *pb.Sources) *pb.SourceRef
- func SourceRefHash(sr *pb.SourceRef) []byte
- func StringPair(k, v string) *pb.StringPair
- func StringPairFromString(s string) (*pb.StringPair, error)
- func StringPairFromStringUnvalidated(s string) *pb.StringPair
- func StringPairToString(pair *pb.StringPair) string
- func StringPairs(pairs ...string) []*pb.StringPair
- func StringPairsContain(pairs []*pb.StringPair, item *pb.StringPair) bool
- func StringPairsToStrings(pairs ...*pb.StringPair) []string
- func TestExonerationName(invocationID, testID, exonerationID string) string
- func TestMetadataName(project, testID string, refHash []byte) string
- func TestResultArtifactName(invocationID, testID, resulID, artifactID string) string
- func TestResultName(invID, testID, resultID string) string
- func ValidateArtifactID(id string) error
- func ValidateArtifactIDPrefix(idPrefix string) error
- func ValidateArtifactName(name string) error
- func ValidateArtifactPredicate(p *pb.ArtifactPredicate) error
- func ValidateBaselineID(baseline string) error
- func ValidateBatchRequestCount(count int) error
- func ValidateBigQueryExport(bqExport *pb.BigQueryExport) error
- func ValidateBugComponent(bugComponent *pb.BugComponent) error
- func ValidateDependencies(dependencies []*pb.InstructionDependency) error
- func ValidateDependency(dependency *pb.InstructionDependency) error
- func ValidateEnum(value int32, validValues map[int32]string) error
- func ValidateError(error *pb.FailureReason_Error) error
- func ValidateFailureReason(fr *pb.FailureReason) error
- func ValidateFilePath(path string) error
- func ValidateGerritChange(change *pb.GerritChange) error
- func ValidateGitilesCommit(commit *pb.GitilesCommit) error
- func ValidateInstruction(instruction *pb.Instruction) error
- func ValidateInstructionFilter(filter *pb.InstructionFilter) error
- func ValidateInstructions(instructions *pb.Instructions) error
- func ValidateInvocationExtendedProperties(extendedProperties map[string]*structpb.Struct) error
- func ValidateInvocationExtendedPropertyKey(key string) error
- func ValidateInvocationID(id string) error
- func ValidateInvocationName(name string) error
- func ValidateInvocationProperties(properties *structpb.Struct) error
- func ValidateProject(project string) error
- func ValidatePropertiesSchema(propertiesSchema string) error
- func ValidateRequestID(requestID string) error
- func ValidateResultID(resultID string) error
- func ValidateSourceSpec(sourceSpec *pb.SourceSpec) error
- func ValidateSources(sources *pb.Sources) error
- func ValidateStartTimeWithDuration(now time.Time, startTime *timestamppb.Timestamp, duration *durationpb.Duration) error
- func ValidateStringPair(p *pb.StringPair) error
- func ValidateStringPairs(pairs []*pb.StringPair) error
- func ValidateSummaryHTML(summary string) error
- func ValidateTargetedInstruction(targetedInstruction *pb.TargetedInstruction, ...) error
- func ValidateTestExonerationName(name string) error
- func ValidateTestExonerationPredicate(p *pb.TestExonerationPredicate) error
- func ValidateTestID(testID string) error
- func ValidateTestLocation(loc *pb.TestLocation) error
- func ValidateTestMetadata(tmd *pb.TestMetadata) error
- func ValidateTestMetadataPredicate(p *pb.TestMetadataPredicate) error
- func ValidateTestMetadataProperties(properties *structpb.Struct) error
- func ValidateTestResult(now time.Time, msg *pb.TestResult) (err error)
- func ValidateTestResultName(name string) error
- func ValidateTestResultPredicate(p *pb.TestResultPredicate) error
- func ValidateTestResultProperties(properties *structpb.Struct) error
- func ValidateTestResultSkipReason(status pb.TestStatus, reason pb.SkipReason) error
- func ValidateTestResultStatus(s pb.TestStatus) error
- func ValidateVariant(vr *pb.Variant) error
- func ValidateVariantHash(variantHash string) error
- func ValidateVariantPredicate(p *pb.VariantPredicate) error
- func Variant(pairs ...string) *pb.Variant
- func VariantFromJSON(variant string) (*pb.Variant, error)
- func VariantFromStrings(pairs []string) (*pb.Variant, error)
- func VariantHash(vr *pb.Variant) string
- func VariantToJSON(variant *pb.Variant) (string, error)
- func VariantToStringPairs(vr *pb.Variant) []*pb.StringPair
- func VariantToStrings(vr *pb.Variant) []string
Constants ¶
const ( MaxSizeInvocationExtendedPropertyValue = 20 * 1024 // 20 KB MaxSizeInvocationExtendedProperties = 100 * 1024 // 100 KB )
const EmptyJSON = "{}"
EmptyJSON corresponds to a serialized, empty JSON object.
const MaxDependencyBuildIDSize = 100
const MaxDependencyStepNameSize = 1024
const MaxDependencyStepTagKeySize = 256
const MaxDependencyStepTagValSize = 1024
const MaxInstructionNameSize = 100
const MaxInstructionSize = 10 * 1024 // 10 KB
const MaxInstructionsSize = 1024 * 1024 // 1 MB
const MaxSizeInvocationProperties = 16 * 1024 // 16 KB
const MaxSizeTestMetadataProperties = 4 * 1024 // 4 KB
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 ¶
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 ¶
InvocationArtifactName synthesizes a name of an invocation-level artifact. Does not validate IDs, use ValidateInvocationID and ValidateArtifactID.
func InvocationName ¶
InvocationName synthesizes an invocation name from an id. Does not validate id, use ValidateInvocationID.
func IsTextArtifact ¶
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 ¶
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 ¶
ParseBaselineName extracts the project and baselineID.
func ParseInstructionName ¶
ParseInstructionName extracts invocationID and instructionID.
func ParseInvocationName ¶
ParseInvocationName extracts the invocation id.
func ParseTestExonerationName ¶
ParseTestExonerationName extracts invocation, test id and exoneration IDs from the name.
func ParseTestResultName ¶
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 ¶
SortedVariantKeys returns the keys in the variant as a sorted slice.
func SourceRefFromSources ¶
SourceRefFromSources extracts a SourceRef from given sources.
func SourceRefHash ¶
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 ¶
TestExonerationName synthesizes a test exoneration name. Assumes invocation and exoneration IDs are valid.
func TestMetadataName ¶
TestMetadataName synthesizes a test metadata name. Assumes project, refHash and test IDs are valid.
func TestResultArtifactName ¶
TestResultArtifactName synthesizes a name of an test-result-level artifact. Does not validate IDs, use ValidateInvocationID, ValidateTestID, ValidateResultID and ValidateArtifactID.
func TestResultName ¶
TestResultName synthesizes a test result name from its parts. Does not validate parts; use ValidateTestResultName.
func ValidateArtifactID ¶
ValidateArtifactID returns a non-nil error if id is invalid.
func ValidateArtifactIDPrefix ¶
ValidateArtifactIDPrefix returns a non-nil error if prefix is invalid.
func ValidateArtifactName ¶
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 ¶
ValidateBaselineID returns a non-nil error if the id is invalid.
func ValidateBatchRequestCount ¶
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 ¶
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 ¶
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 ¶
ValidateInvocationExtendedProperties returns a non-nil error if extendedProperties is invalid.
func ValidateInvocationExtendedPropertyKey ¶
ValidateInvocationExtendedPropertyKey returns a non-nil error if key is invalid.
func ValidateInvocationID ¶
ValidateInvocationID returns a non-nil error if id is invalid.
func ValidateInvocationName ¶
ValidateInvocationName returns a non-nil error if name is invalid.
func ValidateInvocationProperties ¶
ValidateInvocationProperties returns a non-nil error if properties is invalid.
func ValidateProject ¶
ValidateProject returns a non-nil error if project is invalid.
func ValidatePropertiesSchema ¶
ValidatePropertiesSchema returns a non-nil error if properties schema is invalid.
func ValidateRequestID ¶
ValidateRequestID returns a non-nil error if requestID is invalid. Returns nil if requestID is empty.
func ValidateResultID ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ValidateVariant returns an error if vr is invalid.
func ValidateVariantHash ¶
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 ¶
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 ¶
VariantFromJSON convert json string representation of the variant into protocol buffer.
func VariantFromStrings ¶
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 ¶
VariantHash returns a short hash of the variant.
func VariantToJSON ¶
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 ¶
VariantToStrings returns a key:val string slice representation of the Variant. Never returns nil.
Types ¶
This section is empty.