-
Notifications
You must be signed in to change notification settings - Fork 674
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
NOISSUE - Refactor InfluxDB Reader: explicit check event + add safe conversion #1460
Conversation
Signed-off-by: tzzed <zerouali.t@gmail.com>
7da2b28
to
f9e5eac
Compare
@tzzed thanks for the PR. Please sync your branch to the master. @arvindh123 please review this PR |
…factore/reader_influxdb
b2b2916
to
04e569e
Compare
Codecov Report
@@ Coverage Diff @@
## master #1460 +/- ##
==========================================
- Coverage 68.80% 68.78% -0.03%
==========================================
Files 132 132
Lines 10581 10587 +6
==========================================
+ Hits 7280 7282 +2
- Misses 2726 2727 +1
- Partials 575 578 +3
Continue to review full report at Codecov.
|
0efd3fc
to
0508757
Compare
Signed-off-by: tzzed <zerouali.t@gmail.com>
0508757
to
7d1b9c2
Compare
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.
@drasko, It looks good
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.
Honestly, I do not see value in this PR. I would like that @dusanb94 reviews, but I do not find new code better or more comprehensible.
for i := 0; i < len(result.Messages); i++ { | ||
m := result.Messages[i] | ||
// Remove time as it is not sent by the client. | ||
delete(m.(map[string]interface{}), "time") | ||
|
||
result.Messages[i] = m | ||
} | ||
assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %s", desc, err)) |
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 is this assert 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 assert checks the error after the loop but it should be done before just after getting the result, err := reader.ReadAll(tc.chanID, tc.pageMeta)
.
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.
Is it done?
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.
Again - is this done?
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 put it after reader.ReadAll(tc.chanID, tc.pageMeta)
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 looks ok but in any case don't resolve remarks by hand please.
the len's comparison to zero is more clear because we want to check the 0 value an empty array. About the safe cast is just to avoid panic. I just let myself to do this PR as a "good first issue" but you are free to close it. |
Signed-off-by: tzzed <zerouali.t@gmail.com>
fc4208b
to
843c7f4
Compare
@nmarcetic and @dusanb94 need to review and approve this one. |
readers/influxdb/messages.go
Outdated
return readers.MessagesPage{}, nil | ||
} | ||
|
||
var messages []readers.Message | ||
|
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 need for blank line
@@ -140,7 +140,8 @@ func fmtCondition(chanID string, rpm readers.PageMetadata) string { | |||
if err != nil { | |||
return condition | |||
} | |||
json.Unmarshal(meta, &query) | |||
|
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 need for blank line.
readers/influxdb/messages.go
Outdated
@@ -140,7 +140,8 @@ func fmtCondition(chanID string, rpm readers.PageMetadata) string { | |||
if err != nil { | |||
return condition | |||
} | |||
json.Unmarshal(meta, &query) | |||
|
|||
_ = json.Unmarshal(meta, &query) |
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.
Do not ignore errors.
for i := 0; i < len(result.Messages); i++ { | ||
m := result.Messages[i] | ||
// Remove time as it is not sent by the client. | ||
delete(m.(map[string]interface{}), "time") | ||
|
||
result.Messages[i] = m | ||
} | ||
assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %s", desc, err)) |
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.
Is it done?
Signed-off-by: tzzed <zerouali.t@gmail.com>
The refactoring makes sense. @tzzed please consider adding better error handling and InfluxDB records parsing. Those improvements can be added to this PR to improve its value. |
for i := 0; i < len(result.Messages); i++ { | ||
m := result.Messages[i] | ||
// Remove time as it is not sent by the client. | ||
delete(m.(map[string]interface{}), "time") | ||
|
||
result.Messages[i] = m | ||
} | ||
assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %s", desc, err)) |
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.
Again - is this done?
OK, then I left a few comments, and these must be corrected before we are ready to merge. |
@tzzed if there is no action from your side to correct mentioned comment, this PR will be closed due to the inactivity. |
3625173
to
10783dd
Compare
readers/influxdb/messages_test.go
Outdated
@@ -6,6 +6,7 @@ import ( | |||
"time" | |||
|
|||
influxdata "github.com/influxdata/influxdb/client/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.
Remove this blank line
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.
done
Signed-off-by: tzzed <zerouali.t@gmail.com>
10783dd
to
c00ee1c
Compare
@tzzed CI is failing. Please check your tests, you have introduced regression:
|
@drasko I did not introduced regression. This is because of the now := float64(time.Now().UTC().Second())
for i := 0; i < msgsNum; i++ {
// Mix possible values as well as value sum.
msg := m
msg.Time = now - float64(i) // This operations has a random fails or success. I will change it tomorrow if you are ok @drasko ? It will add a real value to this PR. |
Signed-off-by: tzzed <zerouali.t@gmail.com>
63c4bfb
to
d2bba44
Compare
readers/influxdb/messages_test.go
Outdated
now := float64(time.Now().UTC().Second()) | ||
rand.Seed(time.Now().UnixNano()) | ||
to := msgsNum | ||
from := 21 |
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.
You can use this as a constant in tests with a range search instead of literals, as well.
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.
@tzzed I also meant to use this constant later in the code: https://github.com/mainflux/mainflux/blob/master/readers/influxdb/messages_test.go#L334-L355
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 seen this line but I have not enough context about this lines. How do you see the usage.Should I create a const for each value in test.
pageMeta: readers.PageMetadata{
Offset: 0,
Limit: uint64(len(messages[21:])),
To: messages[20].Time,
},
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 need, I think. Replacing literals 20
and 21
with from
and from + 1
(and maybe rename from
to offset
) will be just fine.
Signed-off-by: tzzed <zerouali.t@gmail.com>
5379f78
to
69927e7
Compare
Signed-off-by: tzzed <zerouali.t@gmail.com>
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.
LGTM
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.
LGTM
…onversion (absmach#1460) * refactore(reader/influxdb): explicit check event + add safe conversion Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion Signed-off-by: tzzed <zerouali.t@gmail.com> * Delete useless space. Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion, replace require.NoError(t, err) by assert.Nil Signed-off-by: tzzed <zerouali.t@gmail.com> * Fix tests when message time is randomly equal to 0 in tests cases. Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion use constant Signed-off-by: tzzed <zerouali.t@gmail.com> * use const offset Signed-off-by: tzzed <zerouali.t@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
…onversion (absmach#1460) * refactore(reader/influxdb): explicit check event + add safe conversion Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion Signed-off-by: tzzed <zerouali.t@gmail.com> * Delete useless space. Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion, replace require.NoError(t, err) by assert.Nil Signed-off-by: tzzed <zerouali.t@gmail.com> * Fix tests when message time is randomly equal to 0 in tests cases. Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion use constant Signed-off-by: tzzed <zerouali.t@gmail.com> * use const offset Signed-off-by: tzzed <zerouali.t@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
…onversion (absmach#1460) * refactore(reader/influxdb): explicit check event + add safe conversion Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion Signed-off-by: tzzed <zerouali.t@gmail.com> * Delete useless space. Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion, replace require.NoError(t, err) by assert.Nil Signed-off-by: tzzed <zerouali.t@gmail.com> * Fix tests when message time is randomly equal to 0 in tests cases. Signed-off-by: tzzed <zerouali.t@gmail.com> * apply review suggestion use constant Signed-off-by: tzzed <zerouali.t@gmail.com> * use const offset Signed-off-by: tzzed <zerouali.t@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> Signed-off-by: skovacevic <stefan.kovacevic@mainflux.io>
What does this do?
This PR is a simple refactoring of influxdb measurement data.
Which issue(s) does this PR fix/relate to?
No issue related to this PR.
List any changes that modify/break current functionality
Have you included tests for your changes?
Still working
Did you document any new/modified functionality?
No
Notes