class DailyTagPurgeLimitCheck in CloudFlare 8
Checks that the site is within CloudFlare's daily tag purge rate limit.
CloudFlare currently has a rate limit of 2000 tag purges/day.
@todo We hope this limit is raised soon!
Plugin annotation
@PurgeDiagnosticCheck(
id = "cloudflare_daily_limit_check",
title = @Translation("CloudFlare - Daily Tag Purge Limit"),
description = @Translation("Checks that the site is not violating CloudFlare's daily purge limit."),
dependent_queue_plugins = {},
dependent_purger_plugins = {"cloudflare"}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase implements DiagnosticCheckInterface
- class \Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\DailyTagPurgeLimitCheck implements DiagnosticCheckInterface
- class \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase implements DiagnosticCheckInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DailyTagPurgeLimitCheck
See also
https://support.cloudflare.com/hc/en-us/articles/206596608-How-to-Purge-...
1 file declares its use of DailyTagPurgeLimitCheck
- DailyTagPurgeLimitCheckTest.php in modules/
cloudflarepurger/ tests/ src/ Unit/ DailyTagPurgeLimitCheckTest.php
File
- modules/
cloudflarepurger/ src/ Plugin/ Purge/ DiagnosticCheck/ DailyTagPurgeLimitCheck.php, line 28
Namespace
Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheckView source
class DailyTagPurgeLimitCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
/**
* Tracks rate limits associated with CloudFlare Api.
*
* @var \Drupal\cloudflare\CloudFlareStateInterface
*/
protected $state;
/**
* Flag for if dependencies for CloudFlare are met.
*
* @var bool
*/
protected $areCloudFlareComposerDependenciesMet;
/**
* Constructs a DailyTagPurgeLimitCheck object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\cloudflare\CloudFlareStateInterface $state
* Tracks rate limits associated with CloudFlare Api.
* @param bool $composer_dependencies_met
* Checks that the composer dependencies for CloudFlare are met.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CloudFlareStateInterface $state, $composer_dependencies_met) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->state = $state;
$this->areCloudFlareComposerDependenciesMet = $composer_dependencies_met;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('cloudflare.state'), $container
->get('cloudflare.composer_dependency_check')
->check());
}
/**
* {@inheritdoc}
*/
public function run() {
if (!$this->areCloudFlareComposerDependenciesMet) {
$this->recommendation = $this
->t("Composer dependencies unmet. Unable to assess API rate limits.");
return SELF::SEVERITY_ERROR;
}
// Current number of purges today.
$daily_count = $this->state
->getTagDailyCount();
$this->value = $daily_count;
// Warn at 75% of capacity.
$daily_warning_level = 0.75 * CloudFlareAPI::API_TAG_PURGE_DAILY_RATE_LIMIT;
$message_variables = [
':daily_limit' => CloudFlareAPI::API_TAG_PURGE_DAILY_RATE_LIMIT,
':$daily_count' => $daily_count,
];
if ($daily_count >= CloudFlareAPI::API_TAG_PURGE_DAILY_RATE_LIMIT) {
$this->recommendation = $this
->t('Past Api limit of :daily_count/:daily_limit limit tag purges/day.', $message_variables);
return SELF::SEVERITY_ERROR;
}
elseif ($daily_count >= $daily_warning_level) {
$this->recommendation = $this
->t('Approaching Api limit of :daily_count/:daily_limit limit tag purges/day.', $message_variables);
return SELF::SEVERITY_WARNING;
}
elseif ($daily_count < $daily_warning_level) {
$this->recommendation = $this
->t('Site is safely below the daily limit of :daily_limit tag purges/day.', $message_variables);
return SELF::SEVERITY_OK;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DailyTagPurgeLimitCheck:: |
protected | property | Flag for if dependencies for CloudFlare are met. | |
DailyTagPurgeLimitCheck:: |
protected | property | Tracks rate limits associated with CloudFlare Api. | |
DailyTagPurgeLimitCheck:: |
public static | function |
Creates an instance of the plugin. Overrides DiagnosticCheckBase:: |
|
DailyTagPurgeLimitCheck:: |
public | function |
Perform the check and determine the severity level. Overrides DiagnosticCheckInterface:: |
|
DailyTagPurgeLimitCheck:: |
public | function |
Constructs a DailyTagPurgeLimitCheck object. Overrides PluginBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DiagnosticCheckBase:: |
private | property | The description of the check as described in the plugin's metadata. | |
DiagnosticCheckBase:: |
protected | property | A recommendation matching the severity level, may contain NULL. | |
DiagnosticCheckBase:: |
private | property | The severity of the outcome of this check. | |
DiagnosticCheckBase:: |
private | property | The title of the check as described in the plugin's metadata. | |
DiagnosticCheckBase:: |
protected | property | Optional check outcome / value (e.g. version numbers), may contain NULL. | |
DiagnosticCheckBase:: |
public | function |
Gets the description of the check. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get a recommendation matching the severity level, may return NULL. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Generates a individual Drupal-like requirements array. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level, expressed as a status_report severity. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level as unprefixed string. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Gets the title of the check. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get an optional value for the check output, may return NULL. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
protected | function | Late runtime helper to assure that ::run() got called (and only once). | |
DiagnosticCheckInterface:: |
constant | BLOCKING severity -- Error condition; purge.purgers service cannot operate. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- Informational message only. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- check successfully passed. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- Warning condition; proceed but flag warning. | ||
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |