Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ tbd.
## Refactorings

* #128: Explicitly configured validation of SaaS SSL certificates in pyexasol connection

## Bugfixes

* #135: Made the database name semi-unique.
16 changes: 14 additions & 2 deletions exasol/saas/client/api_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,21 @@ def interval_retry(interval: timedelta, timeout: timedelta):

def timestamp_name(project_short_tag: str | None = None) -> str:
"""
project_short_tag: Abbreviation of your project
Generates a semi-unique name for a database with the following format:
- 0-4: number of minutes since the start of the year in hex,
- 0-5: a semi-random number,
- provided tag,
- -username.

Args:
project_short_tag: Abbreviation of your project
"""
timestamp = f"{datetime.now(timezone.utc).timestamp():.0f}"
now = datetime.now()
year_start = datetime(now.year, 1, 1)
minutes_elapsed = int((now - year_start).total_seconds() // 60)
random_suffix = time.time_ns() % 1048576
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So, we would need more or less a nanosecond collision to generate the same name. And, the minutes since year start only can collide, if instances would run for more then a year.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I come from assumption that nobody works around Xmas/New Year time. So, a DB left from the previous year is probably stuck and should be deleted. Overall, I call the names semi-unique, but it should be unique enough for practical purposes. Also, the minute resolution should be enough to see how long a DB is running.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I aimed to fit the changes into the same 10 characters that were previously occupied by the proper timestamp.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please note that this change will break some parts of our monitoring in GHA relying on the current specific timestamp format of the database names.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Where does the magic number 1048576 come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

2 ** 20 that cuts off a hex number 5 characters long.

timestamp = f"{minutes_elapsed:05x}{random_suffix:05x}"

owner = getpass.getuser()
candidate = f"{timestamp}{project_short_tag or ''}-{owner}"
return candidate[: Limits.MAX_DATABASE_NAME_LENGTH]
Expand Down
9 changes: 9 additions & 0 deletions exasol/saas/client/openapi/models/create_cluster.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions exasol/saas/client/openapi/models/scale_cluster.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading