Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
system_rewrite_options.h
Go to the documentation of this file.
1 // Copyright 2013 Google Inc.
16 
17 #ifndef PAGESPEED_SYSTEM_SYSTEM_REWRITE_OPTIONS_H_
18 #define PAGESPEED_SYSTEM_SYSTEM_REWRITE_OPTIONS_H_
19 
20 #include <set>
21 
23 #include "net/instaweb/rewriter/static_asset_config.pb.h"
33 
34 namespace net_instaweb {
35 
36 class MessageHandler;
37 
41  public:
42  typedef std::set<StaticAssetEnum::StaticAsset> StaticAssetSet;
43 
44  static const char kCentralControllerPort[];
45  static const char kPopularityContestMaxInFlight[];
46  static const char kPopularityContestMaxQueueSize[];
47  static const char kStaticAssetCDN[];
48  static const char kRedisServer[];
49  static const char kRedisReconnectionDelayMs[];
50  static const char kRedisTimeoutUs[];
51  static const char kRedisDatabaseIndex[];
52 
53  static constexpr int kMemcachedDefaultPort = 11211;
54  static constexpr int kRedisDefaultPort = 6379;
55 
56  static void Initialize();
57  static void Terminate();
58 
59  SystemRewriteOptions(const StringPiece& description,
60  ThreadSystem* thread_system);
61  explicit SystemRewriteOptions(ThreadSystem* thread_system);
62  virtual ~SystemRewriteOptions();
63 
64  virtual void Merge(const RewriteOptions& src);
65 
66  virtual OptionSettingResult ParseAndSetOptionFromName2(
67  StringPiece name, StringPiece arg1, StringPiece arg2,
68  GoogleString* msg, MessageHandler* handler);
69 
71 
72  int64 file_cache_clean_interval_ms() const {
73  return file_cache_clean_interval_ms_.value();
74  }
75  bool has_file_cache_clean_interval_ms() const {
76  return file_cache_clean_interval_ms_.was_set();
77  }
78  void set_file_cache_clean_interval_ms(int64 x) {
79  set_option(x, &file_cache_clean_interval_ms_);
80  }
81  int64 file_cache_clean_size_kb() const {
82  return file_cache_clean_size_kb_.value();
83  }
84  bool has_file_cache_clean_size_kb() const {
85  return file_cache_clean_size_kb_.was_set();
86  }
87  void set_file_cache_clean_size_kb(int64 x) {
88  set_option(x, &file_cache_clean_size_kb_);
89  }
90  int64 file_cache_clean_inode_limit() const {
91  return file_cache_clean_inode_limit_.value();
92  }
93  bool has_file_cache_clean_inode_limit() const {
94  return file_cache_clean_inode_limit_.was_set();
95  }
96  void set_file_cache_clean_inode_limit(int64 x) {
97  set_option(x, &file_cache_clean_inode_limit_);
98  }
99  int64 lru_cache_byte_limit() const {
100  return lru_cache_byte_limit_.value();
101  }
102  void set_lru_cache_byte_limit(int64 x) {
103  set_option(x, &lru_cache_byte_limit_);
104  }
105  int64 lru_cache_kb_per_process() const {
106  return lru_cache_kb_per_process_.value();
107  }
108  void set_lru_cache_kb_per_process(int64 x) {
109  set_option(x, &lru_cache_kb_per_process_);
110  }
111  bool use_shared_mem_locking() const {
112  return use_shared_mem_locking_.value();
113  }
114  void set_use_shared_mem_locking(bool x) {
115  set_option(x, &use_shared_mem_locking_);
116  }
117  bool compress_metadata_cache() const {
118  return compress_metadata_cache_.value();
119  }
120  void set_compress_metadata_cache(bool x) {
121  set_option(x, &compress_metadata_cache_);
122  }
123  bool statistics_enabled() const {
124  return statistics_enabled_.value();
125  }
126  void set_statistics_enabled(bool x) {
127  set_option(x, &statistics_enabled_);
128  }
129  bool statistics_logging_enabled() const {
130  return statistics_logging_enabled_.value();
131  }
132  void set_statistics_logging_enabled(bool x) {
133  set_option(x, &statistics_logging_enabled_);
134  }
135  int64 statistics_logging_max_file_size_kb() const {
136  return statistics_logging_max_file_size_kb_.value();
137  }
138  const GoogleString& statistics_logging_charts_css() const {
139  return statistics_logging_charts_css_.value();
140  }
141  const GoogleString& statistics_logging_charts_js() const {
142  return statistics_logging_charts_js_.value();
143  }
144  int64 statistics_logging_interval_ms() const {
145  return statistics_logging_interval_ms_.value();
146  }
147  void set_statistics_logging_interval_ms(int64 x) {
148  set_option(x, &statistics_logging_interval_ms_);
149  }
150  const GoogleString& file_cache_path() const {
151  return file_cache_path_.value();
152  }
153  void set_file_cache_path(const GoogleString& x) {
154  set_option(x, &file_cache_path_);
155  }
156  const GoogleString& log_dir() const { return log_dir_.value(); }
157  void set_log_dir(const GoogleString& x) { set_option(x, &log_dir_); }
158  const ExternalClusterSpec& memcached_servers() const {
159  return memcached_servers_.value();
160  }
161  void set_memcached_servers(const ExternalClusterSpec& x) {
162  set_option(x, &memcached_servers_);
163  }
164  int memcached_threads() const {
165  return memcached_threads_.value();
166  }
167  void set_memcached_threads(int x) {
168  set_option(x, &memcached_threads_);
169  }
170  int memcached_timeout_us() const {
171  return memcached_timeout_us_.value();
172  }
173  bool has_memcached_timeout_us() const {
174  return memcached_timeout_us_.was_set();
175  }
176  void set_memcached_timeout_us(int x) {
177  set_option(x, &memcached_timeout_us_);
178  }
179  const ExternalServerSpec& redis_server() const {
180  return redis_server_.value();
181  }
182  void set_redis_server(const ExternalServerSpec& x) {
183  set_option(x, &redis_server_);
184  }
185  int64 redis_reconnection_delay_ms() const {
186  return redis_reconnection_delay_ms_.value();
187  }
188  int64 redis_timeout_us() const {
189  return redis_timeout_us_.value();
190  }
191  int redis_database_index() const {
192  return redis_database_index_.value();
193  }
194  bool has_redis_database_index() const {
195  return redis_database_index_.was_set();
196  }
197  int64 slow_file_latency_threshold_us() const {
198  return slow_file_latency_threshold_us_.value();
199  }
200  bool has_slow_file_latency_threshold_us() const {
201  return slow_file_latency_threshold_us_.was_set();
202  }
203  void set_slow_file_latency_threshold_us(int64 x) {
204  set_option(x, &slow_file_latency_threshold_us_);
205  }
206  const GoogleString& fetcher_proxy() const {
207  return fetcher_proxy_.value();
208  }
209  void set_fetcher_proxy(const GoogleString& x) {
210  set_option(x, &fetcher_proxy_);
211  }
212 
213  const GoogleString& controller_port() const {
214  return controller_port_.value();
215  }
216  int popularity_contest_max_inflight_requests() const {
217  return popularity_contest_max_inflight_requests_.value();
218  }
219  int popularity_contest_max_queue_size() const {
220  return popularity_contest_max_queue_size_.value();
221  }
222 
224  void set_cache_flush_poll_interval_sec(int64 num_seconds) {
225  set_option(num_seconds, &cache_flush_poll_interval_sec_);
226  }
227  int64 cache_flush_poll_interval_sec() const {
228  return cache_flush_poll_interval_sec_.value();
229  }
230  void set_cache_flush_filename(const StringPiece& sp) {
231  set_option(sp.as_string(), &cache_flush_filename_);
232  }
233  const GoogleString& cache_flush_filename() const {
234  return cache_flush_filename_.value();
235  }
236 
237  const GoogleString& https_options() const {
238  return https_options_.value();
239  }
240  const GoogleString& ssl_cert_directory() const {
241  return ssl_cert_directory_.value();
242  }
243  const GoogleString& ssl_cert_file() const {
244  return ssl_cert_file_.value();
245  }
246 
247  int64 slurp_flush_limit() const {
248  return slurp_flush_limit_.value();
249  }
250  void set_slurp_flush_limit(int64 x) {
251  set_option(x, &slurp_flush_limit_);
252  }
253  bool slurp_read_only() const {
254  return slurp_read_only_.value();
255  }
256  void set_slurp_read_only(bool x) {
257  set_option(x, &slurp_read_only_);
258  }
259  bool rate_limit_background_fetches() const {
260  return rate_limit_background_fetches_.value();
261  }
262  const GoogleString& slurp_directory() const {
263  return slurp_directory_.value();
264  }
265  void set_slurp_directory(GoogleString x) {
266  set_option(x, &slurp_directory_);
267  }
268  bool disable_loopback_routing() const {
269  return disable_loopback_routing_.value();
270  }
271  bool fetch_with_gzip() const {
272  return fetch_with_gzip_.value();
273  }
274  int64 ipro_max_response_bytes() const {
275  return ipro_max_response_bytes_.value();
276  }
277  int64 ipro_max_concurrent_recordings() const {
278  return ipro_max_concurrent_recordings_.value();
279  }
280  int64 default_shared_memory_cache_kb() const {
281  return default_shared_memory_cache_kb_.value();
282  }
283  void set_default_shared_memory_cache_kb(int64 x) {
284  set_option(x, &default_shared_memory_cache_kb_);
285  }
286  int shm_metadata_cache_checkpoint_interval_sec() const {
287  return shm_metadata_cache_checkpoint_interval_sec_.value();
288  }
289  void set_purge_method(const GoogleString& x) {
290  set_option(x, &purge_method_);
291  }
292  const GoogleString& purge_method() const { return purge_method_.value(); }
293 
294  bool AllowDomain(const GoogleUrl& url,
295  const FastWildcardGroup& wildcard_group) const;
296 
299  bool StatisticsAccessAllowed(const GoogleUrl& url) const {
300  return AllowDomain(url, *statistics_domains_);
301  }
302  bool GlobalStatisticsAccessAllowed(const GoogleUrl& url) const {
303  return AllowDomain(url, *global_statistics_domains_);
304  }
305  bool MessagesAccessAllowed(const GoogleUrl& url) const {
306  return AllowDomain(url, *messages_domains_);
307  }
308  bool ConsoleAccessAllowed(const GoogleUrl& url) const {
309  return AllowDomain(url, *console_domains_);
310  }
311  bool AdminAccessAllowed(const GoogleUrl& url) const {
312  return AllowDomain(url, *admin_domains_);
313  }
314  bool GlobalAdminAccessAllowed(const GoogleUrl& url) const {
315  return AllowDomain(url, *global_admin_domains_);
316  }
317 
321  bool test_proxy() const {
322  return test_proxy_.value();
323  }
324  void set_test_proxy(bool x) {
325  set_option(x, &test_proxy_);
326  }
327 
332  return static_assets_to_cdn_.was_set();
333  }
334 
336  const StaticAssetSet& static_assets_to_cdn() const {
337  return static_assets_to_cdn_.asset_set();
338  }
339 
342  return static_assets_to_cdn_.value();
343  }
344 
346  void FillInStaticAssetCDNConf(StaticAssetConfig* out_conf) const;
347 
355  return test_proxy_slurp_.value();
356  }
357 
359  bool slurping_enabled() const {
360  return !slurp_directory().empty();
361  }
362 
363  bool slurping_enabled_read_only() const {
364  return slurping_enabled() && slurp_read_only();
365  }
366 
367  virtual SystemRewriteOptions* Clone() const;
368  virtual SystemRewriteOptions* NewOptions() const;
369 
372  static const SystemRewriteOptions* DynamicCast(
373  const RewriteOptions* instance);
374  static SystemRewriteOptions* DynamicCast(RewriteOptions* instance);
375 
379  StringPiece description() const { return description_; }
380  void set_description(const StringPiece& x) { x.CopyToString(&description_); }
381 
382  private:
385  class HttpsOptions : public Option<GoogleString> {
386  public:
387  virtual bool SetFromString(StringPiece value_string,
388  GoogleString* error_detail);
389  };
390 
391  class StaticAssetCDNOptions : public OptionTemplateBase<GoogleString> {
392  public:
393  virtual bool SetFromString(StringPiece value_string,
394  GoogleString* error_detail);
395 
396  virtual GoogleString Signature(const Hasher* hasher) const;
397  virtual GoogleString ToString() const;
398  virtual void Merge(const OptionBase* src);
399 
401  const StaticAssetSet& asset_set() const {
402  return *static_assets_to_cdn_.get();
403  }
404 
405  private:
407  CopyOnWrite<StaticAssetSet> static_assets_to_cdn_;
408  };
409 
410  template<typename Spec, int default_port>
411  class ExternalServersOption : public OptionTemplateBase<Spec> {
412  public:
413  bool SetFromString(StringPiece value_string,
414  GoogleString* error_detail) override {
415  return this->mutable_value().SetFromString(value_string, default_port,
416  error_detail);
417  }
418  GoogleString ToString() const override {
419  return this->value().ToString();
420  }
421  GoogleString Signature(const Hasher* hasher) const override {
422  return hasher->Hash(ToString());
423  }
424  };
425 
426  class ControllerPortOption : public Option<GoogleString> {
427  public:
428  bool SetFromString(StringPiece value_string,
429  GoogleString* error_detail) override;
430  };
431 
434  static Properties* system_properties_;
435 
438  template<class OptionClass>
439  static void AddSystemProperty(typename OptionClass::ValueType default_value,
440  OptionClass SystemRewriteOptions::*offset,
441  const char* id,
442  StringPiece option_name,
443  const char* help,
444  bool safe_to_print) {
445  AddProperty(default_value, offset, id, option_name, kServerScope, help,
446  safe_to_print, system_properties_);
447  }
448 
449  template<class OptionClass>
450  static void AddSystemProperty(typename OptionClass::ValueType default_value,
451  OptionClass SystemRewriteOptions::*offset,
452  const char* id,
453  StringPiece option_name,
454  OptionScope scope,
455  const char* help,
456  bool safe_to_print) {
457  AddProperty(default_value, offset, id, option_name, scope, help,
458  safe_to_print, system_properties_);
459  }
460 
461  static void AddProperties();
462 
464  GoogleString description_;
465 
466  Option<GoogleString> fetcher_proxy_;
467  Option<GoogleString> file_cache_path_;
468  Option<GoogleString> log_dir_;
469 
470  ExternalServersOption<ExternalClusterSpec, kMemcachedDefaultPort>
471  memcached_servers_;
472  ExternalServersOption<ExternalServerSpec, kRedisDefaultPort> redis_server_;
473  Option<GoogleString> statistics_logging_charts_css_;
474  Option<GoogleString> statistics_logging_charts_js_;
475  Option<GoogleString> cache_flush_filename_;
476  Option<GoogleString> ssl_cert_directory_;
477  Option<GoogleString> ssl_cert_file_;
478  HttpsOptions https_options_;
479 
480  Option<GoogleString> slurp_directory_;
481  Option<GoogleString> test_proxy_slurp_;
482 
483  Option<bool> statistics_enabled_;
484  Option<bool> statistics_logging_enabled_;
485  Option<bool> use_shared_mem_locking_;
486  Option<bool> compress_metadata_cache_;
487 
488  Option<bool> slurp_read_only_;
489  Option<bool> test_proxy_;
490  Option<bool> rate_limit_background_fetches_;
491 
494  Option<bool> disable_loopback_routing_;
495 
499  Option<bool> fetch_with_gzip_;
500 
501  ControllerPortOption controller_port_;
502  Option<int> popularity_contest_max_inflight_requests_;
503  Option<int> popularity_contest_max_queue_size_;
504 
505  Option<int> memcached_threads_;
506  Option<int> memcached_timeout_us_;
507  Option<int64> redis_reconnection_delay_ms_;
508  Option<int64> redis_timeout_us_;
509  Option<int> redis_database_index_;
510 
511  Option<int64> slow_file_latency_threshold_us_;
512  Option<int64> file_cache_clean_inode_limit_;
513  Option<int64> file_cache_clean_interval_ms_;
514  Option<int64> file_cache_clean_size_kb_;
515  Option<int64> lru_cache_byte_limit_;
516  Option<int64> lru_cache_kb_per_process_;
517  Option<int64> statistics_logging_interval_ms_;
520  Option<int64> cache_flush_poll_interval_sec_;
521  Option<int64> statistics_logging_max_file_size_kb_;
522  Option<int64> slurp_flush_limit_;
523  Option<int64> ipro_max_response_bytes_;
524  Option<int64> ipro_max_concurrent_recordings_;
525  Option<int64> default_shared_memory_cache_kb_;
526  Option<int> shm_metadata_cache_checkpoint_interval_sec_;
527  Option<GoogleString> purge_method_;
528 
529  StaticAssetCDNOptions static_assets_to_cdn_;
530 
531  CopyOnWrite<FastWildcardGroup> statistics_domains_;
532  CopyOnWrite<FastWildcardGroup> global_statistics_domains_;
533  CopyOnWrite<FastWildcardGroup> messages_domains_;
534  CopyOnWrite<FastWildcardGroup> console_domains_;
535  CopyOnWrite<FastWildcardGroup> admin_domains_;
536  CopyOnWrite<FastWildcardGroup> global_admin_domains_;
537 
538 
539 };
540 
541 }
542 
543 #endif
class GoogleUrl
Definition: google_url.h:58
static const SystemRewriteOptions * DynamicCast(const RewriteOptions *instance)
void FillInStaticAssetCDNConf(StaticAssetConfig *out_conf) const
Fills in an options proto based on the CDN settings passed above.
static void AddProperty(typename OptionClass::ValueType default_value, OptionClass RewriteOptionsSubclass::*offset, const char *id, StringPiece option_name, OptionScope scope, const char *help_text, bool safe_to_print, Properties *properties)
Adds a new Property to 'properties' (the last argument).
Definition: rewrite_options.h:3167
void set_cache_flush_poll_interval_sec(int64 num_seconds)
Cache flushing configuration.
Definition: system_rewrite_options.h:224
Definition: external_server_spec.h:27
GoogleString test_proxy_slurp() const
Definition: system_rewrite_options.h:354
StringPiece description() const
Definition: system_rewrite_options.h:379
bool slurping_enabled() const
Helper functions.
Definition: system_rewrite_options.h:359
Definition: system_rewrite_options.h:40
OptionScope
Definition: rewrite_options.h:629
virtual GoogleString SubclassSignatureLockHeld()
void set_option(const T &new_value, OptionTemplateBase< T > *option)
Definition: rewrite_options.h:3219
virtual SystemRewriteOptions * NewOptions() const
Make an empty options object of the same type as this.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
const StaticAssetSet & static_assets_to_cdn() const
Particular assets to serve of an external URL.
Definition: system_rewrite_options.h:336
bool has_static_assets_to_cdn() const
Definition: system_rewrite_options.h:331
bool StatisticsAccessAllowed(const GoogleUrl &url) const
Definition: system_rewrite_options.h:299
const Hasher * hasher() const
Returns the hasher used for signatures and URLs to purge.
Definition: rewrite_options.h:3021
Definition: rewrite_options.h:633
Definition: thread_system.h:40
OptionSettingResult
Used for return value of SetOptionFromName.
Definition: rewrite_options.h:813
Definition: message_handler.h:39
Definition: external_server_spec.h:44
const GoogleString & static_assets_cdn_base() const
Base URL to serve them from.
Definition: system_rewrite_options.h:341
virtual SystemRewriteOptions * Clone() const
Definition: rewrite_options.h:84
virtual void Merge(const RewriteOptions &src)
bool test_proxy() const
Definition: system_rewrite_options.h:321