mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add support for sending batched agent metadata (#10223)
Part of #9782
This commit is contained in:
@@ -3518,13 +3518,20 @@ func (q *FakeQuerier) GetWorkspaceAgentLogsAfter(_ context.Context, arg database
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetWorkspaceAgentMetadata(_ context.Context, workspaceAgentID uuid.UUID) ([]database.WorkspaceAgentMetadatum, error) {
|
||||
func (q *FakeQuerier) GetWorkspaceAgentMetadata(_ context.Context, arg database.GetWorkspaceAgentMetadataParams) ([]database.WorkspaceAgentMetadatum, error) {
|
||||
if err := validateDatabaseType(arg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
metadata := make([]database.WorkspaceAgentMetadatum, 0)
|
||||
for _, m := range q.workspaceAgentMetadata {
|
||||
if m.WorkspaceAgentID == workspaceAgentID {
|
||||
if m.WorkspaceAgentID == arg.WorkspaceAgentID {
|
||||
if len(arg.Keys) > 0 && !slices.Contains(arg.Keys, m.Key) {
|
||||
continue
|
||||
}
|
||||
metadata = append(metadata, m)
|
||||
}
|
||||
}
|
||||
@@ -6133,19 +6140,17 @@ func (q *FakeQuerier) UpdateWorkspaceAgentMetadata(_ context.Context, arg databa
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
//nolint:gosimple
|
||||
updated := database.WorkspaceAgentMetadatum{
|
||||
WorkspaceAgentID: arg.WorkspaceAgentID,
|
||||
Key: arg.Key,
|
||||
Value: arg.Value,
|
||||
Error: arg.Error,
|
||||
CollectedAt: arg.CollectedAt,
|
||||
}
|
||||
|
||||
for i, m := range q.workspaceAgentMetadata {
|
||||
if m.WorkspaceAgentID == arg.WorkspaceAgentID && m.Key == arg.Key {
|
||||
q.workspaceAgentMetadata[i] = updated
|
||||
return nil
|
||||
if m.WorkspaceAgentID != arg.WorkspaceAgentID {
|
||||
continue
|
||||
}
|
||||
for j := 0; j < len(arg.Key); j++ {
|
||||
if m.Key == arg.Key[j] {
|
||||
q.workspaceAgentMetadata[i].Value = arg.Value[j]
|
||||
q.workspaceAgentMetadata[i].Error = arg.Error[j]
|
||||
q.workspaceAgentMetadata[i].CollectedAt = arg.CollectedAt[j]
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user