Skip to content

refactor: refactor the code to be more structured and find bugs - #185

Open
tarungka wants to merge 5 commits into
masterfrom
refactor/readbility
Open

refactor: refactor the code to be more structured and find bugs#185
tarungka wants to merge 5 commits into
masterfrom
refactor/readbility

Conversation

@tarungka

Copy link
Copy Markdown
Owner

No description provided.

tarungka and others added 3 commits May 11, 2026 04:16
The k6 uppercase pipeline finishes per-job in microseconds, so the
wire_coordinator_job_duration_seconds histogram only ever records
queue wait — useless for measuring actual end-to-end in-system time
under realistic CPU pressure.

Add a configurable CPU-burn pipeline:

1. cpu-burn map operator (wire-worker-example/main.go) — hashes each
   event's value Rounds times in a tight SHA-256 chain. Each round
   feeds the previous hash back in so the compiler can't elide the
   loop. Config is msgpack CPUBurnConfig{Rounds: uint32}; default
   50 000 when config is empty.

2. print-cpuburn-graph helper (examples/print-cpuburn-graph/) emits a
   base64 graph_bytes blob for Source → Map(cpu-burn) → Sink with CLI
   flags --rounds, --events, --payload-bytes. Source events are
   position-filled so the hash chain stays distinct per event.

3. Dockerfile.wire builds + installs the new binary so the compose
   stack stays self-contained.

4. docker-compose.yml gains a k6-cpu profile mirroring the existing
   k6 profile but using print-cpuburn-graph for the request body.
   BURN_ROUNDS / BURN_EVENTS / BURN_PAYLOAD env vars tune the workload
   at graph-build time. Default RPS is 2 — at 50000 rounds × 100
   events × 4 task slots the worker drains ~9 jobs/sec/core, so 2 RPS
   submitted keeps the queue near-empty and the histogram reflects
   pure processing time.

Measured on this host:
  rounds=10000   events=100 → ~95 ms/job
  rounds=50000   events=100 → ~440 ms/job  (default)
  rounds=100000  events=100 → ~860 ms/job
  rounds=500000  events=100 → ~4.3 s/job

Run with:
  docker compose --profile k6-cpu run --rm k6-cpu
  BURN_ROUNDS=100000 RPS=4 DURATION=3m \
    docker compose --profile k6-cpu run --rm k6-cpu

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

Found 27 issues (🔴 18 high · 🟠 9 medium · 🟡 0 low).

Findings
Severity Rule File:Line Message
🔴 HIGH G115 (CWE-190) internal/coordinator/scheduler.go:257 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/coordinator/store_pebble.go:76 integer overflow conversion int -> uint64
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:301 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:306 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:310 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:345 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:44 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:45 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion uint32 -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/protocol/frame.go:112 integer overflow conversion int -> uint32
🔴 HIGH G404 (CWE-338) internal/rpc/client.go:211 Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)
🔴 HIGH G115 (CWE-190) internal/rpc/codec.go:117 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:246 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:256 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/graph_converter.go:30 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion uint64 -> int
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion int -> uint64
🟠 MEDIUM G304 (CWE-22) cmd/main.go:217 Potential file inclusion via variable
🟠 MEDIUM G302 (CWE-276) cmd/main.go:217 Expect file permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/election_filelock.go:38 Expect directory permissions to be 0750 or less
🟠 MEDIUM G302 (CWE-276) internal/coordinator/election_filelock.go:53 Expect file permissions to be 0600 or less
🟠 MEDIUM G304 (CWE-22) internal/coordinator/election_filelock.go:135 Potential file inclusion via variable
🟠 MEDIUM G306 (CWE-276) internal/coordinator/election_filelock.go:143 Expect WriteFile permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/store_memory.go:132 Expect directory permissions to be 0750 or less

…and 2 more. Full SARIF report on the repo's Security tab.

Comment thread cmd/main.go
}

func openLogFile(path string) *os.File {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
Comment thread cmd/main.go
}

func openLogFile(path string) *os.File {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

Found 27 issues (🔴 18 high · 🟠 9 medium · 🟡 0 low).

Findings
Severity Rule File:Line Message
🔴 HIGH G115 (CWE-190) internal/coordinator/scheduler.go:257 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/coordinator/store_pebble.go:76 integer overflow conversion int -> uint64
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:301 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:306 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:310 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:345 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:44 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:45 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion uint32 -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/protocol/frame.go:112 integer overflow conversion int -> uint32
🔴 HIGH G404 (CWE-338) internal/rpc/client.go:211 Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)
🔴 HIGH G115 (CWE-190) internal/rpc/codec.go:117 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:246 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:256 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/graph_converter.go:30 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion uint64 -> int
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion int -> uint64
🟠 MEDIUM G304 (CWE-22) cmd/main.go:217 Potential file inclusion via variable
🟠 MEDIUM G302 (CWE-276) cmd/main.go:217 Expect file permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/election_filelock.go:38 Expect directory permissions to be 0750 or less
🟠 MEDIUM G302 (CWE-276) internal/coordinator/election_filelock.go:53 Expect file permissions to be 0600 or less
🟠 MEDIUM G304 (CWE-22) internal/coordinator/election_filelock.go:135 Potential file inclusion via variable
🟠 MEDIUM G306 (CWE-276) internal/coordinator/election_filelock.go:143 Expect WriteFile permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/store_memory.go:132 Expect directory permissions to be 0750 or less

