- Notifications
You must be signed in to change notification settings - Fork1k
feat: add groups and group members to telemetry snapshot#13655
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
139adf6
c665b4a
c865d65
be0c1f5
c4b12de
4b3e975
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
-- name: GetGroupMembers :many | ||
SELECT * FROM group_members; | ||
-- name: GetGroupMembersByGroupID :many | ||
SELECT | ||
users.* | ||
FROM | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
-- name: GetGroups :many | ||
SELECT * FROM groups; | ||
-- name: GetGroupByID :one | ||
SELECT | ||
* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -344,9 +344,6 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) { | ||
users := database.ConvertUserRows(userRows) | ||
var firstUser database.User | ||
for _, dbUser := range users { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It looks like this is from your previous pr#13613 | ||
if firstUser.CreatedAt.IsZero() { | ||
firstUser = dbUser | ||
} | ||
@@ -366,6 +363,28 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) { | ||
} | ||
return nil | ||
}) | ||
eg.Go(func() error { | ||
groups, err := r.options.Database.GetGroups(ctx) | ||
if err != nil { | ||
return xerrors.Errorf("get groups: %w", err) | ||
} | ||
snapshot.Groups = make([]Group, 0, len(groups)) | ||
for _, group := range groups { | ||
snapshot.Groups = append(snapshot.Groups, ConvertGroup(group)) | ||
} | ||
return nil | ||
}) | ||
eg.Go(func() error { | ||
groupMembers, err := r.options.Database.GetGroupMembers(ctx) | ||
if err != nil { | ||
return xerrors.Errorf("get groups: %w", err) | ||
} | ||
snapshot.GroupMembers = make([]GroupMember, 0, len(groupMembers)) | ||
for _, member := range groupMembers { | ||
snapshot.GroupMembers = append(snapshot.GroupMembers, ConvertGroupMember(member)) | ||
} | ||
return nil | ||
}) | ||
eg.Go(func() error { | ||
workspaceRows, err := r.options.Database.GetWorkspaces(ctx, database.GetWorkspacesParams{}) | ||
if err != nil { | ||
@@ -642,6 +661,26 @@ func ConvertUser(dbUser database.User) User { | ||
EmailHashed: emailHashed, | ||
RBACRoles: dbUser.RBACRoles, | ||
CreatedAt: dbUser.CreatedAt, | ||
Status: dbUser.Status, | ||
} | ||
} | ||
func ConvertGroup(group database.Group) Group { | ||
return Group{ | ||
ID: group.ID, | ||
Name: group.Name, | ||
OrganizationID: group.OrganizationID, | ||
AvatarURL: group.AvatarURL, | ||
QuotaAllowance: group.QuotaAllowance, | ||
DisplayName: group.DisplayName, | ||
Source: group.Source, | ||
} | ||
} | ||
func ConvertGroupMember(member database.GroupMember) GroupMember { | ||
return GroupMember{ | ||
GroupID: member.GroupID, | ||
UserID: member.UserID, | ||
} | ||
} | ||
@@ -746,6 +785,8 @@ type Snapshot struct { | ||
TemplateVersions []TemplateVersion `json:"template_versions"` | ||
Templates []Template `json:"templates"` | ||
Users []User `json:"users"` | ||
Groups []Group `json:"groups"` | ||
GroupMembers []GroupMember `json:"group_members"` | ||
WorkspaceAgentStats []WorkspaceAgentStat `json:"workspace_agent_stats"` | ||
WorkspaceAgents []WorkspaceAgent `json:"workspace_agents"` | ||
WorkspaceApps []WorkspaceApp `json:"workspace_apps"` | ||
@@ -797,6 +838,21 @@ type User struct { | ||
Status database.UserStatus `json:"status"` | ||
} | ||
type Group struct { | ||
ID uuid.UUID `json:"id"` | ||
Name string `json:"name"` | ||
OrganizationID uuid.UUID `json:"organization_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
QuotaAllowance int32 `json:"quota_allowance"` | ||
DisplayName string `json:"display_name"` | ||
Source database.GroupSource `json:"source"` | ||
} | ||
type GroupMember struct { | ||
UserID uuid.UUID `json:"user_id"` | ||
GroupID uuid.UUID `json:"group_id"` | ||
} | ||
type WorkspaceResource struct { | ||
ID uuid.UUID `json:"id"` | ||
CreatedAt time.Time `json:"created_at"` | ||
Uh oh!
There was an error while loading.Please reload this page.