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

Fix initOverTime's calculation of last slot timestamp #1312

Merged
merged 1 commit into from
Apr 2, 2022

Conversation

icyflame
Copy link
Contributor

@icyflame icyflame commented Mar 6, 2022

By submitting this pull request, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your PR:

Please submit all pull requests against the development branch. Failure to do so will delay or deny your request

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?: 2


initOverTime calculate's the last slot timestamp with the assumption that OVERTIME_INTERVAL will
allow atleast OVERTIME_SLOTS number of slots between now and the last slot in the current
hour. This leads it to calculate the timestamp of the last slot, and then assign timestamps to each
slot counting down from that timestamp.

This logic is not compatible with changes in the OVERTIME_INTERVAL and the MAXLOGAGE variables. Here is a demonstration of a case where this can be shown clearly:

OVERTIME_INTERVAL = 60s (Each slot stores 1 minute of data)
MAXLOGAGE = 600s (Store date for only 10 minutes)
OVERTIME_SLOTS = 11 (MAXLOGAGE/OVERTIME_INTERVAL)

GCInterval = 90 (Any value less than MAXLOGAGE is okay)

Current logic:

  • Current time: 10:35:04
  • First slot time: 10:48:30
  • Last slot time: 10:59:30

This PR's proposal:

  • Current time: 10:35:04
  • First slot time: 10:35:30
  • Last slot time: 10:46:30

Note that this logic does work as expected with the default minimum of 1 hour for the MAXLOGAGE
configuration variable.

However, I believe that there is no need to make this part of the code dependent on this minimum. If this part of the code is changed, the macros for OVERTIME_INTERVAL and MAXLOGAGE can be freely changed by users.

This template was created based on the work of udemy-dl.

@icyflame icyflame force-pushed the update-init-overtime branch from dcad87e to da8f94f Compare March 6, 2022 14:34
@icyflame icyflame marked this pull request as ready for review March 6, 2022 14:39
@DL6ER
Copy link
Member

DL6ER commented Mar 11, 2022

Thank you for your contribution and sorry for the delay in reviewing. Things are moving a lot slower with the attention being closer to a war that is going on only a few hours by car from here. I'll come back to you PR and do a proper review when time allows.

Copy link
Member

@DL6ER DL6ER left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I only have a very small comment concerning indentation of a line you changed and then we're good to g on this one.

src/overTime.c Outdated Show resolved Hide resolved
initOverTime calculate's the last slot timestamp with the assumption that `OVERTIME_INTERVAL` will
allow atleast `OVERTIME_SLOTS` number of slots between now and the last slot in the current
hour. This leads it to calculate the timestamp of the last slot, and then assign timestamps to each
slot counting down from that timestamp.

This logic is not compatible with changes in the OVERTIME_INTERVAL and the MAXLOGAGE variables. Here
is a demonstration of a case where this can be shown clearly:

```
OVERTIME_INTERVAL = 60s (Each slot stores 1 minute of data)
MAXLOGAGE = 600s (Store date for only 10 minutes)
OVERTIME_SLOTS = 11 (MAXLOGAGE/OVERTIME_INTERVAL)
```

- Current time: 10:35
- Last slot time: 10:59:30
- First slot time: 10:48:30

Note that this logic *does* work as expected with the default minimum of 1 hour for the MAXLOGAGE
configuration variable.

Signed-off-by: Siddharth Kannan <mail@siddharthkannan.in>
@icyflame icyflame force-pushed the update-init-overtime branch from da8f94f to 06b0606 Compare April 2, 2022 04:15
@icyflame
Copy link
Contributor Author

icyflame commented Apr 2, 2022

Thank you for the review, I fixed the indentation, and pushed again with GPG verification for each commit.

For piHole 6.0's development / plan / roadmap / timeline, I was wondering where I could follow the development. Is it everything on the development branch of this repository? I can't find anything related to the next version on Discourse. A search for 6.0 does not yield anything (https://discourse.pi-hole.net/search?q=6.0)

@icyflame icyflame requested a review from DL6ER April 2, 2022 04:23
@yubiuser
Copy link
Member

yubiuser commented Apr 2, 2022

Is it everything on the development branch of this repository

It's in new/http. To get a glance at the API use https://ftl.pi-hole.net/new/http/docs/#overview or after you checked out that branch `http://pi.hole:8080/api/docs/

@DL6ER DL6ER merged commit 392ff15 into pi-hole:development Apr 2, 2022
Comment on lines +74 to +75
time_t first_slot_ts = now - now % OVERTIME_INTERVAL + (OVERTIME_INTERVAL / 2);
time_t last_slot_ts = first_slot_ts + (OVERTIME_SLOTS-1) * OVERTIME_INTERVAL;
Copy link
Member

@DL6ER DL6ER Apr 7, 2022

Choose a reason for hiding this comment

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

The logic in this PR is broken, unfortunately, I didn't see this before.

The issue here is, basically, that first_slot_ts should be the one 24 hours in the past, however, it is a timestamp centered at the current timestamp (as the comment correctly says). The last_slot_ts is then 24 hours in the future which is wrong.

This wasn't an issue in the code before the change as the old code was going backwards from now. The new code tries to go forward but start at now causing the history to incorrectly live in the future rather than in the past.

DL6ER added a commit that referenced this pull request Apr 7, 2022
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER mentioned this pull request Apr 8, 2022
5 tasks
yubiuser added a commit that referenced this pull request Apr 8, 2022
Fix overtime computation logic broken in PR #1312
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-ftl-v5-15-web-v5-12-and-core-v5-10-released/54987/1

@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/found-database-entries-in-the-future/55333/3

@thomasmerz thomasmerz mentioned this pull request May 24, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants