-
Notifications
You must be signed in to change notification settings - Fork 7
[log] Add debug logging to DIFC agent module #751
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,12 @@ package difc | |
| import ( | ||
| "log" | ||
| "sync" | ||
|
|
||
| "github.com/github/gh-aw-mcpg/internal/logger" | ||
| ) | ||
|
|
||
| var logAgent = logger.New("difc:agent") | ||
|
|
||
| // AgentLabels associates each agent with their DIFC labels | ||
| // Tracks what secrecy and integrity tags an agent has accumulated | ||
| type AgentLabels struct { | ||
|
|
@@ -16,6 +20,7 @@ type AgentLabels struct { | |
|
|
||
| // NewAgentLabels creates a new agent with empty labels | ||
| func NewAgentLabels(agentID string) *AgentLabels { | ||
| logAgent.Printf("Creating new agent labels: agentID=%s", agentID) | ||
| return &AgentLabels{ | ||
| AgentID: agentID, | ||
| Secrecy: NewSecrecyLabel(), | ||
|
|
@@ -25,6 +30,8 @@ func NewAgentLabels(agentID string) *AgentLabels { | |
|
|
||
| // NewAgentLabelsWithTags creates a new agent with initial tags | ||
| func NewAgentLabelsWithTags(agentID string, secrecyTags []Tag, integrityTags []Tag) *AgentLabels { | ||
| logAgent.Printf("Creating agent labels with tags: agentID=%s, secrecyTags=%v, integrityTags=%v", | ||
| agentID, secrecyTags, integrityTags) | ||
| return &AgentLabels{ | ||
| AgentID: agentID, | ||
| Secrecy: NewSecrecyLabelWithTags(secrecyTags), | ||
|
|
@@ -34,6 +41,7 @@ func NewAgentLabelsWithTags(agentID string, secrecyTags []Tag, integrityTags []T | |
|
|
||
| // AddSecrecyTag adds a secrecy tag to the agent | ||
| func (a *AgentLabels) AddSecrecyTag(tag Tag) { | ||
| logAgent.Printf("Agent %s adding secrecy tag: %s", a.AgentID, tag) | ||
| a.mu.Lock() | ||
| defer a.mu.Unlock() | ||
| a.Secrecy.Label.Add(tag) | ||
|
|
@@ -42,6 +50,7 @@ func (a *AgentLabels) AddSecrecyTag(tag Tag) { | |
|
|
||
| // AddIntegrityTag adds an integrity tag to the agent | ||
| func (a *AgentLabels) AddIntegrityTag(tag Tag) { | ||
| logAgent.Printf("Agent %s adding integrity tag: %s", a.AgentID, tag) | ||
| a.mu.Lock() | ||
| defer a.mu.Unlock() | ||
| a.Integrity.Label.Add(tag) | ||
|
|
@@ -132,10 +141,13 @@ func NewAgentRegistryWithDefaults(defaultSecrecy []Tag, defaultIntegrity []Tag) | |
|
|
||
| // GetOrCreate gets an existing agent or creates a new one with default labels | ||
| func (r *AgentRegistry) GetOrCreate(agentID string) *AgentLabels { | ||
| logAgent.Printf("GetOrCreate called for agentID=%s", agentID) | ||
|
|
||
| // Try to get existing agent first (read lock) | ||
| r.mu.RLock() | ||
| if labels, ok := r.agents[agentID]; ok { | ||
| r.mu.RUnlock() | ||
| logAgent.Printf("Found existing agent: %s", agentID) | ||
| return labels | ||
| } | ||
| r.mu.RUnlock() | ||
|
|
@@ -146,6 +158,7 @@ func (r *AgentRegistry) GetOrCreate(agentID string) *AgentLabels { | |
|
|
||
| // Double-check after acquiring write lock | ||
| if labels, ok := r.agents[agentID]; ok { | ||
| logAgent.Printf("Agent %s created by another goroutine", agentID) | ||
| return labels | ||
|
Comment on lines
160
to
162
|
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains trailing whitespace on an otherwise blank line; please remove it (or run gofmt) to avoid noisy diffs and keep formatting consistent.