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

Allow different days as start of the week #263

Open
alexewerlof opened this issue May 23, 2024 · 4 comments
Open

Allow different days as start of the week #263

alexewerlof opened this issue May 23, 2024 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@alexewerlof
Copy link

alexewerlof commented May 23, 2024

Problem to solve

Most countries consider Monday the start of the week:

wikipedia

  • Blue: Sunday
  • Green: Saturday
  • Orange: Monday

The current OpenSLO spec for timeWindow doesn't acknowledge that nuance for "calendar–aligned time window".

Proposal

I've been building another OSS tool that faced this same challenge.

I went for:

isFixed: string

Where the string can be w for week-bound, m for month-bound, q for quarter-bound, and y for year-bound.

For week, one can add an extra number to specify which exact day is the start:

  • w0 start the week on Sunday
  • w1 start the week on Monday
  • w6 start the week on Saturday

The reason I went with those exact numbers is because my tool is built in JS and this is how Javascript works (which is the reason I looked into seeing how OpenSLO solves this problem).

One could use the english day names (e.g., w-monday) or a shorthand (e.g., w-mo) but there's another use case which fits beautifully to the number-annotation: month-aligned time windows.

Suppose a SLO window needs to always start on the second day of the month. In my tool, it is indicated like this: m2 (why not start from zero? You guessed it! That's how Javascript works) 😄

Anyway, I'm not suggesting that OpenSLO should be using the same syntax as my code, but I hope we can agree that the need exists and we need to have a way to configure it:

Further details

To annotate a specific date, I suggest to use a number instead of the English name for the days (e.g. 1 instead of monday).

If N is the numerical value indicating the day of the week, it can map to a lookup table like this:

Day N Example Meaning
Sunday 0 w:0 Start the SLO window on Sunday
Monday 1 w:1 Second day of the week
Tuesday 2 w:2 Mid-start of the work week
Wednesday 3 w:3 Mid-week
Thursday 4 w:4 Nearing the end of the work week
Friday 5 w:5 End of the work week
Saturday 6 w:6 Weekend

Some other notable alternatives:

  • w(N)
  • w-N
  • wN
  • w_N
  • w::N

Month

By extension, it'd be great if we could have a way to specify a date other than the first day of the month as the start of the compliance period.

For example m+2 could mean the second day of the month and m-10 could mean 10 days before the current month ends.

The latter can be useful for systems that work with payroll where the majority of transactions happen on the last few days of the month.

This is just an idea. But my suggestion is to think about the month also, when finding a solution for the week.

Links / references

@alexewerlof alexewerlof added the enhancement New feature or request label May 23, 2024
@weyert
Copy link
Collaborator

weyert commented May 29, 2024

I am wondering if we could use the ISO 8601 Time intervals for this?

@anoopknayak
Copy link

I'm also in support of using ISO 8601 time-intervals for this. I'm not sure if this is the intended way to use the spec, but I was thinking of something like follows (I assume @weyert might also be thinking along the same lines, if not please correct me here).

If we want a weekly time window that starts on a wednesday we could potentially do something like:

    - duration: 1w
      calendar:
        startTime: 2024-06-19 00:00:00
        timeZone: America/New_York

@alexewerlof do you see a use case which will not be fulfilled with the above approach (assuming this is intended way)

@alexewerlof
Copy link
Author

@anoopknayak yeah I'm aware of that format.

The general format for specifying repeating periods in ISO 8601 is:

R[n]/start/duration where

  • The R character is for repetition (there's a R[n] convention for specifiying the number of repetitions indicated by n)
  • The P character is for periods

Advantage

Compliance: no need to reinvent the wheel. Sticking to the standard means that we can potentially benefit from the wider ecosystem that can parse, lint, and generate this format. Moreover, it keep the OpenSLO standard shorter because we can just refer to ISO 8601.

Disadvantage

Harder to read: It requires some mental gymnastics and lookup the date and see which day of the week it is (2024-06-19 is a Wednesday), and then reason about the implicit behavior that if the date starts in the middle of the week, that day of the week is considered as the start of the period going forward. One could refer to the documentation for that to know that behavior, but I believe the whole point of YAML is to make it human-readable and I'm not sure if this format with those 2 extra steps is immediately approachable and intuitive. It works, but probably we could do better.


So if we want to specify weekly periods starting from 2024-06-19 00:00:00, we could write R/2024-06-19T00:00:00/P1W.

Subjectively, harder to read, but due to the advantages above, it might be better than my initial suggestion?

Note:
The ISO 8601 durations uses uppercase W which is different from the OpenSLO duration shorthand.

@alexewerlof
Copy link
Author

In the group discussion today we agreed that we don't change the spec but rather be more specific with an example about how it's done.

For this use case, we can mention:

If you're using a calendar-bound compliance period (SLO window) which uses weeks as the unit (e.g. 4w), the day of the start date will be used as the starting day of the period by convention.

e.g: if the start date is 2024-10-09 which is a Wednesday, this means a calendar-bound config of 4w will always look back from the start of Wednesday <=4 weeks ago.

@fourstepper fourstepper added this to the v2 release milestone Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants