Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD deprecatedFeatures counters #4476

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- 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
- Add: deprecatedFeatures counters block in GET /v2/statistics
- 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
17 changes: 13 additions & 4 deletions src/lib/common/logTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string.h>

#include "logMsg/logMsg.h"
#include "common/statistics.h"



Expand Down Expand Up @@ -170,9 +171,13 @@ void logInfoRequestWithoutPayload
{
LM_I(("Request received: %s %s, response code: %d", verb, url, rc));

if (logDeprecate && isNgsiV1Url(url))
if (isNgsiV1Url(url))
{
LM_W(("Deprecated NGSIv1 request received: %s %s, response code: %d", verb, url, rc));
__sync_fetch_and_add(&noOfDprNgsiv1Request, 1);
if (logDeprecate)
{
LM_W(("Deprecated NGSIv1 request received: %s %s, response code: %d", verb, url, rc));
}
}
}

Expand Down Expand Up @@ -205,9 +210,13 @@ void logInfoRequestWithPayload

LM_I(("Request received: %s %s, request payload (%d bytes): %s, response code: %d", verb, url, strlen(payload), effectivePayload, rc));

if (logDeprecate && isNgsiV1Url(url))
if (isNgsiV1Url(url))
{
LM_W(("Deprecated NGSIv1 request received: %s %s, request payload (%d bytes): %s, response code: %d", verb, url, strlen(payload), effectivePayload, rc));
__sync_fetch_and_add(&noOfDprNgsiv1Request, 1);
if (logDeprecate)
{
LM_W(("Deprecated NGSIv1 request received: %s %s, request payload (%d bytes): %s, response code: %d", verb, url, strlen(payload), effectivePayload, rc));
}
}

if (cleanAfterUse)
Expand Down
7 changes: 7 additions & 0 deletions src/lib/common/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ int noOfDiscoveryErrors = -1;
int noOfNotificationsSent = -1;
int noOfSimulatedNotifications = -1;

// Deprecated features
int noOfDprNgsiv1Request = -1;
int noOfDprLegacyForwarding = -1;
int noOfDprLegacyNotif = -1;
int noOfDprLocationMetadata = -1;
int noOfDprGeoformat = -1;


