Skip to content

Check for calendar updates after callbacks from Google#20156

Merged
getvictor merged 11 commits intomainfrom
victor/19352-calendar-real-time
Jul 8, 2024
Merged

Check for calendar updates after callbacks from Google#20156
getvictor merged 11 commits intomainfrom
victor/19352-calendar-real-time

Conversation

@getvictor
Copy link
Copy Markdown
Member

@getvictor getvictor commented Jul 2, 2024

#19352

Video explaining code changes: https://www.loom.com/share/370200a276b84aa388effd6ebd762e01?sid=038508c4-f3c2-40c0-baf6-6b6df682d1f0

In maintenance windows using Google Calendar, calendar event is now recreated within 30 seconds if deleted or moved to the past.

  • Added new endpoint for Google Calendar: /api/_version_/fleet/calendar/webhook/{event_uuid}
  • Added UUID to calendar_events table to make webhook lookup more efficient
  • webhook endpoint will only recreate event if needed -- it will not fire webhook. Webhook is still done by the cron job.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Added/updated tests
  • If database migrations are included, checked table schema to confirm autoupdate
  • For database migrations:
    • Checked schema for all modified table for columns that will auto-update timestamps during migration.
    • Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects.
    • Ensured the correct collation is explicitly set for character columns (COLLATE utf8mb4_unicode_ci).
  • Manual QA for all new/changed functionality
    • For Orbit and Fleet Desktop changes:

Comment thread server/service/calendar/calendar.go Outdated

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types

Incorrect conversion of an unsigned 64-bit integer from [strconv.ParseUint](1) to a lower bit size type uint without an upper bound check.
@getvictor getvictor force-pushed the victor/19352-calendar-real-time branch from 928268c to 11f8cd2 Compare July 2, 2024 16:47
@getvictor getvictor force-pushed the victor/19352-calendar-real-time branch from 8b6c6ec to 119665c Compare July 2, 2024 19:15
@getvictor getvictor force-pushed the victor/19352-calendar-real-time branch from 67b2a55 to b129369 Compare July 3, 2024 13:48
@getvictor getvictor marked this pull request as ready for review July 3, 2024 15:05
@getvictor getvictor requested review from a team, gillespi314, lucasmrod and roperzh as code owners July 3, 2024 15:05
@getvictor getvictor force-pushed the victor/19352-calendar-real-time branch from c82cf43 to d184869 Compare July 7, 2024 15:50
Copy link
Copy Markdown
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

LGTM!

Left a couple of questions to under stand some of the changes before approving.

We should let the product team know that this new feature happens for new events, right?

Comment thread ee/server/service/calendar.go
Comment thread server/cron/calendar_cron.go

func Up_20240626195531(tx *sql.Tx) error {
if _, err := tx.Exec(`ALTER TABLE calendar_events ADD COLUMN timezone VARCHAR(64) NULL`); err != nil {
if _, err := tx.Exec(`ALTER TABLE calendar_events ADD COLUMN timezone VARCHAR(64) COLLATE utf8mb4_unicode_ci NULL`); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This migration wasn't released yet, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(And thanks for catching this!)

func Up_20240707134035(tx *sql.Tx) error {
// UUID is a 36-character string with the most common 8-4-4-4-12 format, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
// Reference: https://en.wikipedia.org/wiki/Universally_unique_identifier#Textual_representation
if _, err := tx.Exec(`ALTER TABLE calendar_events ADD COLUMN uuid VARCHAR(36) COLLATE utf8mb4_unicode_ci NOT NULL`); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We use UUID v4, the entirely random version of UUIDs. Such randomness make writes expensive (rebalancing
B+ trees on random-value writes is expensive). See https://planetscale.com/blog/the-problem-with-using-a-uuid-primary-key-in-mysql. That said, it is maybe a-ok for now as this is not a heavy used table like hosts.

Maybe an optimization for later: we could use BINARY(16); see https://dev.mysql.com/blog-archive/storing-uuid-values-in-mysql-tables/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This makes sense. I'll try to get this optimization in before the release.

Comment on lines +8476 to +8477
team1Policy1Calendar.ID: ptr.Bool(true),
team1Policy2.ID: ptr.Bool(false),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Curious why you are changing from team2 to team1.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This looked like a copy/paste error -- I think it was supposed to be team1 initially.

},
)
require.NoError(t, err)
team1Policy2, err := s.ds.NewTeamPolicy(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rename to team1Policy2Calendar? (has CalendarEventsEnabled : true), or set CalendarEventsEnabled: false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, will make the change for the next PR.

Comment thread server/service/integration_enterprise_test.go
// Apply current migration.
applyNext(t, db)

// check that it's NULL
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

// check that it's not NULL
?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, will fix in the next PR

Comment thread tools/calendar/stop-channel/stop-channel.go
@getvictor getvictor merged commit df141cd into main Jul 8, 2024
@getvictor getvictor deleted the victor/19352-calendar-real-time branch July 8, 2024 15:20
getvictor added a commit that referenced this pull request Jul 10, 2024
…20277)

#19352

Fix for code review comment:
#20156 (comment)

Also includes changes from #20252

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Added/updated tests
- [x] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [x] Manual QA for all new/changed functionality
getvictor added a commit that referenced this pull request Jul 10, 2024
…20277)

#19352

Fix for code review comment:
#20156 (comment)

Also includes changes from #20252

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Added/updated tests
- [x] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [x] Manual QA for all new/changed functionality

(cherry picked from commit 7bcd61a)
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.

3 participants