buildgrid.server.metering.models module

class buildgrid.server.metering.models.Identity(*, instance: str, workflow: str, actor: str, subject: str)

Bases: BaseModel

Identity that consumes build resource

Parameters:
  • Instance – REAPI service instance, e.g., “dev”

  • Workflow – The associated workflow of the operation, e.g., “build”

  • Actor – The tooling or agent that submitted the operation, e.g., “my-build-tool”

  • Subject – The end user that submitted the operation, e.g. “user1”

instance: str
workflow: str
actor: str
subject: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.ResourceUsage

Bases: BaseModel, ABC

abstract combine(other: R) R

Combine two resource usages of the same type

abstract get_throttled(threshold: R) R

Get a subset of this resource type that exceeds the predefined threshold while attributes that are <= threshold are default-valued.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.NumericResourceUsage

Bases: ResourceUsage

A subtype of ResourceUsage where each attribute is either int or float. It provides reasonable default methods.

combine(other: N) N

Combine two resource usages of the same type

get_throttled(threshold: N) N

Get a subset of this resource type that exceeds the predefined threshold while attributes that are <= threshold are default-valued.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.ComputingUsage(*, utime: int = 0, stime: int = 0, maxrss: int = 0, inblock: int = 0, oublock: int = 0)

Bases: NumericResourceUsage

Basic computing resource usage defined in getrusage(2)

utime: int
stime: int
maxrss: int
inblock: int
oublock: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.CASUsage(*, read_bytes: int = 0, write_bytes: int = 0)

Bases: NumericResourceUsage

IO usage of ContentAddressableStorage

read_bytes: int
write_bytes: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.RPCUsage(*, execute: int = 0)

Bases: NumericResourceUsage

Counters of RPC invocations

execute: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.Usage(*, computing: ComputingUsage = ComputingUsage(utime=0, stime=0, maxrss=0, inblock=0, oublock=0), cas: CASUsage = CASUsage(read_bytes=0, write_bytes=0), rpc: RPCUsage = RPCUsage(execute=0))

Bases: ResourceUsage

The aggregation of all kinds of usages

computing: ComputingUsage
cas: CASUsage
rpc: RPCUsage
combine(other: Usage) Usage

Combine two resource usages of the same type

get_throttled(threshold: Usage) Usage

Get a subset of this resource type that exceeds the predefined threshold while attributes that are <= threshold are default-valued.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.GetThrottlingResponse(*, throttled: bool, tracked_usage: Usage | None = None, tracked_time_window_secs: int | None = None)

Bases: BaseModel

Summary if an identity should be throttled for the next remote execution

throttled: bool
tracked_usage: Usage | None
tracked_time_window_secs: int | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class buildgrid.server.metering.models.MeteringProtocol(*args, **kwargs)

Bases: Protocol

Protocol satisfied by both Metering (Redis-direct) and the deprecated SyncMeteringServiceClient.

get_throttling(identity: Identity) GetThrottlingResponse
put_usage(identity: Identity, operation_name: str, usage: Usage) None