Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat(sg): send analytic events to bigquery#63674

Merged
burmudar merged 9 commits into
nsc/sg-analytics-localstorefrom
wb/sg/analytics-send-events
Jul 9, 2024
Merged

feat(sg): send analytic events to bigquery#63674
burmudar merged 9 commits into
nsc/sg-analytics-localstorefrom
wb/sg/analytics-send-events

Conversation

@burmudar

@burmudar burmudar commented Jul 5, 2024

Copy link
Copy Markdown
Contributor

Reads events from the local analytics db and writes them to events table in the bigquery sg_analytics dataset

Example of published events

{
  "uuid": "01908369-9f55-7ed0-b8ff-79a804e4ead5",
  "user_id": "anonymous",
  "inserted_at": "2024-07-05 15:03:25.108429 UTC",
  "recorded_at": "2024-07-05 15:01:00.578734 UTC",
  "command": "sg live",
  "version": "unknown",
  "flags_and_args": "{\"args\":[\"dotcom\"],\"flags\":{\"live\":null,\"sg\":[\"disable-analytics\"]}}",
  "duration": "0-0 0 0:0:4",
  "error": "",
  "data": null,
  "metadata": "{\"cancelled\":false,\"failed\":false,\"panicked\":false,\"success\":true}"
}, {
  "uuid": "0190836b-e1e3-7b2b-8002-e5eba10f2a27",
  "user_id": "anonymous",
  "inserted_at": "2024-07-05 15:04:22.344947 UTC",
  "recorded_at": "2024-07-05 15:03:33.360211 UTC",
  "command": "sg bazel configure",
  "version": "unknown",
  "flags_and_args": "{\"args\":[],\"flags\":{\"bazel\":null,\"configure\":null,\"sg\":[\"disable-analytics\"]}}",
  "duration": "0-0 0 0:0:9",
  "error": "signal: killed",
  "data": null,
  "metadata": "{\"cancelled\":true,\"failed\":true,\"panicked\":false,\"success\":false}"
}, {
  "uuid": "0190836c-c191-78f4-93f5-d2c0da4e0873",
  "user_id": "anonymous",
  "inserted_at": "2024-07-05 15:06:04.153071 UTC",
  "recorded_at": "2024-07-05 15:05:27.525827 UTC",
  "command": "sg start",
  "version": "unknown",
  "flags_and_args": "{\"args\":[\"enterprise-bazel\"],\"flags\":{\"sg\":[\"disable-analytics\"],\"start\":null}}",
  "duration": "0-0 0 0:1:6",
  "error": "",
  "data": null,
  "metadata": "{\"cancelled\":true,\"failed\":false,\"panicked\":false,\"success\":true}"
}, {
  "uuid": "0190836e-4f48-7718-80c2-9ba82636b4ae",
  "user_id": "anonymous",
  "inserted_at": "2024-07-05 15:07:41.263882 UTC",
  "recorded_at": "2024-07-05 15:06:10.849122 UTC",
  "command": "sg cloud ephemeral list-versions",
  "version": "unknown",
  "flags_and_args": "{\"args\":[],\"flags\":{\"cloud\":null,\"ephemeral\":null,\"list-versions\":null,\"sg\":[\"disable-analytics\"]}}",
  "duration": "0-0 0 0:0:7",
  "error": "",
  "data": null,
  "metadata": "{\"cancelled\":false,\"failed\":false,\"panicked\":false,\"success\":true}"
}]	

Fields that are published

The following event attributes are puslished:

  • command
  • version
  • flags_ang_args
  • error
  • recorded_at
  • metadata: which contains cancelled, failed, panicked and sucess (should this possibly be stored under status instead?)

The metadata field can and should be expanded.

What is missing?

  • Need to expand what is added to metadata
  • Need to use and expand what is put into data

Test plan

Tested locally and https://console.cloud.google.com/bigquery?referrer=search&project=sourcegraph-local-dev&ws=!1m10!1m4!4m3!1ssourcegraph-local-dev!2ssg_analytics!3sevents!1m4!1m3!1ssourcegraph-local-dev!2sbquxjob_761f4a78_1908370012d!3sus-central1

Changelog

burmudar added 4 commits July 5, 2024 14:26
The following fields in the events table are populated
- command, version, flags_and_args, error, duration and recorded_at
@burmudar burmudar self-assigned this Jul 5, 2024
@cla-bot cla-bot Bot added the cla-signed label Jul 5, 2024
@burmudar burmudar requested review from Strum355 and jhchabran July 5, 2024 15:21
Comment thread dev/sg/internal/analytics/sqlite.go
metadata map[string]any
}

func (i invocation) GetStartTime() *time.Time {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aren't these funcs an UnmarshalJSON() on the metadata type in disguise?

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.

This is an excellent point 🙏🏼

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.

Still have to look into this

Comment thread dev/sg/internal/analytics/analytics.go Outdated
Comment thread dev/sg/internal/analytics/background.go Outdated
Comment thread dev/sg/internal/analytics/background.go Outdated
Comment thread dev/sg/internal/analytics/bigquery.go
Comment thread dev/sg/internal/analytics/bigquery.go
@burmudar burmudar requested a review from jhchabran July 8, 2024 17:06
@burmudar burmudar merged this pull request into nsc/sg-analytics-localstore Jul 9, 2024
@burmudar burmudar deleted the wb/sg/analytics-send-events branch July 9, 2024 08:27
burmudar added a commit that referenced this pull request Jul 9, 2024
Reads events from the local analytics db and writes them to events table
in the bigquery `sg_analytics` dataset
```
{
  "uuid": "01908369-9f55-7ed0-b8ff-79a804e4ead5",
  "user_id": "anonymous",
  "inserted_at": "2024-07-05 15:03:25.108429 UTC",
  "recorded_at": "2024-07-05 15:01:00.578734 UTC",
  "command": "sg live",
  "version": "unknown",
  "flags_and_args": "{\"args\":[\"dotcom\"],\"flags\":{\"live\":null,\"sg\":[\"disable-analytics\"]}}",
  "duration": "0-0 0 0:0:4",
  "error": "",
  "data": null,
  "metadata": "{\"cancelled\":false,\"failed\":false,\"panicked\":false,\"success\":true}"
}, {
  "uuid": "0190836b-e1e3-7b2b-8002-e5eba10f2a27",
  "user_id": "anonymous",
  "inserted_at": "2024-07-05 15:04:22.344947 UTC",
  "recorded_at": "2024-07-05 15:03:33.360211 UTC",
  "command": "sg bazel configure",
  "version": "unknown",
  "flags_and_args": "{\"args\":[],\"flags\":{\"bazel\":null,\"configure\":null,\"sg\":[\"disable-analytics\"]}}",
  "duration": "0-0 0 0:0:9",
  "error": "signal: killed",
  "data": null,
  "metadata": "{\"cancelled\":true,\"failed\":true,\"panicked\":false,\"success\":false}"
}]
```
The following event attributes are puslished:
- command
- version
- flags_ang_args
- error
- recorded_at
- metadata: which contains cancelled, failed, panicked and sucess
(should this possibly be stored under status instead?)

The metadata field can and _should_ be expanded.

* Need to expand what is added to metadata
* Need to use and expand what is put into data

Tested locally and
https://console.cloud.google.com/bigquery?referrer=search&project=sourcegraph-local-dev&ws=!1m10!1m4!4m3!1ssourcegraph-local-dev!2ssg_analytics!3sevents!1m4!1m3!1ssourcegraph-local-dev!2sbquxjob_761f4a78_1908370012d!3sus-central1

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants