Skip to content

Commit 4f293ab

Browse files
committed
Remove UUID handling and fix unit test
1 parent 071b288 commit 4f293ab

File tree

9 files changed

+123
-162
lines changed

9 files changed

+123
-162
lines changed

.github/workflows/graphs/build-test-publish.act

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ nodes:
199199
else
200200
P4_LIB="$(pwd)/p4api/windows-x86_64/lib"
201201
P4_CGO_CPPFLAGS="-I$P4_INCLUDE -DOS_NT"
202-
P4_CGO_LDFLAGS="-L$P4_LIB -lp4api -lssl -lcrypto -lcrypt32 -lws2_32 -lole32 -lshell32 -luser32 -ladvapi32"
202+
SSL_LIB="$(pwd)/p4api/ssl-windows-x64/lib"
203+
# Install Perl modules and make required by OpenSSL's Configure script
204+
pacman -S --noconfirm --needed make perl-IPC-Cmd
205+
bash setup-openssl.sh windows x64 "$SSL_LIB"
206+
P4_CGO_LDFLAGS="-L$P4_LIB -lp4api $SSL_LIB/libssl.a $SSL_LIB/libcrypto.a -lcrypt32 -lws2_32 -lole32 -lshell32 -luser32 -ladvapi32"
203207
fi
204208
;;
205209
esac

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
strategy:
7474
matrix:
7575
license: [free] # add pro when ready
76-
os: [windows-latest, ubuntu-latest, ubuntu-24.04-arm, macos-latest]
76+
os: [windows-latest]
7777

7878
runs-on: ${{ matrix.os }}
7979

agent/client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
type Client struct {
1313
serverURL string
1414
token string
15-
uuid string
1615
httpClient *http.Client
1716
}
1817

@@ -26,10 +25,6 @@ func NewClient(serverURL, token string) *Client {
2625
}
2726
}
2827

