|
| 1 | +/* Copyright 2017 Google Inc. All Rights Reserved. |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +#ifndef MIXERCLIENT_OPTIONS_H |
| 17 | +#define MIXERCLIENT_OPTIONS_H |
| 18 | + |
| 19 | +#include <memory> |
| 20 | + |
| 21 | +namespace istio { |
| 22 | +namespace mixer_client { |
| 23 | + |
| 24 | +// Options controlling check behavior. |
| 25 | +struct CheckOptions { |
| 26 | + // Default constructor. |
| 27 | + // Default options are chosen from experience. |
| 28 | + CheckOptions() |
| 29 | + : num_entries(10000), flush_interval_ms(500), expiration_ms(1000) {} |
| 30 | + |
| 31 | + // Constructor. |
| 32 | + // cache_entries is the maximum number of cache entries that can be kept in |
| 33 | + // the cache. Cache is disabled when cache_entries <= 0. |
| 34 | + // flush_cache_entry_interval_ms is the maximum milliseconds before an |
| 35 | + // check request needs to send to remote server again. |
| 36 | + // response_expiration_ms is the maximum milliseconds before a cached check |
| 37 | + // response is invalidated. We make sure that it is at least |
| 38 | + // flush_cache_entry_interval_ms + 1. |
| 39 | + CheckOptions(int cache_entries, int flush_cache_entry_interval_ms, |
| 40 | + int response_expiration_ms) |
| 41 | + : num_entries(cache_entries), |
| 42 | + flush_interval_ms(flush_cache_entry_interval_ms), |
| 43 | + expiration_ms(std::max(flush_cache_entry_interval_ms + 1, |
| 44 | + response_expiration_ms)) {} |
| 45 | + |
| 46 | + // Maximum number of cache entries kept in the cache. |
| 47 | + // Set to 0 will disable caching. |
| 48 | + const int num_entries; |
| 49 | + |
| 50 | + // Maximum milliseconds before check requests are flushed to the |
| 51 | + // server. The flush is triggered by a check request. |
| 52 | + const int flush_interval_ms; |
| 53 | + |
| 54 | + // Maximum milliseconds before a cached check response should be deleted. The |
| 55 | + // deletion is triggered by a timer. This value must be larger than |
| 56 | + // flush_interval_ms. |
| 57 | + const int expiration_ms; |
| 58 | +}; |
| 59 | + |
| 60 | +// Options controlling report behavior. |
| 61 | +struct ReportOptions { |
| 62 | + // Default constructor. |
| 63 | + ReportOptions() : num_entries(10000), flush_interval_ms(1000) {} |
| 64 | + |
| 65 | + // Constructor. |
| 66 | + // cache_entries is the maximum number of cache entries that can be kept in |
| 67 | + // the cache. Cache is disabled when cache_entries <= 0. |
| 68 | + // flush_cache_entry_interval_ms is the maximum milliseconds before |
| 69 | + // report requests are flushed to the server. The cache entry is deleted after |
| 70 | + // the flush. |
| 71 | + ReportOptions(int cache_entries, int flush_cache_entry_interval_ms) |
| 72 | + : num_entries(cache_entries), |
| 73 | + flush_interval_ms(flush_cache_entry_interval_ms) {} |
| 74 | + |
| 75 | + // Maximum number of cache entries kept in the cache. |
| 76 | + // Set to 0 will disable caching. |
| 77 | + const int num_entries; |
| 78 | + |
| 79 | + // Maximum milliseconds before report requests are flushed to the |
| 80 | + // server. The flush is triggered by a timer. |
| 81 | + const int flush_interval_ms; |
| 82 | +}; |
| 83 | + |
| 84 | +// Options controlling quota behavior. |
| 85 | +struct QuotaOptions { |
| 86 | + // Default constructor. |
| 87 | + QuotaOptions() |
| 88 | + : num_entries(10000), flush_interval_ms(500), expiration_ms(1000) {} |
| 89 | + |
| 90 | + // Constructor. |
| 91 | + // cache_entries is the maximum number of cache entries that can be kept in |
| 92 | + // the cache. Cache is disabled when cache_entries <= 0. |
| 93 | + // flush_cache_entry_interval_ms is the maximum milliseconds before an |
| 94 | + // quota request needs to send to remote server again. |
| 95 | + // response_expiration_ms is the maximum milliseconds before a cached quota |
| 96 | + // response is invalidated. We make sure that it is at least |
| 97 | + // flush_cache_entry_interval_ms + 1. |
| 98 | + QuotaOptions(int cache_entries, int flush_cache_entry_interval_ms, |
| 99 | + int response_expiration_ms) |
| 100 | + : num_entries(cache_entries), |
| 101 | + flush_interval_ms(flush_cache_entry_interval_ms), |
| 102 | + expiration_ms(std::max(flush_cache_entry_interval_ms + 1, |
| 103 | + response_expiration_ms)) {} |
| 104 | + |
| 105 | + // Maximum number of cache entries kept in the cache. |
| 106 | + // Set to 0 will disable caching. |
| 107 | + const int num_entries; |
| 108 | + |
| 109 | + // Maximum milliseconds before quota requests are flushed to the |
| 110 | + // server. The flush is triggered by a quota request. |
| 111 | + const int flush_interval_ms; |
| 112 | + |
| 113 | + // Maximum milliseconds before a cached quota response should be deleted. The |
| 114 | + // deletion is triggered by a timer. This value must be larger than |
| 115 | + // flush_interval_ms. |
| 116 | + const int expiration_ms; |
| 117 | +}; |
| 118 | + |
| 119 | +} // namespace mixer_client |
| 120 | +} // namespace istio |
| 121 | + |
| 122 | +#endif // MIXERCLIENT_OPTIONS_H |
0 commit comments