…and 2 more. Full SARIF report on the repo's Security tab.

… --max-frame-size

--metrics-enabled and --metrics-addr bypassed the file → flag → validate
pipeline that every other operator setting uses, so they were CLI-only.
Now they layer on top of YAML the same way --http-listen and friends do.

- Add ObservabilityConfig (Enabled, MetricsAddr) to WireConfig.
- Wire the two flags through flagToKey; defaults live in DefaultConfig.
- Validate rejects enabled=true with empty metrics_addr.
- Drop --max-frame-size: declared but never read by any consumer.
- Six new tests cover YAML, CLI override, defaults, validation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

Found 27 issues (🔴 18 high · 🟠 9 medium · 🟡 0 low).

Findings
Severity Rule File:Line Message
🔴 HIGH G115 (CWE-190) internal/coordinator/scheduler.go:257 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/coordinator/store_pebble.go:76 integer overflow conversion int -> uint64
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:301 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:306 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:310 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:345 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:44 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:45 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion uint32 -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/protocol/frame.go:112 integer overflow conversion int -> uint32
🔴 HIGH G404 (CWE-338) internal/rpc/client.go:211 Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)
🔴 HIGH G115 (CWE-190) internal/rpc/codec.go:117 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:246 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:256 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/graph_converter.go:30 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion uint64 -> int
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion int -> uint64
🟠 MEDIUM G304 (CWE-22) cmd/main.go:217 Potential file inclusion via variable
🟠 MEDIUM G302 (CWE-276) cmd/main.go:217 Expect file permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/election_filelock.go:38 Expect directory permissions to be 0750 or less
🟠 MEDIUM G302 (CWE-276) internal/coordinator/election_filelock.go:53 Expect file permissions to be 0600 or less
🟠 MEDIUM G304 (CWE-22) internal/coordinator/election_filelock.go:135 Potential file inclusion via variable
🟠 MEDIUM G306 (CWE-276) internal/coordinator/election_filelock.go:143 Expect WriteFile permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/store_memory.go:132 Expect directory permissions to be 0750 or less

…and 2 more. Full SARIF report on the repo's Security tab.

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

Found 27 issues (🔴 18 high · 🟠 9 medium · 🟡 0 low).

Findings
Severity Rule File:Line Message
🔴 HIGH G115 (CWE-190) internal/coordinator/scheduler.go:257 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/coordinator/store_pebble.go:76 integer overflow conversion int -> uint64
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:301 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:306 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:310 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/engine/state_backend_hashmap.go:345 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:44 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/assignment.go:45 integer overflow conversion int -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion uint32 -> uint16
🔴 HIGH G115 (CWE-190) internal/keygroup/hasher.go:8 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/protocol/frame.go:112 integer overflow conversion int -> uint32
🔴 HIGH G404 (CWE-338) internal/rpc/client.go:211 Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)
🔴 HIGH G115 (CWE-190) internal/rpc/codec.go:117 integer overflow conversion int -> uint32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:246 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) internal/worker/worker.go:256 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/graph_converter.go:30 integer overflow conversion int -> int32
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion uint64 -> int
🔴 HIGH G115 (CWE-190) sdk/partition_router.go:39 integer overflow conversion int -> uint64
🟠 MEDIUM G304 (CWE-22) cmd/main.go:255 Potential file inclusion via variable
🟠 MEDIUM G302 (CWE-276) cmd/main.go:255 Expect file permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/election_filelock.go:38 Expect directory permissions to be 0750 or less
🟠 MEDIUM G302 (CWE-276) internal/coordinator/election_filelock.go:53 Expect file permissions to be 0600 or less
🟠 MEDIUM G304 (CWE-22) internal/coordinator/election_filelock.go:135 Potential file inclusion via variable
🟠 MEDIUM G306 (CWE-276) internal/coordinator/election_filelock.go:143 Expect WriteFile permissions to be 0600 or less
🟠 MEDIUM G301 (CWE-276) internal/coordinator/store_memory.go:132 Expect directory permissions to be 0750 or less

…and 2 more. Full SARIF report on the repo's Security tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants