fleet/tools/calendar
Victor Lyuboslavsky c1a5e3b7b6
Fix calendar duplicated events and other issues (#20443)
#19352
Includes the following changes:
- Re-enable calendar callback
- Introduced a new Redis key that indicates event was updated by
calendar callback. In that case, we ignore subsequent callbacks for 10
seconds.
- This reduces the amount of Google API calls, including handling of the
unneeded callback generated by our own event change.
- Read event from DB after acquiring lock. This is critical since we get
the updated ETag of the Google Calendar event from our DB. Using the
previous ETag when fetching event sometimes returns stale data,
resulting in duplicate events.
- Fixed bug in getCalendarLock where calendar cron would always think it
got the lock
- Do not refetch timezone during calendar callback to reduce Google API
load
- Watch for calendar event changes for 1 week after event end (to
account for user moving event into the future)
- #20442: Speculative improvement for Google callback latency by keeping
the same notification channel (callback URL).
- processCalendarAsync now takes at least 1 sec to process all events,
to reduce CPU/Redis load
- Increased lock expiration time from 1 minute to 20 minutes to account
for potential Google API retries, fixing occasional duplicate events.
- Added `get-events.go` helper script that gets maintenance events from
user calendars, and checks for duplicates

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-07-24 13:40:33 +02:00
..
delete-events Distributed lock and store calendar_events UUID as binary in MySQL (#20277) 2024-07-10 08:49:05 -05:00
get-events Fix calendar duplicated events and other issues (#20443) 2024-07-24 13:40:33 +02:00
move-events Distributed lock and store calendar_events UUID as binary in MySQL (#20277) 2024-07-10 08:49:05 -05:00
stop-channel Check for calendar updates after callbacks from Google (#20156) 2024-07-08 10:20:03 -05:00
calendar.go Adding calendar test server and other fixes. (#17751) 2024-03-26 13:39:37 -05:00
README.md Check for calendar updates after callbacks from Google (#20156) 2024-07-08 10:20:03 -05:00

Helper methods for Google calendar

To delete all downtime events from a Google Calendar, use delete-events/delete-events.go

To move all downtime events from multiple Google Calendars to a specific time, use move-events/move-events.go

To use the helper scripts, you must set FLEET_TEST_GOOGLE_CALENDAR_SERVICE_EMAIL and FLEET_TEST_GOOGLE_CALENDAR_PRIVATE_KEY environment variables. The email is the client_email from JSON key file. The private key also comes from JSON key file for the service account, and starts with -----BEGIN PRIVATE KEY-----.

Calendar server for load testing

Test calendar server that provides a REST API for managing events. Since we may not have access to a real calendar server (such as Google Calendar API), this server will be used to test the calendar feature during load testing.

Start the server like:

go run calendar.go --port 8083 --db ./calendar.db

The server uses a SQLite database to store events. This database can be modified during testing.

On the fleet server, configure Google Calendar API key where client_email is the specified value and the private_key is the base URL of the calendar server:

{
    "client_email": "calendar-load@example.com",
    "private_key": "http://localhost:8083"
}

Useful tricks

To update all the events in SQLite database to start at the current time, do SQL query:

UPDATE events SET start = unixepoch('now'), end = unixepoch('now', '+30 minutes');