Documentation ¶
Overview ¶
Package model contains datastore model implementation.
Index ¶
- Constants
- Variables
- func BucketKey(ctx context.Context, project, bucket string) *datastore.Key
- func BuilderKey(ctx context.Context, project, bucket, builder string) *datastore.Key
- func GenerateSequenceNumbers(ctx context.Context, name string, n int) (int32, error)
- func GetBuildAndBucket(ctx context.Context, id int64) (*Build, *Bucket, error)
- func GetIgnoreMissing(ctx context.Context, dst ...interface{}) error
- func LoadBuildDetails(ctx context.Context, m *mask.Mask, builds ...*pb.Build) error
- func OverrideGlobalBuildUpdateTimeClock(c clock.Clock) (undo func())
- func ProjectKey(ctx context.Context, project string) *datastore.Key
- func UpdateBuilderStat(ctx context.Context, builds []*Build, scheduledTime time.Time) error
- func UpdateTagIndex(ctx context.Context, tag string, ents []TagIndexEntry) error
- type Bucket
- type Build
- func (b *Build) ExperimentStatus(expname string) (ret pb.Trinary)
- func (b *Build) IterExperiments(cb func(enabled bool, exp string) bool)
- func (b *Build) Load(p datastore.PropertyMap) error
- func (b *Build) Realm() string
- func (b *Build) Save(withMeta bool) (datastore.PropertyMap, error)
- func (b *Build) ToProto(ctx context.Context, m *mask.Mask) (*pb.Build, error)
- func (b *Build) ToSimpleBuildProto(ctx context.Context) *pb.Build
- type BuildInfra
- type BuildInputProperties
- type BuildOutputProperties
- type BuildSteps
- type Builder
- type BuilderStat
- type DSBuildInfra
- type DSStruct
- type LeaseProperties
- type LegacyCancelationReason
- type LegacyFailureReason
- type LegacyProperties
- type LegacyResult
- type LegacyStatus
- type NumberSequence
- type Project
- type PubSubCallback
- type RequestID
- type TagIndex
- type TagIndexEntry
- type UnusedProperties
Constants ¶
const (
// BucketKind is a bucket entity's kind in the datastore.
BucketKind = "BucketV2"
)
const (
// BuildKind is a Build entity's kind in the datastore.
BuildKind = "Build"
)
const BuildStepsMaxBytes = 1e6
BuildStepsMaxBytes is the maximum length of BuildSteps.Bytes. If Bytes exceeds this maximum, this package will try to compress it, setting IsZipped accordingly, but if this length is still exceeded it's an error to write such entities to the datastore. Use FromProto to ensure this maximum is respected.
const BuilderExpirationDuration = 4 * 7 * 24 * time.Hour // 4 weeks
BuilderExpirationDuration is the maximum duration a builder can go without having a build scheduled before its BuilderStat may be deleted.
const BuilderKind = "Bucket.Builder"
BuilderKind is the kind of the Builder entity.
const MaxTagIndexEntries = 1000
MaxTagIndexEntries is the maximum number of entries that may be associated with a single TagIndex entity.
const TagIndexShardCount = 16
TagIndexShardCount is the number of shards used by the TagIndex.
Variables ¶
var LegacyCancelationReason_name = []string{
0: "UNSET",
ExplicitlyCanceled: "CANCELED_EXPLICITLY",
TimeoutCanceled: "TIMEOUT",
}
var LegacyFailureReason_name = []string{
0: "UNSET",
BuildFailure: "BUILD_FAILURE",
BuildbucketFailure: "BUILDBUCKET_FAILURE",
InfraFailure: "INFRA_FAILURE",
InvalidBuildDefinition: "INVALID_BUILD_DEFINITION",
}
var LegacyResult_name = []string{
0: "UNSET",
Success: "SUCCESS",
Failure: "FAILURE",
Canceled: "CANCELED",
}
var LegacyStatus_name = []string{ 0: "UNSET", Scheduled: "SCHEDULED", Started: "STARTED", Completed: "COMPLETED", }
var TagIndexIncomplete = errors.BoolTag{Key: errors.NewTagKey("tag index incomplete")}
TagIndexIncomplete means the tag index is incomplete and thus cannot be searched.
Functions ¶
func BuilderKey ¶
BuilderKey returns a datastore key of a builder.
func GenerateSequenceNumbers ¶
GenerateSequenceNumbers generates n numbers for the given sequence name, returning the smallest number the caller may use. For a returned number i, the caller may use [i, i+n).
func GetBuildAndBucket ¶
GetBuildAndBucket returns the build with the given ID as well as the bucket it belongs to. Returns datastore.ErrNoSuchEntity if either is not found.
func GetIgnoreMissing ¶
GetIgnoreMissing fetches the given entities from the datastore, ignoring datastore.ErrNoSuchEntity errors. All other errors are returned. For valid values of dst, see datastore.Get.
func LoadBuildDetails ¶
LoadBuildDetails loads the details of the given builds, trimming them according to the mask.
func OverrideGlobalBuildUpdateTimeClock ¶
OverrideGlobalBuildUpdateTimeClock allows you to override the clock used for setting the Build.Proto.UpdateTime field.
This should only be used in tests, though use appropriate caution since this is a global variable.
Overriding with `nil` will result in UpdateTime not being manipulated at all.
Returns a function to undo the manipulation.
Example Usage:
ctx, testClock := testclock.UseTime(ctx, ...) defer OverrideGlobalBuildUpdateTimeClock(testClock)()
func ProjectKey ¶
ProjectKey returns a datastore key of a project.
func UpdateBuilderStat ¶
UpdateBuilderStat updates or creates datastore BuilderStat entities.
func UpdateTagIndex ¶
func UpdateTagIndex(ctx context.Context, tag string, ents []TagIndexEntry) error
UpdateTagIndex updates the tag index for the given tag.
Types ¶
type Bucket ¶
type Bucket struct { // ID is the bucket in v2 format. // e.g. try (never luci.chromium.try). ID string `gae:"$id"` Parent *datastore.Key `gae:"$parent"` // Bucket is the bucket in v2 format. // e.g. try (never luci.chromium.try). Bucket string `gae:"bucket_name"` // Proto is the pb.Bucket proto representation of the bucket. // // acl_sets is zeroed by inlining acls. swarming.builders is // zeroed and stored in separate Builder datastore entities due to // potentially large size. // // noindex is not respected here, it's set in pb.Bucket.ToProperty. Proto pb.Bucket `gae:"config,noindex"` // Revision is the config revision this entity was created from. // TODO(crbug/1042991): Switch to noindex. Revision string `gae:"revision"` // Schema is this entity's schema version. // TODO(crbug/1042991): Switch to noindex. Schema int32 `gae:"entity_schema_version"` // contains filtered or unexported fields }
Bucket is a representation of a bucket in the datastore.
type Build ¶
type Build struct { ID int64 `gae:"$id"` // LegacyProperties are properties set for v1 legacy builds. LegacyProperties // UnusedProperties are properties set previously but currently unused. UnusedProperties // Proto is the pb.Build proto representation of the build. // // infra, input.properties, output.properties, and steps // are zeroed and stored in separate datastore entities // due to their potentially large size (see details.go). // tags are given their own field so they can be indexed. // // noindex is not respected here, it's set in pb.Build.ToProperty. Proto pb.Build `gae:"proto,noindex"` Project string `gae:"project"` // <project>/<bucket>. Bucket is in v2 format. // e.g. chromium/try (never chromium/luci.chromium.try). BucketID string `gae:"bucket_id"` // <project>/<bucket>/<builder>. Bucket is in v2 format. // e.g. chromium/try/linux-rel. BuilderID string `gae:"builder_id"` Canary bool `gae:"canary"` CreatedBy identity.Identity `gae:"created_by"` // TODO(nodir): Replace reliance on create_time indices with id. CreateTime time.Time `gae:"create_time"` // Experimental, if true, means to exclude from monitoring and search results // (unless specifically requested in search results). Experimental bool `gae:"experimental"` // Experiments is a slice of experiments enabled or disabled on this build. // Each element should look like "[-+]$experiment_name". // // Special case: // "-luci.non_production" is not kept here as a storage/index // optimization. // // Notably, all search/query implementations on the Build model // apply this filter in post by checking that // `b.ExperimentStatus("luci.non_production") == pb.Trinary_YES`. // // This is because directly including this value in the datastore query // results in bad performance due to excessive zig-zag join overhead // in the datastore, since 99%+ of the builds in Buildbucket are production // builds. Experiments []string `gae:"experiments"` Incomplete bool `gae:"incomplete"` // Deprecated; remove after v1 api turndown IsLuci bool `gae:"is_luci"` ResultDBUpdateToken string `gae:"resultdb_update_token,noindex"` Status pb.Status `gae:"status_v2"` StatusChangedTime time.Time `gae:"status_changed_time"` // Tags is a slice of "<key>:<value>" strings taken from Proto.Tags. // Stored separately in order to index. Tags []string `gae:"tags"` // UpdateToken is set at the build creation time, and UpdateBuild requests are required // to have it in the header. UpdateToken string `gae:"update_token,noindex"` // PubSubCallback, if set, creates notifications for build status changes. PubSubCallback PubSubCallback `gae:"pubsub_callback,noindex"` // contains filtered or unexported fields }
Build is a representation of a build in the datastore. Implements datastore.PropertyLoadSaver.
func (*Build) ExperimentStatus ¶
ExperimentStatus scans the experiments attached to this Build and returns:
- YES - The experiment was known at schedule time and enabled.
- NO - The experiment was known at schedule time and disabled.
- UNSET - The experiment was unknown at schedule time.
Malformed Experiment filters are treated as UNSET.
func (*Build) IterExperiments ¶
IterExperiments parses all experiments and calls `cb` for each.
This will always include a call with bb.ExperimentNonProduction, even if '-'+bb.ExperimentNonProduction isn't recorded in the underlying Experiments field.
func (*Build) Load ¶
func (b *Build) Load(p datastore.PropertyMap) error
Load overwrites this representation of a build by reading the given datastore.PropertyMap. Mutates this entity.
func (*Build) Realm ¶
Realm returns this build's auth realm, or an empty string if not opted into the realms experiment.
func (*Build) Save ¶
func (b *Build) Save(withMeta bool) (datastore.PropertyMap, error)
Save returns the datastore.PropertyMap representation of this build. Mutates this entity to reflect computed datastore fields in the returned PropertyMap.
type BuildInfra ¶
type BuildInfra struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id,1"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // Proto is the pb.BuildInfra proto representation of the infra field. Proto DSBuildInfra `gae:"infra,noindex"` // contains filtered or unexported fields }
BuildInfra is a representation of a build proto's infra field in the datastore.
type BuildInputProperties ¶
type BuildInputProperties struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id,1"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // Proto is the structpb.Struct representation of the properties field. Proto DSStruct `gae:"properties,noindex"` // contains filtered or unexported fields }
BuildInputProperties is a representation of a build proto's input field's properties field in the datastore.
type BuildOutputProperties ¶
type BuildOutputProperties struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id,1"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // Proto is the structpb.Struct representation of the properties field. Proto DSStruct `gae:"properties,noindex"` // contains filtered or unexported fields }
BuildOutputProperties is a representation of a build proto's output field's properties field in the datastore.
type BuildSteps ¶
type BuildSteps struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id,1"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // IsZipped indicates whether or not Bytes is zlib compressed. // Use ToProto to ensure this compression is respected. IsZipped bool `gae:"step_container_bytes_zipped,noindex"` // Bytes is the pb.Build proto representation of the build proto where only steps is set. // IsZipped determines whether this value is compressed or not. Bytes []byte `gae:"steps,noindex"` // contains filtered or unexported fields }
BuildSteps is a representation of a build proto's steps field in the datastore.
func (*BuildSteps) CancelIncomplete ¶
func (s *BuildSteps) CancelIncomplete(ctx context.Context, now *timestamppb.Timestamp) (bool, error)
CancelIncomplete marks any incomplete steps as cancelled, returning whether at least one step was cancelled. The caller is responsible for writing the entity to the datastore if any steps were cancelled. This entity will not be mutated if an error occurs.
type Builder ¶
type Builder struct { // ID is the builder name, e.g. "linux-rel". ID string `gae:"$id"` // Parent is the key of the parent Bucket. Parent *datastore.Key `gae:"$parent"` // Config is the builder configuration feched from luci-config. Config pb.Builder `gae:"config"` // ConfigHash is used for fast deduplication of configs. ConfigHash string `gae:"config_hash"` // contains filtered or unexported fields }
Builder is a Datastore entity that stores builder configuration. It is a child of Bucket entity.
Builder entities are updated together with their parents, in a cron job.
type BuilderStat ¶
type BuilderStat struct { // ID is a string with format "{project}:{bucket}:{builder}". ID string `gae:"$id"` // LastScheduled is the last time we received a valid build scheduling request // for this builder. Probabilistically update when scheduling a build. LastScheduled time.Time `gae:"last_scheduled"` // contains filtered or unexported fields }
BuilderStat represents a builder Datastore entity which is used internally for metrics.
The builder will be registered automatically by scheduling a build, and unregistered automatically by not scheduling builds for BuilderExpirationDuration.
Note: due to the historical reason, the entity kind is Builder.
type DSBuildInfra ¶
type DSBuildInfra struct {
pb.BuildInfra
}
DSBuildInfra is a wrapper around pb.BuildInfra. Although pb.BuildInfra already implements datastore.PropertyConverter, override FromProto to apply defaultStructValues.
func (*DSBuildInfra) FromProperty ¶
func (b *DSBuildInfra) FromProperty(p datastore.Property) error
FromProperty deserializes pb.BuildInfra protos from the datastore. Implements datastore.PropertyConverter.
type DSStruct ¶
DSStruct is a wrapper around structpb.Struct. Implements datastore.PropertyConverter, allowing reads from and writes to the datastore.
func (*DSStruct) FromProperty ¶
FromProperty deserializes structpb.Struct protos from the datastore. Implements datastore.PropertyConverter.
type LeaseProperties ¶
type LeaseProperties struct { IsLeased bool `gae:"is_leased"` // TODO(crbug/1042991): Create datastore.PropertyConverter in server/auth. Leasee []byte `gae:"leasee"` LeaseExpirationDate time.Time `gae:"lease_expiration_date"` // LeaseKey is a random value used to verify the leaseholder's identity. LeaseKey int `gae:"lease_key"` NeverLeased bool `gae:"never_leased"` }
LeaseProperties are properties associated with the legacy leasing API.
type LegacyCancelationReason ¶
type LegacyCancelationReason int
LegacyCancelationReason is the reason for a canceled legacy build.
const ( // ExplicitlyCanceled means the build was canceled (likely via API call). ExplicitlyCanceled LegacyCancelationReason // TimeoutCanceled means Buildbucket timed the build out. TimeoutCanceled )
func (LegacyCancelationReason) String ¶
func (r LegacyCancelationReason) String() string
type LegacyFailureReason ¶
type LegacyFailureReason int
LegacyFailureReason is the reason for a legacy build failure.
const ( // BuildFailure means the build itself failed. BuildFailure LegacyFailureReason // BuildbucketFailure means something went wrong within Buildbucket. BuildbucketFailure // InfraFailure means something went wrong outside the build and Buildbucket. InfraFailure // InvalidBuildDefinition means the build system rejected the build definition. InvalidBuildDefinition )
func (LegacyFailureReason) String ¶
func (r LegacyFailureReason) String() string
type LegacyProperties ¶
type LegacyProperties struct { LeaseProperties CancelationReason LegacyCancelationReason `gae:"cancelation_reason"` FailureReason LegacyFailureReason `gae:"failure_reason"` Parameters []byte `gae:"parameters"` Result LegacyResult `gae:"result"` ResultDetails []byte `gae:"result_details"` // ID of the Build this is a retry of. RetryOf int `gae:"retry_of"` Status LegacyStatus `gae:"status"` URL string `gae:"url,noindex"` }
LegacyProperties are properties of legacy builds.
Parameters and ResultDetails are byte slices interpretable as JSON. TODO(crbug/1042991): Create datastore.PropertyConverter for JSON properties.
type LegacyResult ¶
type LegacyResult int
LegacyResult is the result of a completed legacy build.
const ( // Success means the build completed successfully. Success LegacyResult // Failure means the build failed and has an associated LegacyFailureReason. Failure // Canceled means the build was canceled // and has an associated LegacyCancelationReason. Canceled )
func (LegacyResult) String ¶
func (r LegacyResult) String() string
type LegacyStatus ¶
type LegacyStatus int
LegacyStatus is the status of a legacy build request.
const ( // Scheduled builds may be leased and started. Scheduled LegacyStatus // Started builds are leased and marked as started. Started // Completed builds are finished and have an associated LegacyResult. Completed )
func (LegacyStatus) String ¶
func (r LegacyStatus) String() string
type NumberSequence ¶
type NumberSequence struct { ID string `gae:"$id"` Next int32 `gae:"next_number,noindex"` // contains filtered or unexported fields }
NumberSequence stores the next number in a named sequence of numbers.
type Project ¶
type Project struct {
ID string `gae:"$id"`
}
Project is the parent entity of buckets in the datastore. Entities of this kind don't exist in the datastore.
type PubSubCallback ¶
type PubSubCallback struct { AuthToken string `gae:"auth_token,noindex"` Topic string `gae:"topic,noindex"` UserData []byte `gae:"user_data,noindex"` }
PubSubCallback encapsulates parameters for a Pub/Sub callback.
type RequestID ¶
type RequestID struct { // ID is a string of the form "<auth.Identity>:<request ID string>" encoded // as a hex string using SHA-256 for a well-distributed key space. ID string `gae:"$id"` // BuildID is the ID of the Build entity this entity refers to. BuildID int64 `gae:"build_id,noindex"` CreatedBy identity.Identity `gae:"created_by,noindex"` CreateTime time.Time `gae:"create_time,noindex"` // RequestID is the original request ID string this entity was created from. RequestID string `gae:"request_id,noindex"` // contains filtered or unexported fields }
RequestID stores request IDs for request deduplication.
type TagIndex ¶
type TagIndex struct { // ID is a "<key>:<value>" or ":<index>:<key>:<value>" string for index > 0. ID string `gae:"$id"` // Incomplete means there are more than MaxTagIndexEntries entities // with the same ID, and therefore the index is incomplete and cannot be // searched. Incomplete bool `gae:"permanently_incomplete,noindex"` // Entries is a slice of TagIndexEntries matching this ID. Entries []TagIndexEntry `gae:"entries,noindex"` // contains filtered or unexported fields }
TagIndex is an index used to search Build entities by tag.
type TagIndexEntry ¶
type TagIndexEntry struct { // BuildID is the ID of the Build entity this entry refers to. BuildID int64 `json:"build_id"` // <project>/<bucket>. Bucket is in v2 format. // e.g. chromium/try (never chromium/luci.chromium.try). BucketID string `json:"bucket_id"` // CreatedTime is the time this entry was created. CreatedTime time.Time `json:"created_time"` }
TagIndexEntry refers to a particular Build entity.
func SearchTagIndex ¶
func SearchTagIndex(ctx context.Context, key, val string) ([]*TagIndexEntry, error)
SearchTagIndex searches the tag index for the given tag. Returns an error tagged with TagIndexIncomplete if the tag index is incomplete and thus cannot be searched.
func (*TagIndexEntry) FromProperty ¶
func (e *TagIndexEntry) FromProperty(p datastore.Property) error
FromProperty deserializes TagIndexEntries from the datastore. Implements datastore.PropertyConverter.
func (*TagIndexEntry) ToProperty ¶
func (e *TagIndexEntry) ToProperty() (datastore.Property, error)
ToProperty serializes TagIndexEntries to datastore format. Implements datastore.PropertyConverter.
type UnusedProperties ¶
type UnusedProperties struct { // PubSubCallback is normally a struct (see build.go), which translates into datastore // fields pubsub_callback.auth_token, pubsub_callback.topic, pubsub_callback.user_data // with no actual field called pubsub_callback. However, nil values in the datastore // may exist for pubsub_callback (should instead be represented by having all three // pubsub_callback.* fields nil, but isn't). Capture such nil values here. // TODO(crbug/1042991): Support this case properly in gae datastore package. PubSubCallback []byte `gae:"pubsub_callback,noindex"` }
UnusedProperties are properties previously set but currently unused.