Class QoSHandler
- java.lang.Object
-
- org.swisspush.gateleen.qos.QoSHandler
-
- All Implemented Interfaces:
org.swisspush.gateleen.core.logging.LoggableResource
public class QoSHandler extends java.lang.Object implements org.swisspush.gateleen.core.logging.LoggableResourceQoS Handler.{ "config":{ "percentile":75, "quorum":40, "period":5, "minSampleCount" : 1000, "minSentinelCount" : 5 }, "sentinels":{ "sentinelA":{ "percentile":50 }, "sentinelB":{}, "sentinelC":{}, "sentinelD":{} }, "rules":{ "/test/myapi1/v1/.*":{ "reject":1.2, "warn":0.5 }, "/test/myapi2/v1/.*":{ "reject":0.3 } } }The
configsection defines the global settings of the QoS.
percentile: Indicates which percentile value from the metrics will be used (eg. 50, 75, 95, 98, 999 or 99)
quorum: Percentage of the the sentinels which have to be over the calculated threshold to trigger the given rule.
period: The period (in seconds) after which a new calculation is triggered. If a rule is set to reject requests, it will reject requests until the next period.
minSampleCount: The min. count of the samples a sentinel has to provide to be regarded for the QoS calculation.
minSentinelCount:The min count of sentinels which have to be available to perform a QoS calculation. A sentinel is only available if it corresponds to the minSampleCount rule.
The
sentinelssection defines which metrics (defined in the routing rules) will be used as sentinels. To determine the load, the lowest measured percentile value will be preserved for each sentinel and put in relation to the current percentile value. This calculated ratio is later used to check if a rule needs some actions or not. You can override the taken percentile value for a specific sentinel by setting the attributepercentile.The
rulessection defines the rules for the QoS. Each rule is based on a pattern like the routing rules.
The possible attributes are:
reject: The ratio (eg. 1.3 means that *quorum* % of all sentinels must have an even or greater current ratio) which defines when a rule rejects the given request.
warn: The ratio which defines when a rule writes a warning in the log without rejecting the given request.
You can combine warn and reject
- Author:
- https://github.com/ljucam [Mario Ljuca]
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringREJECT_ACTIONprotected static java.lang.StringWARN_ACTION
-
Constructor Summary
Constructors Constructor Description QoSHandler(io.vertx.core.Vertx vertx, org.swisspush.gateleen.core.storage.ResourceStorage storage, java.lang.String qosSettingsPath, java.util.Map<java.lang.String,java.lang.Object> properties, java.lang.String prefix)Creates a new instance of the QoSHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanactionNecessary(java.lang.Double ratio, double thresholdSentinelRatio)Takes the ratio of the rule and compares if the calculated sentinel ratio from the desc.protected voidcancelTimer()Cancels the timer.protected QoSConfigcreateQoSConfig(io.vertx.core.json.JsonObject qosSettings)Creates the QoS config object from the given JsonObject and returns it.protected java.util.List<QoSSentinel>createQoSSentinels(io.vertx.core.json.JsonObject qosSettings)Creates the QoS sentinel objects from the given JsonObject and returns them in a list.voidenableResourceLogging(boolean resourceLoggingEnabled)protected voidevaluateQoSActions()Calculates the threshold and determines if any action for each rule has to be applied.QoSSentinelgetOldSentinel(java.lang.String sentinelName)We try to retrive the old sentinel (if available).protected java.util.List<QoSRule>getQosRules()Returns a list of the QoS rules.protected java.util.List<QoSSentinel>getQosSentinels()Gets a list of all sentinels.booleanhandle(io.vertx.core.http.HttpServerRequest request)Processes the request if it’s a request concerning the updates of the QoS settings or if it’s a request affected by the QoS rules.protected io.vertx.core.json.JsonObjectparseQoSSettings(io.vertx.core.buffer.Buffer buffer)Tries to parse the QoS settings.protected voidsetGlobalQoSConfig(QoSConfig globalQoSConfig)Sets the global configuration for the QoS.protected voidsetMBeanServer(javax.management.MBeanServer mbeanServer)Sets the mbean server.protected voidsetQosRules(java.util.List<QoSRule> qosRules)Sets the QoS rules.protected voidsetQosSentinels(java.util.List<QoSSentinel> qosSentinels)Sets a list of all sentinels.
-
-
-
Field Detail
-
REJECT_ACTION
protected static final java.lang.String REJECT_ACTION
- See Also:
- Constant Field Values
-
WARN_ACTION
protected static final java.lang.String WARN_ACTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QoSHandler
public QoSHandler(io.vertx.core.Vertx vertx, org.swisspush.gateleen.core.storage.ResourceStorage storage, java.lang.String qosSettingsPath, java.util.Map<java.lang.String,java.lang.Object> properties, java.lang.String prefix)Creates a new instance of the QoSHandler.- Parameters:
vertx- vertx referencestorage- storage referenceqosSettingsPath- the url path to the QoS rulesproperties- the propertiesprefix- the prefix for the server
-
-
Method Detail
-
enableResourceLogging
public void enableResourceLogging(boolean resourceLoggingEnabled)
- Specified by:
enableResourceLoggingin interfaceorg.swisspush.gateleen.core.logging.LoggableResource
-
setMBeanServer
protected void setMBeanServer(javax.management.MBeanServer mbeanServer)
Sets the mbean server. This method is usefull for mocking in tests.- Parameters:
mbeanServer- a mbean server
-
handle
public boolean handle(io.vertx.core.http.HttpServerRequest request)
Processes the request if it’s a request concerning the updates of the QoS settings or if it’s a request affected by the QoS rules. In either case the return value will betrueotherwisefalse.- Parameters:
request-- Returns:
- true if request is QoS update or affected by the rules, otherwise false.
-
createQoSConfig
protected QoSConfig createQoSConfig(io.vertx.core.json.JsonObject qosSettings)
Creates the QoS config object from the given JsonObject and returns it.- Parameters:
qosSettings- json object- Returns:
- the global QoS config object, null if the config section is not present.
-
createQoSSentinels
protected java.util.List<QoSSentinel> createQoSSentinels(io.vertx.core.json.JsonObject qosSettings)
Creates the QoS sentinel objects from the given JsonObject and returns them in a list.- Parameters:
qosSettings- json object- Returns:
- a list with the QoSSentinel objects, empty if the sentinel section is not present or empty.
-
getOldSentinel
public QoSSentinel getOldSentinel(java.lang.String sentinelName)
We try to retrive the old sentinel (if available).- Parameters:
sentinelName- the name of the sentinel.- Returns:
- old sentinel object or null if no sentinel was found
-
parseQoSSettings
protected io.vertx.core.json.JsonObject parseQoSSettings(io.vertx.core.buffer.Buffer buffer)
Tries to parse the QoS settings.- Parameters:
buffer- buffer from the request- Returns:
- a JsonObject containing the settings.
-
cancelTimer
protected void cancelTimer()
Cancels the timer.
This method is protected to be used in tests where you wish to manually trigger the evaluation.
-
evaluateQoSActions
protected void evaluateQoSActions()
Calculates the threshold and determines if any action for each rule has to be applied.
-
actionNecessary
protected boolean actionNecessary(java.lang.Double ratio, double thresholdSentinelRatio)Takes the ratio of the rule and compares if the calculated sentinel ratio from the desc. sorted list at the index coresponding to the percentual value (quorum) of all sentinel api's is lower or even.- Parameters:
ratio-thresholdSentinelRatio-- Returns:
- true if any action must be applied, otherwise false
-
setGlobalQoSConfig
protected void setGlobalQoSConfig(QoSConfig globalQoSConfig)
Sets the global configuration for the QoS.- Parameters:
globalQoSConfig- the config object for QoS.
-
getQosRules
protected java.util.List<QoSRule> getQosRules()
Returns a list of the QoS rules.- Returns:
- list of QoS rules.
-
setQosRules
protected void setQosRules(java.util.List<QoSRule> qosRules)
Sets the QoS rules.- Parameters:
qosRules- a list of the QoS rule objects
-
setQosSentinels
protected void setQosSentinels(java.util.List<QoSSentinel> qosSentinels)
Sets a list of all sentinels.- Parameters:
qosSentinels- list with sentinel objects
-
getQosSentinels
protected java.util.List<QoSSentinel> getQosSentinels()
Gets a list of all sentinels.- Returns:
- list with sentinel objects
-
-