go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/quotapb/op.proto (about)

     1  // Copyright 2022 The LUCI Authors. All rights reserved.
     2  // Use of this source code is governed under the Apache License, Version 2.0
     3  // that can be found in the LICENSE file.
     4  
     5  syntax = "proto3";
     6  
     7  import "validate/validate.proto";
     8  
     9  import "go.chromium.org/luci/server/quota/quotapb/ids.proto";
    10  
    11  option go_package = "go.chromium.org/luci/server/quota/quotapb";
    12  
    13  package go.chromium.org.luci.server.quota.quotapb;
    14  
    15  // A single operation to apply to the quota state.
    16  //
    17  // NOTE: Keep in sync with RawOp, which is the type which is actually passed to
    18  // the update lua script.
    19  message Op {
    20    // The Account to adjust the value for.
    21    AccountID account_id = 1 [
    22      (validate.rules).message.required = true
    23    ];
    24  
    25    // The policy under which to adjust the account balance.
    26    //
    27    // If the policy is not specified, this will use the Policy already set on the
    28    // Account.
    29    //
    30    // If the Account doesn't already exist, this Op will fail with an error of
    31    // status MISSING_ACCOUNT, unless relative_to is ZERO.
    32    PolicyID policy_id = 2;
    33  
    34    enum RelativeTo {
    35      // This will apply Delta by adding it to the Account's current balance.
    36      //
    37      // Note that if the Account is new, and `policy_ref` was omitted, this will
    38      // fail with an error status MISSING_ACCOUNT.
    39      CURRENT_BALANCE = 0;
    40  
    41      // This will apply Delta by adding it to zero; This effectively allows you
    42      // to 'set' an Account to some specific value.
    43      ZERO = 1;
    44  
    45      // This will apply Delta by adding it to the policy `default` value.
    46      //
    47      // This uses the `default` field of the Account's current policy, if
    48      // `policy` on this Op is omitted. Otherwise this will use the `default`
    49      // field of the new policy.
    50      //
    51      // It is an error to use this RelativeTo value with an Account containing no
    52      // Policy, and this will result in an error status of POLICY_REQUIRED.
    53      DEFAULT = 2;
    54  
    55      // This will apply Delta by adding it to the policy `limit` value.
    56      // Usually this is used with a negative Delta.
    57      //
    58      // This uses the `limit` field of the Account's current policy, if
    59      // `limit` on this Op is omitted. Otherwise this will use the `limit`
    60      // field of the new policy.
    61      //
    62      // It is an error to use this RelativeTo value with an Account containing no
    63      // Policy, and this will result in an error status of POLICY_REQUIRED.
    64      LIMIT = 3;
    65    }
    66    // The value that `delta` is relative to, when calculating the new balance.
    67    RelativeTo relative_to = 3;
    68  
    69    // Delta is the number of units to add (or subtract) from the `relative_to` to
    70    // get a new `proposed` balance for the given Account.
    71    //
    72    // If `proposed` would bring a positive Account balance below 0, this will an
    73    // error with status UNDERFLOW.
    74    //   * IGNORE_POLICY_BOUNDS will allow this Op to bring the Account balance
    75    //     negative.
    76    //
    77    // If `proposed` would set the Account balance above Policy.limit, this will
    78    // instead set the Account balance to Policy.limit.
    79    //   * IGNORE_POLICY_BOUNDS will allow this Op to set the Account balance above
    80    //     Policy.limit.
    81    //   * DO_NOT_CAP_PROPOSED will cause this to be an error with status OVERFLOW.
    82    //
    83    // Adding to an account with a negative balance is OK, and will increase the
    84    // balance by the given amount (subject to the rules above).
    85    // Subtracting from an account with an over-limit balance is OK, and will
    86    // decrease the balance by the given amount (subject to the rules above).
    87    //
    88    // Ops with relative_to CURRENT_BALANCE or ZERO and no Policy set have no
    89    // boundaries (i.e. value can drop below zero or go all the way up to the
    90    // maximum balance without issue).
    91    //
    92    // Note that Ops with `delta == 0` are legitimate, for example:
    93    //   * as a means to apply a new policy without explicitly modifying
    94    //     the balance.
    95    //   * as a means to recalculate and save a refill policy value (note that
    96    //     this should not effect the observed value of the balance; e.g. delta:
    97    //     0 followed by delta: 1 at the same time will have the same cumulative
    98    //     effect as just delta: 1)
    99    //   * as a means to 'touch' an active account, resetting its updated_ts
   100    //     time and any potential expiration timer.
   101    int64 delta = 4 [(validate.rules).int64 = {
   102      gte: -9007199254740
   103      lte:  9007199254740
   104    }];
   105  
   106    // NOTE: Options is a collection of bit-field values, not a standard enum.
   107    enum Options {
   108      // Default value; no implied behavior change.
   109      NO_OPTIONS = 0;
   110  
   111      // If set, this Op can bring the account balance out of bounds; A positive
   112      // Delta will be allowed to bring the account balance above the
   113      // Policy.limit, and a negative Delta will be allowed to bring the account
   114      // balance below zero.
   115      //
   116      // NOTE: Regardless of this setting, Refill will never cause an Account to
   117      // go out of [0, Policy.limit], or cause an Account already in such a state
   118      // to go MORE out of bounds. This option only affects the behavior of `delta`.
   119      //
   120      // REQUIRED to do an operation on an Account with no associated Policy.
   121      //
   122      // Mutually exclusive with DO_NOT_CAP_PROPOSED.
   123      IGNORE_POLICY_BOUNDS = 1;
   124  
   125      // If set, and this Op's positive delta would be capped by the policy limit,
   126      // AND the new value would be greater than the current balance, this Op will
   127      // produce an error with status OVERFLOW.
   128      //
   129      // For example, if the account has a value 10 with a limit of 15, normally
   130      // an Op{CURRENT_BALANCE, +10} would result in a balance of 15, but if it
   131      // instead had this bit set, the Op would error out.
   132      //
   133      // Additionally, if an account has a value 20, with a limit of 10, normally
   134      // an Op{CURRENT_BALANCE, -5} would result in a balance of 10 (the limit),
   135      // but if it instead had this bit set, the Op would result in a balance of
   136      // 15.
   137      //
   138      // Mutually exclusive with IGNORE_POLICY_BOUNDS.
   139      // No-op for Ops with delta <= 0.
   140      DO_NOT_CAP_PROPOSED = 2;
   141      // If set, and if this Op introduces a policy change, i.e., it contains a
   142      // different policy_ref than what the account currently uses, the delta
   143      // between the new Policy.limit and old Policy.limit will be added to the
   144      // account's current balance. If the account has no existing policy_ref,
   145      // WITH_POLICY_LIMIT_DELTA is a noop.
   146      //
   147      // For example, if an account has a value of 3 with a limit of 5, and
   148      // the new policy_ref in this Op has a limit of 10, the account's value
   149      // with be updated to 8 (3 + delta, where delta = 10 - 5) before the Op is
   150      // applied. Similarly, if the limit were updated to 1 from 5, the account's
   151      // value will be updated to -1 (3 + delta, where delta = 1 - 5) before the
   152      // Op is applied.
   153      //
   154      // NOTE: IGNORE_POLICY_BOUNDS still works as documented if this option is
   155      // set, and WITH_POLICY_LIMIT_DELTA takes the balance below zero.
   156      WITH_POLICY_LIMIT_DELTA = 4;
   157      // Next entry is 8.
   158    }
   159    // Bitwise-OR of Options values.
   160    uint32 options = 5;
   161  }