29-
func (c *Client) SetUUID(uuid string) {
30-
c.uuid = uuid
31-
}
32-
3328
func (c *Client) doRequest(method, path string, body interface{}) (*http.Response, error) {
3429
var bodyReader io.Reader
3530
if body != nil {
@@ -45,9 +40,6 @@ func (c *Client) doRequest(method, path string, body interface{}) (*http.Respons
4540
return nil, err
4641
}
4742
req.Header.Set("Authorization", "Bearer "+c.token)
48-
if c.uuid != "" {
49-
req.Header.Set("X-Agent-UUID", c.uuid)
50-
}
5143
if body != nil {
5244
req.Header.Set("Content-Type", "application/json")
5345
}

agent/flock_unix.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

agent/flock_windows.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

agent/models.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ type StatusReport struct {
7474

7575
// HeartbeatRequest is sent periodically with agent metrics.
7676
type HeartbeatRequest struct {
77-
UUID string `json:"uuid,omitempty"`
7877
CPUPercent float64 `json:"cpu_percent"`
7978
MemPercent float64 `json:"mem_percent"`
8079
MemUsedBytes int64 `json:"mem_used_bytes"`

agent/worker.go

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package agent
33
import (
44
"bufio"
55
"context"
6-
"crypto/rand"
76
"fmt"
87
"os"
98
"os/exec"
@@ -25,106 +24,27 @@ type Worker struct {
2524
docker DockerConfig
2625
vcsOpts vcs.Options
2726
pollInterval time.Duration
28-
uuid string
29-
slotCleanup func()
3027
log *logrus.Entry
3128

3229
metricsMu sync.Mutex
3330
lastCounters *RawCounters
3431
}
3532

3633
func NewWorker(client *Client, docker DockerConfig, vcsOpts vcs.Options) *Worker {
37-
uuid, cleanup := acquireAgentSlot()
38-
client.SetUUID(uuid)
3934
return &Worker{
4035
client: client,
4136
docker: docker,
4237
vcsOpts: vcsOpts,
4338
pollInterval: 1 * time.Second,
44-
uuid: uuid,
45-
slotCleanup: cleanup,
4639
log: logrus.WithField("component", "agent"),
4740
}
4841
}
4942

50-
// agentSlotDir returns the directory for agent UUID slot files.
51-
func agentSlotDir() string {
52-
dir, err := os.UserConfigDir()
53-
if err != nil {
54-
dir = os.TempDir()
55-
}
56-
return filepath.Join(dir, "actionforge")
57-
}
58-
59-
// acquireAgentSlot finds and locks the lowest available agent slot.
60-
// Each slot has a persistent UUID file and a lock file. When the process
61-
// exits, the lock is released so the next process can reuse that slot
62-
// (and its UUID/metrics history).
63-
// Returns the UUID and a cleanup function that releases the lock.
64-
func acquireAgentSlot() (string, func()) {
65-
dir := agentSlotDir()
66-
_ = os.MkdirAll(dir, 0700)
67-
68-
const maxSlots = 256
69-
for i := 0; i < maxSlots; i++ {
70-
lockPath := filepath.Join(dir, fmt.Sprintf("agent-%d.lock", i))
71-
uuidPath := filepath.Join(dir, fmt.Sprintf("agent-%d.uuid", i))
72-
73-
lockFile, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0600)
74-
if err != nil {
75-
continue
76-
}
77-
78-
if err := lockFileExclusive(lockFile); err != nil {
79-
if cerr := lockFile.Close(); cerr != nil {
80-
logrus.WithError(cerr).Warn("failed to close lock file")
81-
}
82-
continue
83-
}
84-
85-
// Slot acquired — read or generate UUID
86-
uuid := ""
87-
if data, err := os.ReadFile(uuidPath); err == nil {
88-
if id := strings.TrimSpace(string(data)); len(id) == 36 {
89-
uuid = id
90-
}
91-
}
92-
if uuid == "" {
93-
var buf [16]byte
94-
_, _ = rand.Read(buf[:])
95-
buf[6] = (buf[6] & 0x0f) | 0x40 // version 4
96-
buf[8] = (buf[8] & 0x3f) | 0x80 // variant 1
97-
uuid = fmt.Sprintf("%08x-%04x-%04x-%04x-%012x",
98-
buf[0:4], buf[4:6], buf[6:8], buf[8:10], buf[10:16])
99-
_ = os.WriteFile(uuidPath, []byte(uuid+"\n"), 0600)
100-
}
101-
102-
cleanup := func() {
103-
unlockFile(lockFile)
104-
if cerr := lockFile.Close(); cerr != nil {
105-
logrus.WithError(cerr).Warn("failed to close lock file")
106-
}
107-
}
108-
return uuid, cleanup
109-
}
110-
111-
// Fallback: all slots taken, generate ephemeral UUID with no lock
112-
var buf [16]byte
113-
_, _ = rand.Read(buf[:])
114-
buf[6] = (buf[6] & 0x0f) | 0x40
115-
buf[8] = (buf[8] & 0x3f) | 0x80
116-
return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x",
117-
buf[0:4], buf[4:6], buf[6:8], buf[8:10], buf[10:16]), func() {}
118-
}
119-
12043
// maxConsecutiveErrors is the number of consecutive connection errors before
12144
// Run returns ErrConnectionLost so the caller can decide to restart.
12245
const maxConsecutiveErrors = 10
12346

12447
func (w *Worker) Run(ctx context.Context) error {
125-
if w.slotCleanup != nil {
126-
defer w.slotCleanup()
127-
}
12848
w.log.Info("starting")
12949

13050
// Take initial snapshot for delta computation
@@ -632,13 +552,13 @@ func (w *Worker) buildHeartbeatRequest() HeartbeatRequest {
632552
snap, err := Snapshot()
633553
if err != nil {
634554
w.log.WithError(err).Warn("metrics snapshot error")
635-
return HeartbeatRequest{UUID: w.uuid}
555+
return HeartbeatRequest{}
636556
}
637557

638558
w.metricsMu.Lock()
639559
defer w.metricsMu.Unlock()
640560

641-
req := HeartbeatRequest{UUID: w.uuid}
561+
req := HeartbeatRequest{}
642562
if w.lastCounters != nil {
643563
// CPU percent
644564
if snap.CPUInstant {
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
//depot/pong/background.jpg#1 - add change 3 (binary+F)
2-
//depot/pong/build-pong-game.act#1 - add change 3 (text)
3-
//depot/pong/tutorial-readme.md#1 - add change 3 (text)
1+
build hasn't expired yet
2+
looking for value: 'env_file'
3+
no value (is optional) found for: 'env_file'
4+
looking for value: 'config_file'
5+
no value (is optional) found for: 'config_file'
6+
looking for value: 'concurrency'
7+
no value (is optional) found for: 'concurrency'
8+
looking for value: 'graph_file'
9+
no value (is optional) found for: 'graph_file'
10+
looking for value: 'session_token'
11+
no value (is optional) found for: 'session_token'
12+
looking for value: 'create_debug_session'
13+
found value in flags
14+
evaluated to: 'false'
15+
PushNodeVisit: start, execute: true
16+
🟢 Execute 'P4 Run (list-files)'
17+
PushNodeVisit: list-files, execute: true
18+
🟢 Execute 'Print (print-result)'
19+
PushNodeVisit: print-result, execute: true
20+
PushNodeVisit: (cached) list-files, execute: false
21+
[REDACTED]/background.jpg#1 - add change 3 (binary+F)
22+
[REDACTED]/build-pong-game.act#2 - edit change 4 (text)
23+
[REDACTED]/tutorial-readme.md#1 - add change 3 (text)

0 commit comments

Comments
 (0)