go.temporal.io/server@v1.23.0/common/dynamicconfig/shared_constants.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package dynamicconfig
    26  
    27  import (
    28  	"math/rand"
    29  
    30  	"go.temporal.io/server/common/metrics"
    31  	"go.temporal.io/server/common/primitives"
    32  )
    33  
    34  const GlobalDefaultNumTaskQueuePartitions = 4
    35  
    36  var defaultNumTaskQueuePartitions = []ConstrainedValue{
    37  	// The per-ns worker task queue in all namespaces should only have one partition, since
    38  	// we'll only run one worker per task queue.
    39  	{
    40  		Constraints: Constraints{
    41  			TaskQueueName: primitives.PerNSWorkerTaskQueue,
    42  		},
    43  		Value: 1,
    44  	},
    45  
    46  	// The system activity worker task queues in the system local namespace should only have
    47  	// one partition, since we'll only run one worker per task queue.
    48  	{
    49  		Constraints: Constraints{
    50  			TaskQueueName: primitives.AddSearchAttributesActivityTQ,
    51  			Namespace:     primitives.SystemLocalNamespace,
    52  		},
    53  		Value: 1,
    54  	},
    55  	{
    56  		Constraints: Constraints{
    57  			TaskQueueName: primitives.DeleteNamespaceActivityTQ,
    58  			Namespace:     primitives.SystemLocalNamespace,
    59  		},
    60  		Value: 1,
    61  	},
    62  	{
    63  		Constraints: Constraints{
    64  			TaskQueueName: primitives.MigrationActivityTQ,
    65  			Namespace:     primitives.SystemLocalNamespace,
    66  		},
    67  		Value: 1,
    68  	},
    69  
    70  	// TODO: After we have a solution for ensuring no tasks are lost, add a constraint here for
    71  	// all task queues in SystemLocalNamespace to have one partition.
    72  
    73  	// Default for everything else:
    74  	{
    75  		Value: GlobalDefaultNumTaskQueuePartitions,
    76  	},
    77  }
    78  
    79  var DefaultPerShardNamespaceRPSMax = GetIntPropertyFilteredByNamespace(0)
    80  
    81  const (
    82  	// dynamic config map keys and defaults for client.DynamicRateLimitingParams for controlling dynamic rate limiting options
    83  	// dynamicRateLimitEnabledKey toggles whether dynamic rate limiting is enabled
    84  	dynamicRateLimitEnabledKey     = "enabled"
    85  	dynamicRateLimitEnabledDefault = false
    86  	// dynamicRateLimitRefreshIntervalKey is how often the rate limit and dynamic properties are refreshed. should be a string timestamp e.g. 10s
    87  	// even if the rate limiter is disabled, this property will still determine how often the dynamic config is reevaluated
    88  	dynamicRateLimitRefreshIntervalKey     = "refreshInterval"
    89  	dynamicRateLimitRefreshIntervalDefault = "10s"
    90  	// dynamicRateLimitLatencyThresholdKey is the maximum average latency in ms before the rate limiter should backoff
    91  	dynamicRateLimitLatencyThresholdKey     = "latencyThreshold"
    92  	dynamicRateLimitLatencyThresholdDefault = 0.0 // will not do backoff based on latency
    93  	// dynamicRateLimitErrorThresholdKey is the maximum ratio of errors:total_requests before the rate limiter should backoff. should be between 0 and 1
    94  	dynamicRateLimitErrorThresholdKey     = "errorThreshold"
    95  	dynamicRateLimitErrorThresholdDefault = 0.0 // will not do backoff based on errors
    96  	// dynamicRateLimitBackoffStepSizeKey is the amount the rate limit multiplier is reduced when backing off. should be between 0 and 1
    97  	dynamicRateLimitBackoffStepSizeKey     = "rateBackoffStepSize"
    98  	dynamicRateLimitBackoffStepSizeDefault = 0.3
    99  	// dynamicRateLimitIncreaseStepSizeKey the amount the rate limit multiplier is increased when the system is healthy. should be between 0 and 1
   100  	dynamicRateLimitIncreaseStepSizeKey     = "rateIncreaseStepSize"
   101  	dynamicRateLimitIncreaseStepSizeDefault = 0.1
   102  	// dynamicRateLimitMultiMinKey is the minimum the rate limit multiplier can be reduced to
   103  	dynamicRateLimitMultiMinKey     = "rateMultiMin"
   104  	dynamicRateLimitMultiMinDefault = 0.8
   105  	// dynamicRateLimitMultiMaxKey is the maximum the rate limit multiplier can be increased to
   106  	dynamicRateLimitMultiMaxKey     = "rateMultiMax"
   107  	dynamicRateLimitMultiMaxDefault = 1.0
   108  )
   109  
   110  var DefaultDynamicRateLimitingParams = map[string]interface{}{
   111  	dynamicRateLimitEnabledKey:          dynamicRateLimitEnabledDefault,
   112  	dynamicRateLimitRefreshIntervalKey:  dynamicRateLimitRefreshIntervalDefault,
   113  	dynamicRateLimitLatencyThresholdKey: dynamicRateLimitLatencyThresholdDefault,
   114  	dynamicRateLimitErrorThresholdKey:   dynamicRateLimitErrorThresholdDefault,
   115  	dynamicRateLimitBackoffStepSizeKey:  dynamicRateLimitBackoffStepSizeDefault,
   116  	dynamicRateLimitIncreaseStepSizeKey: dynamicRateLimitIncreaseStepSizeDefault,
   117  	dynamicRateLimitMultiMinKey:         dynamicRateLimitMultiMinDefault,
   118  	dynamicRateLimitMultiMaxKey:         dynamicRateLimitMultiMaxDefault,
   119  }
   120  
   121  // AccessHistory is an interim config helper for dialing fraction of FE->History calls
   122  // DEPRECATED: Remove once migration is complete
   123  func AccessHistory(accessHistoryFraction FloatPropertyFn, metricsHandler metrics.Handler) bool {
   124  	if rand.Float64() < accessHistoryFraction() {
   125  		metricsHandler.Counter(metrics.AccessHistoryNew).Record(1)
   126  		return true
   127  	}
   128  	metricsHandler.Counter(metrics.AccessHistoryOld).Record(1)
   129  	return false
   130  }