Skip to content

Commit

Permalink
Merge pull request #4469 from telefonicaid/hardening/log_deprecate_im…
Browse files Browse the repository at this point in the history
…provements

ADD legacyForwarding mode (regs) and notification legacy format (subs) to deprecation traces
  • Loading branch information
mapedraza authored Jan 11, 2024
2 parents 74a7d97 + 7194d95 commit 5b7fa18
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- Add: servicePath field to builtin attributes (#2877)
- Add: notification.mqtt.retain and notification.mqttCustom.retain flag for MQTT retain in notifications (#4388)
- Add: notification payload in INFO log traces (#4449)
- Add: log deprecation traces for usage of legacyForwarding mode in registrations
- Add: log deprecation traces for usage of attrsFormat legacy in subscriptions
- Fix: do not show dateExpires built-in attribute in GET /v2/types and GET /v2/types/{type} operations (#4451)
- Fix: correctly detect JSON attribute and metadata value changes in subscription triggering logic (#4211, #4434, #643)
- Fix: update forwarding was not working when entity type is not included in the request (#4460)
Expand Down
22 changes: 19 additions & 3 deletions doc/manuals/admin/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,31 @@ time=2020-10-26T15:06:14.642Z | lvl=INFO | corr=c4a3192e-179c-11eb-ac8f-000c29df
If `-logDeprecate` CLI setting is used (or `deprecate` parameter in the [log admin REST API](management_api.md#log-configs-and-trace-levels)) the
following WARN traces are generated:

* NGSIv1 requests (both with and without payload). Note this doesn't
include notifications using [`"attrsFormat": "legacy"`](../orion-api.md#subscriptionnotification) or forward requests corresponding
to registrations using [`"legacyForwarding": true`](../orion-api.md#registrationprovider)). For instance:
* NGSIv1 requests (both with and without payload). For instance:

```
time=2023-05-25T14:27:45.958Z | lvl=WARN | corr=513bd10e-fb08-11ed-8ad7-000c29583ca5 | trans=1685024865-125-00000000001 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=logTracing.cpp[171]:logInfoRequestWithPayload | msg=Deprecated NGSIv1 request received: POST /v1/queryContext, request payload (48 bytes): { "entities": [ { "type": "T1", "id": "E1" } ] }, response code: 200
time=2023-05-25T14:27:46.041Z | lvl=WARN | corr=51490536-fb08-11ed-9782-000c29583ca5 | trans=1685024865-125-00000000002 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=logTracing.cpp[114]:logInfoRequestWithoutPayload | msg=Deprecated NGSIv1 request received: GET /v1/contextEntities/E, response code: 200
```

* Usages of [`"legacyForwarding": true`](../orion-api.md#registrationprovider)). For instance:

```
time=2024-01-11T13:57:13.537Z | lvl=WARN | corr=527378d8-b089-11ee-875d-080027cd35f1 | trans=1704981432-655-00000000006 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoRegistrationCreate.cpp[235]:mongoRegistrationCreate | msg=Deprecated usage of legacyForwarding mode in registration creation (regId: 659ff3b9691855f16d00ec5a)
time=2024-01-11T13:57:13.565Z | lvl=WARN | corr=52778eaa-b089-11ee-861c-080027cd35f1 | trans=1704981432-655-00000000007 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoRegistrationGet.cpp[93]:setProvider | msg=Deprecated usage of legacyForwarding mode detected in existing registration (regId: 659ff3b9691855f16d00ec5a)
time=2024-01-11T13:57:13.595Z | lvl=WARN | corr=527c0912-b089-11ee-bb8c-080027cd35f1 | trans=1704981432-655-00000000008 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=postQueryContext.cpp[191]:queryForward | msg=Deprecated usage of legacyForwarding mode in query forwarding operation (regId: 659ff3b9691855f16d00ec5a)
time=2024-01-11T13:57:13.624Z | lvl=WARN | corr=52808938-b089-11ee-9835-080027cd35f1 | trans=1704981432-655-00000000010 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=postUpdateContext.cpp[163]:updateForward | msg=Deprecated usage of legacyForwarding mode in update forwarding operation (regId: 659ff3b9691855f16d00ec5a)
```

* Usages of [`"attrsFormat": "legacy"`](../orion-api.md#subscriptionnotification). For instance:

```
time=2024-01-11T16:23:24.646Z | lvl=WARN | corr=be709034-b09d-11ee-b5d1-080027cd35f1 | trans=1704990203-652-00000000012 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=MongoCommonSubscription.cpp[598]:setFormat | msg=Deprecated usage of notification legacy format in subscription creation (subId: 65a015fcda947708d30425eb)
time=2024-01-11T16:23:24.675Z | lvl=WARN | corr=be74dc98-b09d-11ee-b2d6-080027cd35f1 | trans=1704990203-652-00000000013 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoGetSubscriptions.cpp[217]:setNotification | msg=Deprecated usage of notification legacy format detected in existing subscription (subId: 65a015fcda947708d30425eb)
time=2024-01-11T16:23:24.701Z | lvl=WARN | corr=be709034-b09d-11ee-b5d1-080027cd35f1 | trans=1704990203-652-00000000012 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=MongoCommonSubscription.cpp[598]:setFormat | msg=Deprecated usage of notification legacy format in subscription modification (subId: 65a015fcda947708d30425eb)
time=2024-01-11T16:23:24.716Z | lvl=WARN | corr=be7ae5ac-b09d-11ee-98c8-080027cd35f1 | trans=1704990203-652-00000000015 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=Notifier.cpp[680]:buildSenderParams | msg=Deprecated usage of notification legacy format in notification (subId: 65a015fcda947708d30425eb)
```

* Usages NGSIv1 usages of location metadata. Example:

```
Expand Down
5 changes: 5 additions & 0 deletions src/lib/mongoBackend/mongoCreateSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ std::string mongoCreateSubscription
return "";
}

if (logDeprecate && sub.attrsFormat == NGSI_V1_LEGACY)
{
LM_W(("Deprecated usage of notification legacy format in subscription creation (subId: %s)", subId.c_str()));
}

reqSemGive(__FUNCTION__, "ngsiv2 create subscription request", reqSemTaken);

return subId;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/mongoBackend/mongoGetSubscriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ static void setNotification(Subscription* subP, const orion::BSONObj& r, const s
// Attributes format
subP->attrsFormat = r.hasField(CSUB_FORMAT)? stringToRenderFormat(getStringFieldF(r, CSUB_FORMAT)) : NGSI_V1_LEGACY;

if (logDeprecate && subP->attrsFormat == NGSI_V1_LEGACY)
{
LM_W(("Deprecated usage of notification legacy format detected in existing subscription (subId: %s)", subP->id.c_str()));
}


//
// Check values from subscription cache, update object from cache-values if necessary
Expand Down
6 changes: 6 additions & 0 deletions src/lib/mongoBackend/mongoRegistrationCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ void mongoRegistrationCreate
setForwardingMode(regP->provider.supportedForwardingMode, &bob);

std::string format = (regP->provider.legacyForwardingMode == true)? "JSON" : "normalized";

if (logDeprecate && format == "JSON")
{
LM_W(("Deprecated usage of legacyForwarding mode in registration creation (regId: %s)", regIdP->c_str()));
}

setFormat(format, &bob);

//
Expand Down
4 changes: 4 additions & 0 deletions src/lib/mongoBackend/mongoRegistrationGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ static void setProvider(ngsiv2::Registration* regP, const ngsiv2::ForwardingMode

if (format == "JSON")
{
if (logDeprecate)
{
LM_W(("Deprecated usage of legacyForwarding mode detected in existing registration (regId: %s)", regP->id.c_str()));
}
regP->provider.legacyForwardingMode = true;
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/lib/mongoBackend/mongoUpdateSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ std::string mongoUpdateSubscription
if (subUp.notifyOnMetadataChangeProvided) setNotifyOnMetadataChange(subUp, &setB);
if (subUp.attrsFormatProvided) setFormat(subUp, &setB);

if (logDeprecate && subUp.attrsFormat == NGSI_V1_LEGACY)
{
LM_W(("Deprecated usage of notification legacy format in subscription modification (subId: %s)", subUp.id.c_str()));
}

// Description is special, as "" value removes the field
if (subUp.descriptionProvided)
Expand Down
10 changes: 10 additions & 0 deletions src/lib/ngsiNotify/Notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ static bool setPayload

if (*renderFormatP == NGSI_V1_LEGACY)
{
if (logDeprecate)
{
LM_W(("Deprecated usage of notification legacy format in notification (subId: %s)", subscriptionId.c_str()));
}

*payloadP = ncr.toJsonV1(false, attrsFilter, blacklist, metadataFilter);
}
else
Expand Down Expand Up @@ -670,6 +675,11 @@ SenderThreadParams* Notifier::buildSenderParams
std::string payloadString;
if (renderFormat == NGSI_V1_LEGACY)
{
if (logDeprecate)
{
LM_W(("Deprecated usage of notification legacy format in notification (subId: %s)", subId.c_str()));
}

bool asJsonObject = (ci.uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ci.outMimeType == JSON);
payloadString = ncr.toJsonV1(asJsonObject, attrsFilter, blacklist, metadataFilter);
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/serviceRoutines/postQueryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ static bool queryForward
if (qcrP->providerFormat == PfJson)
{
op = "/queryContext";

if (logDeprecate)
{
LM_W(("Deprecated usage of legacyForwarding mode in query forwarding operation (regId: %s)", regId.c_str()));
}

TIMED_RENDER(payload = qcrP->toJsonV1());
}
else
Expand Down
5 changes: 5 additions & 0 deletions src/lib/serviceRoutines/postUpdateContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ static bool updateForward
TIMED_RENDER(payload = upcrP->toJsonV1(asJsonObject));

op = "/updateContext";

if (logDeprecate)
{
LM_W(("Deprecated usage of legacyForwarding mode in update forwarding operation (regId: %s)", regId.c_str()));
}
}
else
{
Expand Down
Loading

0 comments on commit 5b7fa18

Please sign in to comment.