/* ****************************************************************************
*
Expand Down
6 changes: 6 additions & 0 deletions src/lib/common/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ extern int noOfDiscoveryErrors;
extern int noOfNotificationsSent;
extern int noOfSimulatedNotifications;

// Deprecated features
extern int noOfDprNgsiv1Request;
extern int noOfDprLegacyForwarding;
extern int noOfDprLegacyNotif;
extern int noOfDprLocationMetadata;
extern int noOfDprGeoformat;

/* ****************************************************************************
*
Expand Down
10 changes: 8 additions & 2 deletions src/lib/mongoBackend/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "common/string.h"
#include "common/globals.h"
#include "common/errorMessages.h"
#include "common/statistics.h"
#include "logMsg/logMsg.h"
#include "ngsi/ContextAttribute.h"
#include "parse/CompoundValueNode.h"
Expand Down Expand Up @@ -324,6 +325,7 @@ static bool getGeoJson
// This corresponds to the legacy way in NGSIv1 based in metadata
// The block is the same that for GEO_POINT but it is clearer if we keep it separated

__sync_fetch_and_add(&noOfDprLocationMetadata, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of metadata location %s detected in attribute %s at entity update, please use geo:json instead", caP->type.c_str(), caP->name.c_str()));
Expand All @@ -348,9 +350,13 @@ static bool getGeoJson
return true;
}

if ((logDeprecate) && ((caP->type == GEO_POINT) || (caP->type == GEO_LINE) || (caP->type == GEO_BOX) || (caP->type == GEO_POLYGON)))
if ((caP->type == GEO_POINT) || (caP->type == GEO_LINE) || (caP->type == GEO_BOX) || (caP->type == GEO_POLYGON))
{
LM_W(("Deprecated usage of %s detected in attribute %s at entity update, please use geo:json instead", caP->type.c_str(), caP->name.c_str()));
__sync_fetch_and_add(&noOfDprGeoformat, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of %s detected in attribute %s at entity update, please use geo:json instead", caP->type.c_str(), caP->name.c_str()));
}
}

if (caP->type == GEO_POINT)
Expand Down
9 changes: 7 additions & 2 deletions src/lib/mongoBackend/mongoCreateSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "logMsg/logMsg.h"
#include "logMsg/traceLevels.h"
#include "common/defaultValues.h"
#include "common/statistics.h"
#include "apiTypesV2/Subscription.h"
#include "cache/subCache.h"
#include "rest/OrionError.h"
Expand Down Expand Up @@ -197,9 +198,13 @@ std::string mongoCreateSubscription
return "";
}

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

reqSemGive(__FUNCTION__, "ngsiv2 create subscription request", reqSemTaken);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/mongoBackend/mongoGetSubscriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,13 @@ 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)
if (subP->attrsFormat == NGSI_V1_LEGACY)
{
LM_W(("Deprecated usage of notification legacy format detected in existing subscription (subId: %s)", subP->id.c_str()));
__sync_fetch_and_add(&noOfDprLegacyNotif, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of notification legacy format detected in existing subscription (subId: %s)", subP->id.c_str()));
}
}


Expand Down
8 changes: 6 additions & 2 deletions src/lib/mongoBackend/mongoRegistrationCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,13 @@ void mongoRegistrationCreate

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

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

setFormat(format, &bob);
Expand Down
1 change: 1 addition & 0 deletions src/lib/mongoBackend/mongoRegistrationGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static void setProvider(ngsiv2::Registration* regP, const ngsiv2::ForwardingMode

if (format == "JSON")
{
__sync_fetch_and_add(&noOfDprLegacyForwarding, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of legacyForwarding mode detected in existing registration (regId: %s)", regP->id.c_str()));
Expand Down
9 changes: 7 additions & 2 deletions src/lib/mongoBackend/mongoUpdateSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "logMsg/logMsg.h"
#include "logMsg/traceLevels.h"
#include "common/defaultValues.h"
#include "common/statistics.h"
#include "apiTypesV2/SubscriptionUpdate.h"
#include "rest/OrionError.h"
#include "alarmMgr/alarmMgr.h"
Expand Down Expand Up @@ -369,9 +370,13 @@ std::string mongoUpdateSubscription
if (subUp.notifyOnMetadataChangeProvided) setNotifyOnMetadataChange(subUp, &setB);
if (subUp.attrsFormatProvided) setFormat(subUp, &setB);

if (logDeprecate && subUp.attrsFormat == NGSI_V1_LEGACY)
if (subUp.attrsFormat == NGSI_V1_LEGACY)
{
LM_W(("Deprecated usage of notification legacy format in subscription modification (subId: %s)", subUp.id.c_str()));
__sync_fetch_and_add(&noOfDprLegacyNotif, 1);
if (logDeprecate)
{
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
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ngsiNotify/Notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static bool setPayload

if (*renderFormatP == NGSI_V1_LEGACY)
{
__sync_fetch_and_add(&noOfDprLegacyNotif, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of notification legacy format in notification (subId: %s)", subscriptionId.c_str()));
Expand Down Expand Up @@ -689,6 +690,7 @@ SenderThreadParams* Notifier::buildSenderParams
std::string payloadString;
if (renderFormat == NGSI_V1_LEGACY)
{
__sync_fetch_and_add(&noOfDprLegacyNotif, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of notification legacy format in notification (subId: %s)", subId.c_str()));
Expand Down
1 change: 1 addition & 0 deletions src/lib/serviceRoutines/postQueryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static bool queryForward
{
op = "/queryContext";

__sync_fetch_and_add(&noOfDprLegacyForwarding, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of legacyForwarding mode in query forwarding operation (regId: %s)", regId.c_str()));
Expand Down
1 change: 1 addition & 0 deletions src/lib/serviceRoutines/postUpdateContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ static bool updateForward

op = "/updateContext";

__sync_fetch_and_add(&noOfDprLegacyForwarding, 1);
if (logDeprecate)
{
LM_W(("Deprecated usage of legacyForwarding mode in update forwarding operation (regId: %s)", regId.c_str()));
Expand Down
19 changes: 19 additions & 0 deletions src/lib/serviceRoutines/statisticsTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ static void resetStatistics(void)
noOfNotificationsSent = -1;
noOfSimulatedNotifications = -1;

noOfDprNgsiv1Request = -1;
noOfDprLegacyForwarding = -1;
noOfDprLegacyNotif = -1;
noOfDprLocationMetadata = -1;
noOfDprGeoformat = -1;

statisticsTime = getCurrentTime();

QueueStatistics::reset();
Expand Down Expand Up @@ -213,6 +219,19 @@ std::string renderCounterStats(bool fullCounters)
renderUsedCounter(&js, "discoveryErrors", noOfDiscoveryErrors, fullCounters);
renderUsedCounter(&js, "notificationsSent", noOfNotificationsSent, fullCounters);

JsonObjectHelper jsDeprecated;
renderUsedCounter(&jsDeprecated, "ngsiv1Requests", noOfDprNgsiv1Request, fullCounters);
renderUsedCounter(&jsDeprecated, "ngsiv1Forwarding", noOfDprLegacyForwarding, fullCounters);
renderUsedCounter(&jsDeprecated, "ngsiv1NotifFormat", noOfDprLegacyNotif, fullCounters);
renderUsedCounter(&jsDeprecated, "metadataLocation", noOfDprLocationMetadata, fullCounters);
renderUsedCounter(&jsDeprecated, "geoFormat", noOfDprGeoformat, fullCounters);

std::string deprecation = jsDeprecated.str();
if (deprecation != "{}")
{
js.addRaw("deprecatedFeatures", deprecation);
}

return js.str();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Disable NGSIv1 CLI

--SHELL-INIT--
dbInit CB
brokerStart CB 0 IPV4 -logDeprecate
brokerStart CB 0 IPV4 -logDeprecate -statCounters

--SHELL--

Expand All @@ -47,6 +47,7 @@ brokerStart CB 0 IPV4 -logDeprecate
# 12. Update subscription using attrsFormat legacy
# 13. Trigger notification using attrsFormat legacy
# 14. Get WARNING trace in logs
# 15. Get statistics and see deprecatedFeatures counters
#

echo "01. Query E1-T1"
Expand Down Expand Up @@ -264,6 +265,13 @@ echo
echo


echo "15. Get statistics and see deprecatedFeatures counters"
echo "======================================================"
orionCurl --url /statistics
echo
echo


--REGEXPECT--
01. Query E1-T1
===============
Expand Down Expand Up @@ -540,6 +548,65 @@ Deprecated usage of notification legacy format in notification (subId: SUB_ID)
Raising alarm NotificationError localhost:1234/: notification failure for queue worker: Couldn't connect to server


15. Get statistics and see deprecatedFeatures counters
======================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 587

{
"counters": {
"deprecatedFeatures": {
"geoFormat": 2,
"metadataLocation": 1,
"ngsiv1Forwarding": 4,
"ngsiv1NotifFormat": 4,
"ngsiv1Requests": 4
},
"jsonRequests": 9,
"noPayloadRequests": 5,
"requests": {
"/statistics": {
"GET": 1
},
"/v2/entities": {
"POST": 2
},
"/v2/entities/{id}/attrs/{name}": {
"GET": 1,
"PUT": 1
},
"/v2/registrations": {
"GET": 1,
"POST": 1
},
"/v2/subscriptions": {
"GET": 1,
"POST": 1
},
"/v2/subscriptions/{id}": {
"PATCH": 1
}
},
"requestsLegacy": {
"/v1/contextEntities/{id}/attributes/{name}": {
"GET": 1
},
"/v1/queryContext": {
"POST": 1
},
"/v1/updateContext": {
"POST": 2
}
}
},
"measuring_interval_in_secs": REGEX(\d+),
"uptime_in_secs": REGEX(\d+)
}


--TEARDOWN--
brokerStop CB
dbDrop CB
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ orionCurl --url /v1/updateContext -X POST --payload "$payload" >

# Get statistics

orionCurl --url /statistics?options
orionCurl --url /statistics
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related with the purpose of this PR, this is just a typo fix.

NTC


--REGEXPECT--
HTTP/1.1 200 OK
Expand All @@ -260,6 +260,9 @@ Content-Length: REGEX(\d+)

{
"counters": {
"deprecatedFeatures": {
"ngsiv1Requests": 7
},
"jsonRequests": 16,
"noPayloadRequests": 42,
"requests": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 1525
Content-Length: 1645

{
"counters": {
"deprecatedFeatures": {
"geoFormat": 0,
"metadataLocation": 0,
"ngsiv1Forwarding": 0,
"ngsiv1NotifFormat": 0,
"ngsiv1Requests": 0
},
"discoveryErrors": 0,
"invalidRequests": 0,
"jsonRequests": 0,
Expand Down
Loading