Skip to content

Commit 1bb6c34

Browse files
committed
specific metrics for unknown messages
Signed-off-by: Bob Claerhout <[email protected]>
1 parent 4a8911a commit 1bb6c34

26 files changed

+502
-8
lines changed

adapters/http-base/src/main/java/org/eclipse/hono/adapter/http/AbstractVertxBasedHttpProtocolAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public abstract class AbstractVertxBasedHttpProtocolAdapter<T extends HttpProtoc
8585

8686
private static final String KEY_MATCH_ALL_ROUTE_APPLIED = "matchAllRouteApplied";
8787

88-
private HttpAdapterMetrics metrics = HttpAdapterMetrics.NOOP;
88+
protected HttpAdapterMetrics metrics = HttpAdapterMetrics.NOOP;
8989
private HttpServer server;
9090
private HttpServer insecureServer;
9191

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/LoraProtocolAdapter.java

+11
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ void handleProviderRoute(final HttpContext ctx, final LoraProvider provider) {
269269
currentSpan.finish();
270270
// discard the message but return 202 to not cause errors on the LoRa provider side
271271
handle202(ctx.getRoutingContext());
272+
273+
//TODO: add metrics
274+
metrics.reportTelemetry(
275+
endpoint,
276+
tenant,
277+
tenantTracker.result(),
278+
MetricsTags.ProcessingOutcome.FORWARDED,
279+
qos,
280+
payloadSize,
281+
ctx.getTtdStatus(),
282+
getMicrometerSample(ctx.getRoutingContext()));
272283
}
273284
} catch (final LoraProviderMalformedPayloadException e) {
274285
LOG.debug("error processing request from provider [name: {}]", provider.getProviderName(), e);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
14+
15+
package org.eclipse.hono.adapter.lora;
16+
17+
import com.google.common.io.BaseEncoding;
18+
import io.vertx.core.buffer.Buffer;
19+
import io.vertx.core.json.JsonObject;
20+
import java.util.Objects;
21+
22+
23+
/**
24+
* A Lora message that contains unknown data sent from an end-device to a Network Server.
25+
*
26+
*/
27+
public class UnknownLoraMessage implements LoraMessage {
28+
29+
/**
30+
* {@inheritDoc}
31+
*/
32+
@Override
33+
public final byte[] getDevEUI() {
34+
return new byte[0];
35+
}
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
@Override
41+
public final String getDevEUIAsString() {
42+
return "";
43+
}
44+
45+
/**
46+
* {@inheritDoc}
47+
*/
48+
@Override
49+
public final LoraMessageType getType() {
50+
return LoraMessageType.UNKNOWN;
51+
}
52+
53+
/**
54+
* {@inheritDoc}
55+
*/
56+
@Override
57+
public final Buffer getPayload() {
58+
return Buffer.buffer();
59+
}
60+
}

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/JsonBasedLoraProvider.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.hono.adapter.lora.LoraMessage;
2121
import org.eclipse.hono.adapter.lora.LoraMessageType;
2222
import org.eclipse.hono.adapter.lora.LoraMetaData;
23+
import org.eclipse.hono.adapter.lora.UnknownLoraMessage;
2324
import org.eclipse.hono.adapter.lora.UplinkLoraMessage;
2425
import org.eclipse.hono.util.CommandEndpoint;
2526
import org.eclipse.hono.util.Strings;
@@ -51,7 +52,7 @@ public LoraMessage getMessage(final RoutingContext ctx) {
5152
case UPLINK:
5253
return createUplinkMessage(ctx.request(), message);
5354
default:
54-
throw new LoraProviderMalformedPayloadException(String.format("unsupported message type [%s]", type));
55+
return createUnknownMessage(ctx.request(), message);
5556
}
5657
} catch (final RuntimeException e) {
5758
// catch generic exception in order to also cover any (runtime) exceptions
@@ -184,4 +185,26 @@ protected UplinkLoraMessage createUplinkMessage(final HttpServerRequest request,
184185
message.setAdditionalData(getAdditionalData(requestBody));
185186
return message;
186187
}
188+
189+
/**
190+
* Creates an object representation of a Lora unknown message.
191+
* <p>
192+
* This method uses the {@link #getDevEui(JsonObject)}
193+
* method to extract relevant information from the request body to add
194+
* to the returned message.
195+
*
196+
* @param request The request sent by the provider's Network Server.
197+
* @param requestBody The JSON object contained in the request's body.
198+
* @return The message.
199+
* @throws RuntimeException if the message cannot be parsed.
200+
*/
201+
protected UnknownLoraMessage createUnknownMessage(final HttpServerRequest request, final JsonObject requestBody) {
202+
203+
Objects.requireNonNull(requestBody);
204+
205+
final UnknownLoraMessage message = new UnknownLoraMessage();
206+
return message;
207+
}
208+
209+
187210
}

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/KerlinkProvider.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ public Set<String> pathPrefixes() {
7979
*/
8080
@Override
8181
public LoraMessageType getMessageType(final JsonObject loraMessage) {
82-
return LoraMessageType.UPLINK;
82+
if (loraMessage.containsKey(FIELD_KERLINK_PAYLOAD)){
83+
return LoraMessageType.UPLINK;
84+
}
85+
return LoraMessageType.UNKNOWN;
8386
}
8487

8588
@Override

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/KerlinkProviderCustomContentType.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ public Set<String> pathPrefixes() {
5757
*/
5858
@Override
5959
public LoraMessageType getMessageType(final JsonObject loraMessage) {
60-
return LoraMessageType.UPLINK;
60+
if (loraMessage.containsKey(FIELD_UPLINK_PAYLOAD))
61+
{
62+
return LoraMessageType.UPLINK;
63+
}
64+
return LoraMessageType.UNKNOWN;
6165
}
6266

6367
/**

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/OrbiwiseProvider.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ protected Buffer getPayload(final JsonObject loraMessage) {
8282
protected LoraMessageType getMessageType(final JsonObject loraMessage) {
8383

8484
Objects.requireNonNull(loraMessage);
85-
return LoraMessageType.UPLINK;
85+
if (loraMessage.containsKey(FIELD_ORBIWISE_PAYLOAD)){
86+
return LoraMessageType.UPLINK;
87+
}
88+
return LoraMessageType.UNKNOWN;
8689
}
8790

8891
@Override

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ProximusProvider.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public Set<String> pathPrefixes() {
6666
*/
6767
@Override
6868
protected LoraMessageType getMessageType(final JsonObject loraMessage) {
69-
return LoraMessageType.UPLINK;
69+
70+
if (loraMessage.containsKey(FIELD_PROXIMUS_PAYLOAD)){
71+
return LoraMessageType.UPLINK;
72+
}
73+
return LoraMessageType.UNKNOWN;
7074
}
7175

7276
@Override

adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ThingsNetworkProvider.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ public Set<String> pathPrefixes() {
7676
*/
7777
@Override
7878
protected LoraMessageType getMessageType(final JsonObject loraMessage) {
79-
return LoraMessageType.UPLINK;
79+
if (loraMessage.containsKey(FIELD_TTN_PAYLOAD_RAW)){
80+
return LoraMessageType.UPLINK;
81+
}
82+
return LoraMessageType.UNKNOWN;
8083
}
8184

8285
@Override

adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/LoraProviderTestBase.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.eclipse.hono.adapter.lora.LoraCommand;
2626
import org.eclipse.hono.adapter.lora.LoraMessageType;
27+
import org.eclipse.hono.adapter.lora.UnknownLoraMessage;
2728
import org.eclipse.hono.adapter.lora.UplinkLoraMessage;
2829
import org.eclipse.hono.util.CommandEndpoint;
2930
import org.junit.jupiter.api.BeforeEach;
@@ -65,7 +66,7 @@ public abstract class LoraProviderTestBase<T extends LoraProvider> {
6566
*/
6667
protected final RoutingContext getRequestContext(final LoraMessageType type, final String... classifiers) throws IOException {
6768

68-
final Buffer message = LoraTestUtil.loadTestFile(provider.getProviderName(), LoraMessageType.UPLINK, classifiers);
69+
final Buffer message = LoraTestUtil.loadTestFile(provider.getProviderName(), type, classifiers);
6970
final HttpServerRequest request = mock(HttpServerRequest.class);
7071
final RoutingContext routingContext = mock(RoutingContext.class);
7172
when(routingContext.request()).thenReturn(request);
@@ -99,6 +100,19 @@ public void testGetMessageSucceedsForUplinkMessage() throws IOException {
99100
assertMetaDataForUplinkMessage(loraMessage);
100101
}
101102

103+
/**
104+
* Verifies that uplink messages are parsed correctly.
105+
*
106+
* @throws IOException If the file containing the example message could not be loaded.
107+
*/
108+
@Test
109+
public void testGetMessageSucceedsForUnknownMessage() throws IOException {
110+
111+
final RoutingContext request = getRequestContext(LoraMessageType.UNKNOWN);
112+
final UnknownLoraMessage loraMessage = (UnknownLoraMessage) provider.getMessage(request);
113+
assertThat(loraMessage.getType()).isEqualTo(LoraMessageType.UNKNOWN);
114+
}
115+
102116
/**
103117
* Asserts presence of common properties in an uplink message.
104118
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"DevEUI_unknown": {
3+
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"DevEUI_unknown": {
3+
}
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"applicationID": "123",
3+
"applicationName": "temperature-sensor",
4+
"deviceName": "garden-sensor",
5+
"devEUI": "AgICAgICAgI=",
6+
"devAddr": "AFE5Qg==",
7+
"rxInfo": [
8+
{
9+
"gatewayID": "AwMDAwMDAwM=",
10+
"time": "2019-11-08T13:59:25.048445Z",
11+
"timeSinceGPSEpoch": null,
12+
"rssi": -48,
13+
"loRaSNR": 9,
14+
"channel": 5,
15+
"rfChain": 0,
16+
"board": 0,
17+
"antenna": 0,
18+
"location": {
19+
"latitude": 52.3740364,
20+
"longitude": 4.9144401,
21+
"altitude": 10.5
22+
},
23+
"fineTimestampType": "NONE",
24+
"context": "9u/uvA==",
25+
"uplinkID": "jhMh8Gq6RAOChSKbi83RHQ=="
26+
}
27+
],
28+
"txInfo": {
29+
"frequency": 868100000,
30+
"modulation": "LORA",
31+
"loRaModulationInfo": {
32+
"bandwidth": 125,
33+
"spreadingFactor": 11,
34+
"codeRate": "4/5",
35+
"polarizationInversion": false
36+
}
37+
},
38+
"dr": 1,
39+
"tags": {
40+
"key": "value"
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"deduplicationId": "c9dbe358-2578-4fb7-b295-66b44edc45a6",
3+
"time": "2022-07-18T09:33:28.823500726+00:00",
4+
"deviceInfo": {
5+
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
6+
"tenantName": "ChirpStack",
7+
"applicationId": "17c82e96-be03-4f38-aef3-f83d48582d97",
8+
"applicationName": "Test application",
9+
"deviceProfileId": "14855bf7-d10d-4aee-b618-ebfcb64dc7ad",
10+
"deviceProfileName": "Test device-profile",
11+
"deviceName": "Test device",
12+
"devEui": "0101010101010101",
13+
"tags": {
14+
"key": "value"
15+
}
16+
},
17+
"devAddr": "00189440"
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"meta": {
3+
"network": "9e9bf02a",
4+
"packet_hash": "adc6bcac0d06195bc0329c3ef6a2d6ea",
5+
"application": "b3a1067cf7085309",
6+
"time": 1504638900.866375,
7+
"device": "8c30dd074be218cb",
8+
"packet_id": "287f9555a3e8b000ffc8c3c50f60e309",
9+
"gateway": "017e8cd996cd3a0e"
10+
},
11+
"params": {
12+
"dev_eui": "8c30dd074be218cb",
13+
"dev_addr": "01d6dcd6",
14+
"dev_nonce": "f9e7",
15+
"net_id": "000000"
16+
},
17+
"type": "join_request"
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"uid": "8a569133-aa44-4d7e-810d-af62faf9f722",
3+
"type": "join_accept",
4+
"received_at": "2016-07-15T14:31:11",
5+
"frame_counter": null,
6+
"for_frame_counter": null,
7+
"direction": "down",
8+
"device_eui": "2564927382738492"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

0 commit comments

Comments
 (0)