Skip to content

Commit

Permalink
Adapt resource limit checks API and it's default implementation.
Browse files Browse the repository at this point in the history
- The default resource limit checks implementation now uses `monthly` as the default mode when no period is explicitly given.
- The Period is no more mandatory in case of the connection duration configuration.
- The documentation has been updated for the above points and for the removal of the obsolete DataVolumePeriod.

Signed-off-by: Kartheeswaran Kalidass <Kartheeswaran.Kalidass@bosch.io>
  • Loading branch information
kaniyan authored and sophokles73 committed Feb 6, 2020
1 parent 6ffdeb2 commit 354d49f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
Expand Up @@ -33,7 +33,7 @@ public class ConnectionDuration {
@JsonProperty(TenantConstants.FIELD_MAX_MINUTES)
private long maxMinutes = TenantConstants.UNLIMITED_MINUTES;

@JsonProperty(value = TenantConstants.FIELD_PERIOD, required = true)
@JsonProperty(value = TenantConstants.FIELD_PERIOD)
private ResourceLimitsPeriod period;

/**
Expand Down
Expand Up @@ -322,7 +322,10 @@ private void checkConnectionDurationLimit(final TenantObject tenant, final Map<S
final ConnectionDuration connectionDurationConfig = tenant.getResourceLimits().getConnectionDuration();
final long maxConnectionDurationInMinutes = connectionDurationConfig.getMaxMinutes();
final Instant effectiveSince = connectionDurationConfig.getEffectiveSince();
final PeriodMode periodMode = PeriodMode.from(connectionDurationConfig.getPeriod().getMode());
//If the period is not set explicitly, monthly is assumed as the default value
final PeriodMode periodMode = Optional.ofNullable(connectionDurationConfig.getPeriod())
.map(period -> PeriodMode.from(period.getMode()))
.orElse(PeriodMode.MONTHLY);
final long periodInDays = Optional.ofNullable(connectionDurationConfig.getPeriod())
.map(ResourceLimitsPeriod::getNoOfDays)
.orElse(0);
Expand Down Expand Up @@ -396,7 +399,10 @@ private void checkMessageLimit(
final DataVolume dataVolumeConfig = tenant.getResourceLimits().getDataVolume();
final long maxBytes = dataVolumeConfig.getMaxBytes();
final Instant effectiveSince = dataVolumeConfig.getEffectiveSince();
final PeriodMode periodMode = PeriodMode.from(dataVolumeConfig.getPeriod().getMode());
//If the period is not set explicitly, monthly is assumed as the default value
final PeriodMode periodMode = Optional.ofNullable(dataVolumeConfig.getPeriod())
.map(period -> PeriodMode.from(period.getMode()))
.orElse(PeriodMode.MONTHLY);
final long periodInDays = Optional.ofNullable(dataVolumeConfig.getPeriod())
.map(ResourceLimitsPeriod::getNoOfDays)
.orElse(0);
Expand Down
Expand Up @@ -722,7 +722,6 @@ components:
additionalProperties: false
required:
- effective-since
- period
properties:
"effective-since":
type: string
Expand Down
21 changes: 6 additions & 15 deletions site/documentation/content/api/tenant/index.md
Expand Up @@ -258,19 +258,10 @@ The table below contains the properties which are used to configure a tenant's c
| :------------------------| :-------: | :------------ | :------------ | :---------- |
| *effective-since* | *yes* | *string* | `-` | The point in time at which the current settings became effective, i.e. the start of the first accounting period based on these settings. The value MUST be an [ISO 8601 compliant *combined date and time representation in extended format*](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations).|
| *max-minutes* | *no* | *number* | `-1` | The maximum connection duration in minutes allowed for the tenant for each accounting period. MUST be an integer. Minus one indicates that no limit is set. |
| *period* | *no* | *object* | `-` | The mode and length of an accounting period, i.e. the resource usage is calculated based on the defined number of days or on a monthly basis. |
| *period* | *no* | *object* | `-` | The mode and length of an accounting period, i.e. the resource usage is calculated based on the defined number of days or on a monthly basis. For more information, please refer to the [resource limits period]({{< relref "#resource-limits-period-configuration-format" >}}).|

Protocol adapters that maintain *connection state* SHOULD use this information to determine if a connection request from a device should be accepted or not. For more information, please refer to the [connection duration limit concept]({{< relref "/concepts/resource-limits.md#connection-duration-limit" >}}).

### Resource Limits Period Configuration Format

The table below contains the properties that are used to configure a tenant's resource limits period:

| Name | Mandatory | JSON Type | Default Value | Description |
| :------------------------| :-------: | :------------ | :------------ | :---------- |
| *mode* | *yes* | *string* | `-` | The mode of the resource usage calculation. The default implementation supports two modes namely `days` and `monthly`. |
| *no-of-days* | *no* | *number* | `-` | When the mode is set as `days`, then this value represents the length of an accounting period , i.e. the number of days over which the resource usage is to be limited. MUST be a positive integer.|

### Data Volume Configuration Format

The table below contains the properties which are used to configure a tenant's data volume limit:
Expand All @@ -279,18 +270,18 @@ The table below contains the properties which are used to configure a tenant's d
| :------------------------| :-------: | :------------ | :------------ | :---------- |
| *effective-since* | *yes* | *string* | `-` | The point in time at which the current settings became effective, i.e. the start of the first accounting period based on these settings. The value MUST be an [ISO 8601 compliant *combined date and time representation in extended format*](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations).|
| *max-bytes* | *no* | *number* | `-1` | The maximum number of bytes allowed for the tenant for each accounting period. MUST be an integer. A negative value indicates that no limit is set. |
| *period* | *no* | *object* | `-` | The mode and length of an accounting period, i.e. the data usage can limited based on the defined number of days or on a monthly basis. |
| *period* | *no* | *object* | `-` | The mode and length of an accounting period, i.e. the data usage can limited based on the defined number of days or on a monthly basis. For more information, please refer to the [resource limits period]({{< relref "#resource-limits-period-configuration-format" >}}).|

Protocol adapters SHOULD use this information to determine if a message originating from or destined to a device should be accepted for processing.

### Data Volume Period Configuration Format
### Resource Limits Period Configuration Format

The table below contains the properties which are used to configure a tenant's data volume period:
The table below contains the properties that are used to configure a tenant's resource limits period:

| Name | Mandatory | JSON Type | Default Value | Description |
| :------------------------| :-------: | :------------ | :------------ | :---------- |
| *mode* | *yes* | *string* | `-` | The mode of the data usage calculation. The default implementation supports two modes namely `days` and `monthly`.|
| *no-of-days* | *no* | *number* | `-` | When the mode is set as `days`, then this value represents the length of an accounting period , i.e. the number of days over which the data usage is to be limited. MUST be a positive integer.|
| *mode* | *yes* | *string* | `-` | The mode of the resource usage calculation. The default implementation supports two modes namely `days` and `monthly`. |
| *no-of-days* | *no* | *number* | `-` | When the mode is set as `days`, then this value represents the length of an accounting period , i.e. the number of days over which the resource usage is to be limited. MUST be a positive integer.|

## Delivery States used by the Tenant API

Expand Down
4 changes: 2 additions & 2 deletions site/documentation/content/concepts/resource-limits.md
Expand Up @@ -18,7 +18,7 @@ The MQTT and AMQP protocol adapters keep the connections longer opened than thei

Before accepting a new connection request from a device, the overall amount of time that the devices have already been connected to protocol adapters for that tenant is checked against the configured limit by the protocol adapters. The connection request is declined if the connection duration limit has been already reached. This limit is only supported by protocol adapters that maintain *connection state* with authenticated devices. In particular, the HTTP adapter does not support this metric.

The default Prometheus based implementation uses connection duration as the factor to limit the connections. This default implementation supports two modes of connection duration limit calculation namely `days` and `monthly`. For more details on how to set the mode refer to the [Tenant API]({{< relref "/api/tenant#resource-limits-period-configuration-format" >}}).
The default Prometheus based implementation uses connection duration as the factor to limit the connections. This default implementation supports two modes of connection duration limit calculation namely `days` and `monthly`. For more details on how to set the mode refer to the [Tenant API]({{< relref "/api/tenant#resource-limits-period-configuration-format" >}}). If the period is not set explicitly, then the mode is assumed as *monthly* in the default implementation.

In the `monthly` mode, further device connections are only allowed, if the overall amount of time that the devices have already been connected from the beginning till the end of the current (Gregorian) calendar month does not exceed the configured *max-minutes* value. But for the first month, on which the connection duration limit became effective, the *effective connection duration limit* is calculated based on the *max-minutes* with respect to the remaining days in that month from the *effective-since* date.

Expand Down Expand Up @@ -54,7 +54,7 @@ In the `days` mode, further device connections are only allowed, if the overall

Hono supports limiting the number of messages that devices and north bound applications of a tenant can publish to Hono during a given time interval. Before accepting any telemetry or event or command messages from devices or north bound applications, it is checked by the protocol adapters that if the message limit is exceeded or not. The incoming message is discarded if the limit is exceeded.

The default Prometheus based implementation uses data volume as the factor to limit the messages. The data volume already consumed by a tenant over the given time interval is compared with the configured message limit before accepting any messages. The default implementation supports two modes of message limits calculation namely `days` and `monthly`. For more details on how to set the mode refer to the [Tenant API]({{< relref "/api/tenant#data-volume-period-configuration-format" >}}).
The default Prometheus based implementation uses data volume as the factor to limit the messages. The data volume already consumed by a tenant over the given time interval is compared with the configured message limit before accepting any messages. The default implementation supports two modes of message limits calculation namely `days` and `monthly`. For more details on how to set the mode refer to the [Tenant API]({{< relref "/api/tenant#resource-limits-period-configuration-format" >}}). If the period is not set explicitly, then the mode is assumed as *monthly* in the default implementation.

In the `monthly` mode, the message limit check ensures that the data usage from the beginning till the end of a (Gregorian) calendar month does not exceed the *max-bytes* value. But for the first month on which the message limit became effective, the *effective max-bytes* are calculated based on the *max-bytes* with respect to the remaining days in that month from the *effective-since* date.

Expand Down

0 comments on commit 354d49f

Please sign in to comment.