|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +cc-lib is a shared Go library (`github.com/ClusterCockpit/cc-lib/v2`) for the ClusterCockpit HPC monitoring ecosystem. It provides reusable packages for metric collection, data processing, storage, configuration, and system integration. It is a library only — there is no main binary. |
| 8 | + |
| 9 | +Used by: cc-metric-collector, cc-metric-store, and ClusterCockpit web interface. |
| 10 | + |
| 11 | +## Build & Test Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +go build ./... # Build all packages |
| 15 | +go test ./... # Run all tests |
| 16 | +go test -v ./ccMessage # Test specific package |
| 17 | +go test -v ./ccMessage -run TestJSONEncode # Run single test |
| 18 | +go test -cover ./... # Tests with coverage |
| 19 | +``` |
| 20 | + |
| 21 | +No Makefile or special build tools. The `ccTopology` package requires hwloc C library (`sudo apt install hwloc`). |
| 22 | + |
| 23 | +## Code Style Requirements |
| 24 | + |
| 25 | +**Copyright header required on every Go file:** |
| 26 | +```go |
| 27 | +// Copyright (C) NHR@FAU, University Erlangen-Nuremberg. |
| 28 | +// All rights reserved. This file is part of cc-lib. |
| 29 | +// Use of this source code is governed by a MIT-style |
| 30 | +// license that can be found in the LICENSE file. |
| 31 | +``` |
| 32 | + |
| 33 | +**Import aliases used throughout the codebase:** |
| 34 | +```go |
| 35 | +cclog "github.com/ClusterCockpit/cc-lib/v2/ccLogger" |
| 36 | +lp "github.com/ClusterCockpit/cc-lib/v2/ccMessage" |
| 37 | +mp "github.com/ClusterCockpit/cc-lib/v2/messageProcessor" |
| 38 | +``` |
| 39 | + |
| 40 | +**Formatting:** Code must be formatted with `gofumpt` (a stricter `gofmt`). |
| 41 | + |
| 42 | +**Import grouping:** stdlib first, then third-party separated by blank line. |
| 43 | + |
| 44 | +**Naming:** PascalCase exported, camelCase unexported. Avoid stuttering (`cache.New()` not `cache.NewCache()`). |
| 45 | + |
| 46 | +**Testing:** Name tests `Test<FunctionName>_<Scenario>`. Use table-driven tests. Every package needs a package-level doc comment (linter enforced). |
| 47 | + |
| 48 | +## Architecture |
| 49 | + |
| 50 | +### Data Flow Pipeline |
| 51 | + |
| 52 | +``` |
| 53 | +Receivers → CCMessage (chan) → MessageProcessor → Sinks |
| 54 | +``` |
| 55 | + |
| 56 | +- **Receivers** collect metrics from sources (IPMI, Redfish, Prometheus, NATS, HTTP, EECPT) |
| 57 | +- **CCMessage** is the internal message format extending InfluxDB line protocol with 5 types: Metric, Event, Log, Control, Query |
| 58 | +- **MessageProcessor** transforms messages using expr-lang expressions (drop, rename, tag/meta manipulation) |
| 59 | +- **Sinks** output to destinations (InfluxDB, NATS, Prometheus, HTTP, stdout, Ganglia) |
| 60 | + |
| 61 | +Both receivers and sinks use a Manager pattern (`ReceiveManager`/`SinkManager`) for lifecycle and configuration. |
| 62 | + |
| 63 | +### Key Package Dependencies |
| 64 | + |
| 65 | +**Foundation layer** (used by most other packages): |
| 66 | +- `schema` — Core types: Job, Cluster, SubCluster, MetricConfig, Float (NaN-aware JSON), User |
| 67 | +- `ccMessage` — Message interface and concrete types |
| 68 | +- `ccLogger` — Logging (thread-safe) |
| 69 | +- `ccConfig` — JSON configuration with file references and hot-reload |
| 70 | +- `ccUnits` — Unit prefix/measure system with conversion |
| 71 | + |
| 72 | +**Processing layer:** |
| 73 | +- `messageProcessor` — Expression-based message transformation pipeline (uses expr-lang) |
| 74 | +- `resampler` — Time-series downsampling (SimpleResampler and LTTB algorithm) |
| 75 | +- `lrucache` — Thread-safe LRU cache with TTL and HTTP middleware |
| 76 | + |
| 77 | +**System integration:** |
| 78 | +- `ccTopology` — Hardware topology via hwloc C bindings (cgo) |
| 79 | +- `runtime` — .env loading, privilege dropping, systemd integration |
| 80 | +- `nats` — Singleton NATS client wrapper |
| 81 | +- `hostlist` — HPC hostlist expansion (e.g., `node[1-10]`) |
| 82 | + |
| 83 | +### Notable Types |
| 84 | + |
| 85 | +- `schema.Float` — Custom float64 that marshals NaN as JSON `null`; used extensively for metric data with missing values |
| 86 | +- `schema.Job` — Central job representation with 20+ fields for HPC job metadata |
| 87 | +- `schema.Cluster` / `schema.SubCluster` — Hardware configuration with topology and metric configs |
| 88 | +- `ccMessage.CCMessage` — Interface with Name, Tags, Meta, Fields, Time, MessageType |
| 89 | + |
| 90 | +### Thread Safety |
| 91 | + |
| 92 | +- `ccLogger`, `lrucache`, `messageProcessor`, `nats.Client` are thread-safe |
| 93 | +- `CCMessage` is NOT thread-safe — use `FromMessage()` to copy |
| 94 | + |
| 95 | +### CI |
| 96 | + |
| 97 | +Each package has its own GitHub Actions workflow in `.github/workflows/`. Tests run on ubuntu-latest with Go 1.23+. |
0 commit comments