-
Notifications
You must be signed in to change notification settings - Fork 0
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
Hardening/3109 url parse refactor #20
Conversation
@@ -783,495 +783,393 @@ static const char* validLogLevels[] = | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I undesrtand this is the first of a series of PRs that will end with telefonicaid#3109 step 1 covered. Could you elaborate on your "PR plan" (I mean, the topic for the next PRs after this one)? Maybe the two-levels branch approach (feature/ and task/ branches) should be applied if this is going be a long work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No real reason to do all this work in a separate branch, pretty much only me working on the broker anyway ... :-)
It is not a problem to me to finish every PR leaving the broker in a 100% working state.
There is nothing about "half-working functionalities" here, only refactors.
Doing it in a feature branch would only add extra work.
The next step is to remove the 'payloadWord' from the RestService vector and after that more simplifications of the vector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, then CHANGES_NEXT_RELEASE entry should be "inaugurated" in the first PR addressing this, eg.:
- Hardening: refactor request routing logic (#3109, step 1)
or a similar wording.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no impact on the usage of the broker ...
Normally, when we refactor stuff we don't mention it in the CNR.
The only thing users will notice is that the broker is faster after these changes ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree there is no impact for the user from a functional perspetive, but even in that case it would be interesing to mark it in the changelog (specially when there could be a potentiall impact, non-functional, in the form of performance increase). That's way we use Hardening
as prefix instead of Add
or Fix
. It doesn't hurt and may be useful.
Note we have already done this in the past, eg:
- Hardening: NGSIv1 responses don't use pretty-print JSON format any longer, as NGSIv2 responses work (potentially saving around 50% size) (#2760)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 74c7a9c
@@ -783,495 +783,393 @@ static const char* validLogLevels[] = | |||
|
|||
|
|||
|
|||
#define API_V2 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand, the change in contextBroker.cpp consists on spliting the global routes vector is a per-verb vector.
Is my intepretation correct? Any other change that I may be missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for the same price these loooong vectors could be moved out of contextBroker.cpp (to some new .h or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the PR is all about removing the VERB/METHOD from the vector and splitting the ONE vector into X vectors, one per verb (the last one is special, the one I call badVerbV, containing the service routines where no adequate verb/method has been found)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I could move the vector to another CPP file (and its header), but ... what do we gain with that?
Just more complexity, in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is more clear to have all routes in the same place, not mixed with the rest of logic of the contextBroker.cpp (initialization functions, etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed?
Not sure what you mean with that ...
The service routine vectors are where they have always been, right where they should be and right where they are used.
It's been like this since 2011, so ... very hard to understand why we should move them out to a different file (where they are not used) now ...
The vectors are needed in the call to restInit(), that will stay inside contextBroker.cpp.
I see no reason whatsoever to create another file only with the service vectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't use the "it has been that way from a time long" argument because if we follow it, then even the refactor done by this PR could be put on doubt :)
Routes configuration is pretty much static and could be considered part of the rest library, so the movement could make sense, changing the way restInit() works, i.e. restInit() wouldn't pass the vector as arguments (as much it would select the mode to use, e.g. cors, no-cors, etc.).
However, it is not so important at the present moment, so we can keep it as it is now and think again in the future.
NTC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do the refactoring mentioned in this PR, about having restInit less "flexible", which we needed yeara ago but no longer, then the service vectors would go into the rest library, no doubt.
It's not a bad idea, let's do it. But, in a different PR ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe adding // FIXME PR: to be removed within #3109 refactor task
would be useful. I think I will not forget about this but... never knows :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 74c7a9c
static RestService* patchServiceV = NULL; | ||
static RestService* deleteServiceV = NULL; | ||
static RestService* optionsServiceV = NULL; | ||
RestService* restBadVerbV = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this one is not static? Why the name uses a different pattern (versus badVerbServiceV
for instance)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This vector is needed in another file (use grep to see which), and as it is not static, it needs a prefix.
As it is in the rest-library, I used the prefix "rest".
Perhaps restBadVerbServiceV
would have been a better name. A bit long though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next-coming refactoring, all RestService vectors will be moved to RestService.cpp or rest.cpp, and then perhaps all of them can be made static ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIXME PR for this or NTC... As you prefer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NTC (I am preparing a list of nextcoming PRs about this)
src/lib/rest/RestService.cpp
Outdated
* | ||
* serviceVectorsSet - only for unit tests | ||
*/ | ||
void serviceVectorsSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only used in unit tests, then use #ifdef UNIT_TEST
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the function is used, by restInit() to set the vectors.
It wasn't like that in the beginning, that's why I added the comment.
But now the function is used both for the normal broker compilation as for the unit test compilation so ...
NTC
src/lib/rest/RestService.cpp
Outdated
@@ -445,7 +487,7 @@ static bool compErrorDetect | |||
* | |||
* restService - | |||
*/ | |||
std::string restService(ConnectionInfo* ciP, RestService* serviceV) | |||
static std::string restService(ConnectionInfo* ciP, RestService* serviceV, const char* serviceVectorName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the new parameter serviceVectorName
being used in this function?
Maybe github diff is fooling me, but I cannot find any ocurrence in the diff page appart from this one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not easy to find this kind of things in the github jungle ...
% find . -name "*.cpp" -exec grep "restService(" {} /dev/null
./src/lib/rest/RestService.cpp:static std::string restService(ConnectionInfo* ciP, RestService* serviceV, const char* serviceVectorName)
./src/lib/rest/RestService.cpp: return restService(ciP, restBadVerbV, "BAD VERB");
./src/lib/rest/RestService.cpp: if ((ciP->verb == GET) && (getServiceV != NULL)) return restService(ciP, getServiceV, "GET");
./src/lib/rest/RestService.cpp: else if ((ciP->verb == POST) && (postServiceV != NULL)) return restService(ciP, postServiceV, "POST");
./src/lib/rest/RestService.cpp: else if ((ciP->verb == PUT) && (putServiceV != NULL)) return restService(ciP, putServiceV, "PUT");
./src/lib/rest/RestService.cpp: else if ((ciP->verb == PATCH) && (patchServiceV != NULL)) return restService(ciP, patchServiceV, "PATCH");
./src/lib/rest/RestService.cpp: else if ((ciP->verb == DELETE) && (deleteServiceV != NULL)) return restService(ciP, deleteServiceV, "DELETE");
./src/lib/rest/RestService.cpp: else if ((ciP->verb == OPTIONS) && (optionsServiceV != NULL)) return restService(ciP, optionsServiceV, "OPTIONS");
./src/lib/rest/RestService.cpp: else return restService(ciP, restBadVerbV, "BADVERB");
If I'm not mistaken, I used the "serviceVectorName" fior debugging purposes.
Need to make sure, but if so, it will be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter is no longer used.
Removed in 64983d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 64983d1
src/lib/rest/rest.cpp
Outdated
ipVersionUsed = _ipVersion; | ||
serveFunction = (_serveFunction != NULL)? _serveFunction : serve; | ||
serveFunction = (_serveFunction != NULL)? _serveFunction : orionServe; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked for usages of restInit() and it seems that we neever use _serveFunction
parameter. Thus, maybe we should avoid the complexity of this function selection function and hardwire orionServer()
function as routing logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old stuff from when orion was both ContextBroker and IotAgent and ConfiguratrionManager at the same time.
So, yes, it definitely could be removed, but that is another refactoring. restInit() will change completely etc, etc.
Not for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'd suggest to mark it with a // FIXME PR: to be removed within #3109 refactor task
or a similar wording.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with the current refactoring.
I could mark it with a FIXME saying something like "this might be refactored, or not, in the future" ... Really don't see the need of it though.
What would help here if we really want to make this change, is a new issue about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name changed from orionServe
to orion::requestServe
in 02d46a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next refactoring on my list is exactly this - move RestService vectors into rest lib. No FIXME needed ... Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current situation is that there is an parameter, the one named _serveFunction
in a function that is never used. I think that is a "weird" situation that worth the one-line of effort ;) that a FIXME PR require.
But you have more neurons on this than me right now, so as you prefer...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can fix that. Almost easier than putting it in the issue ... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 124c24a (the variable serveFunction is removed as well - which makes us have to modify images ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Images modified in eaa194d
src/lib/rest/rest.h
Outdated
* | ||
* serve - | ||
*/ | ||
extern std::string serve(ConnectionInfo* ciP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the change from
serveFunction = (_serveFunction != NULL)? _serveFunction : serve;
to
serveFunction = (_serveFunction != NULL)? _serveFunction : orionServe;
Is the serve()
function actually used in some place? Should it be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The serve()
function changed name to orionServe()
, that's all.
And yes, it is used :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Github diff is not always as smart as it should be with renamings... ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NTC
src/lib/rest/rest.h
Outdated
* | ||
* serviceVectorsSet - only for unit tests | ||
*/ | ||
extern void serviceVectorsSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only used in unit tests, then use #ifdef UNIT_TEST
.
(Maybe I'm repeating myself too much... sorry :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned, the comment is no longer valid.
NTC
@@ -783,495 +783,393 @@ static const char* validLogLevels[] = | |||
|
|||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR impacts in development manual. At least, the following should be reviewed:
- The libraries touched by this PR in https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/devel/sourceCode.md
- The flows related with request processing, i.e. RQ-01 and RQ-02.
However, a grep -i ... *.md
in the doc/manuals/devel with the name of the key functions being modified will help to locate other possible changes needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok :-( :-D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sourceCode.md modified in 7c82dd8.
RQ-01 and RQ-02 ... images?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, took a look at RQ-01 and 02.
Not sure why you mention these images. No changes to be made there.
NTC (after changes in sourceCode.md in commit 7c82dd8).
@@ -73,14 +73,23 @@ extern bool multitenant; | |||
extern bool corsEnabled; | |||
extern char corsOrigin[64]; | |||
extern int corsMaxAge; | |||
extern RestService* restBadVerbV; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this addition to global variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I answered before. The vector for bad verbs is needed in RestService.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NTC
src/lib/rest/RestService.h
Outdated
|
||
/* **************************************************************************** | ||
* | ||
* serviceVectorsSet - only for unit tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that at the end this function is not only used only for unit tests, as restInit() also uses it. Thus the "- only for unit tests" fragment should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same in the .ccp file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a265c79
src/lib/rest/rest.h
Outdated
|
||
/* **************************************************************************** | ||
* | ||
* serviceVectorsSet - only for unit tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated declaration? (in seems is also at RestService.h)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a265c79
Except for some minor issues with serviceVectorsSet that should be reviewed, LGTM |
Part 1 of refactoring of the url parse