Skip to content

Commit d9af119

Browse files
authored
Merge pull request #20 from MB3R-Lab/feat/runtime-discovery-service
Update dependencies to Go 1.24, add support for snapshot envelopes, a…
2 parents a8a98a1 + ea04f5c commit d9af119

45 files changed

Lines changed: 5158 additions & 192 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
api/schema/*.json text eol=lf
2+
internal/schema/schema/*.json text eol=lf

README.md

Lines changed: 131 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,70 @@
11
# Bering
22

3-
Bering builds a resilience model artifact from trace artifacts. The output artifact is `bering-model.json` in `BeringResilienceModel` v1.0.0 format. Use it in any downstream tooling or analytics pipeline.
3+
Bering is a discovery and publishing layer for service topology and endpoint contracts.
44

5-
## Contract
5+
It supports two operating modes:
66

7-
Bering pins `metadata.schema` exactly:
7+
- deterministic batch discovery from trace files and directories
8+
- long-running runtime discovery that accepts OTLP/HTTP spans and publishes rolling snapshot envelopes for observability consumers
9+
10+
Bering owns discovery and discovery-side public contracts. It does not own simulation, gating, chaos execution, or policy decisions.
11+
12+
## Public Artifacts
13+
14+
Bering currently publishes two versioned JSON artifact types.
15+
16+
### Core model
817

918
- `name`: `io.mb3r.bering.model`
1019
- `version`: `1.0.0`
1120
- `uri`: `https://mb3r-lab.github.io/Bering/schema/model/v1.0.0/model.schema.json`
1221
- `digest`: `sha256:272277c093f37580adcd2dded225bd37c86539d642d7910baad7e4228227d1a7`
1322

14-
Any mismatch fails validation.
23+
This remains the simple stable topology artifact for file-based users and downstream tools such as Sheaft.
24+
25+
### Snapshot envelope
26+
27+
- `name`: `io.mb3r.bering.snapshot`
28+
- `version`: `1.0.0`
29+
- `uri`: `https://mb3r-lab.github.io/Bering/schema/snapshot/v1.0.0/snapshot.schema.json`
30+
- `digest`: `sha256:87e4e887ed4a37b72f6136e268b73552eccb92941c4de2c6f3a514dd066ea972`
31+
32+
This wraps the core model with runtime window metadata, ingest counts, support summaries, provenance, and topology diffs.
33+
34+
`bering validate` accepts either artifact type.
1535

1636
## Repository layout
1737

1838
```text
1939
cmd/bering CLI entrypoint
2040
internal/app command wiring
21-
internal/connectors/traces trace file/dir loading and normalization
22-
internal/discovery model inference from normalized spans
23-
internal/model model structs, semantic checks, canonical IO
41+
internal/config serve-mode config parsing and validation
42+
internal/connectors/traces file/dir trace loading and normalization
43+
internal/connectors/otlp OTLP/HTTP request decoding into normalized spans
44+
internal/discovery source-agnostic discovery engine and overlay application
45+
internal/model stable core model structs, semantic checks, canonical IO
46+
internal/overlay generic discovery overlay loader
47+
internal/runtime long-running service, tumbling windows, sinks, metrics
2448
internal/schema pinned contract constants + JSON Schema validation
25-
internal/jsoncanon deterministic recursive JSON encoder
26-
api/schema versioned public schema
27-
configs sample configs (replicas override)
28-
examples trace fixtures + expected output artifacts
29-
docs format, heuristic, and MVP limits
49+
internal/snapshot snapshot envelope structs, diffing, canonical IO
50+
api/schema public schemas published via GitHub Pages
51+
configs sample serve and overlay configs
52+
examples traces, outputs, collector/prometheus/grafana examples
53+
docs architecture, contract, config, migration, limits
3054
scripts/ci CI helper scripts
3155
```
3256

3357
## Commands
3458

3559
```bash
36-
bering discover --input <trace-file|dir> [--out bering-model.json] [--replicas replicas.yaml|json] [--discovered-at RFC3339]
37-
bering validate --input <bering-model.json>
60+
bering discover --input <trace-file|dir> [--out bering-model.json] [--snapshot-out bering-snapshot.json] [--replicas replicas.yaml|json] [--overlay overlay.yaml] [--discovered-at RFC3339]
61+
bering validate --input <bering-model.json|bering-snapshot.json>
62+
bering serve --config configs/serve.sample.yaml [--listen :4318] [--window-size 30s] [--flush-interval 5s]
3863
```
3964

4065
## Quickstart
4166

42-
### 1) Discover from traces
67+
### 1) Batch discovery from traces
4368

4469
```bash
4570
go run ./cmd/bering discover \
@@ -48,59 +73,119 @@ go run ./cmd/bering discover \
4873
--discovered-at 2026-03-03T00:00:00Z
4974
```
5075

51-
### 2) Validate artifact
76+
### 2) Validate the model artifact
5277

5378
```bash
5479
go run ./cmd/bering validate \
5580
--input examples/outputs/bering-model.normalized.sample.json
5681
```
5782

58-
### 3) Use the model in any downstream tool
83+
### 3) Generate a snapshot envelope in batch mode
5984

60-
Examples:
85+
```bash
86+
go run ./cmd/bering discover \
87+
--input examples/traces/normalized.sample.json \
88+
--out out/bering-model.json \
89+
--snapshot-out examples/outputs/bering-snapshot.normalized.sample.json \
90+
--overlay configs/discovery.overlay.sample.yaml \
91+
--discovered-at 2026-03-03T00:00:00Z
92+
```
6193

62-
- run your own analytics (topology checks, risk scoring, SLO diagnostics)
63-
- feed the model into simulation tooling
64-
- simulate failures with [Sheaft](https://github.com/MB3R-Lab/Sheaft) (one possible consumer), for example:
65-
```bash
66-
# from sibling Sheaft repository
67-
go run ./cmd/sheaft run \
68-
--model ../Bering/examples/outputs/bering-model.normalized.sample.json \
69-
--policy configs/gate.policy.example.yaml \
70-
--out-dir out \
71-
--seed 42
72-
```
94+
### 4) Run the runtime service
7395

74-
## Deterministic output
96+
```bash
97+
go run ./cmd/bering serve --config configs/serve.sample.yaml
98+
```
7599

76-
Bering output is deterministic for identical inputs and flags:
100+
The runtime service exposes:
101+
102+
- `POST /v1/traces` for OTLP/HTTP trace ingest
103+
- `GET /healthz`
104+
- `GET /readyz`
105+
- `GET /metrics`
106+
107+
The primary integration path is standard OpenTelemetry Collector or SDK exporters sending spans to Bering over OTLP/HTTP. No custom Collector build is required.
108+
109+
### 5) Use the stable model with Sheaft
110+
111+
```bash
112+
# from a sibling Sheaft repository
113+
go run ./cmd/sheaft run \
114+
--model ../Bering/examples/outputs/bering-model.normalized.sample.json \
115+
--policy configs/gate.policy.example.yaml \
116+
--out-dir out \
117+
--seed 42
118+
```
119+
120+
## Examples
121+
122+
- Batch inputs: [examples/traces/normalized.sample.json](examples/traces/normalized.sample.json), [examples/traces/otel.sample.json](examples/traces/otel.sample.json)
123+
- Batch outputs: [examples/outputs/bering-model.normalized.sample.json](examples/outputs/bering-model.normalized.sample.json), [examples/outputs/bering-snapshot.normalized.sample.json](examples/outputs/bering-snapshot.normalized.sample.json)
124+
- Runtime config: [configs/serve.sample.yaml](configs/serve.sample.yaml)
125+
- Discovery overlay: [configs/discovery.overlay.sample.yaml](configs/discovery.overlay.sample.yaml)
126+
- Collector sidecar: [examples/collector/otelcol.sidecar.yaml](examples/collector/otelcol.sidecar.yaml)
127+
- Prometheus scrape config: [examples/prometheus/bering.prometheus.yml](examples/prometheus/bering.prometheus.yml)
128+
- Grafana dashboard: [examples/grafana/bering-runtime-dashboard.json](examples/grafana/bering-runtime-dashboard.json)
129+
130+
## Determinism and Runtime Tradeoffs
131+
132+
Batch output remains deterministic for identical inputs and flags:
77133

78134
- services sorted by `id`
79135
- edges sorted by `(from,to,kind,blocking)`
80136
- endpoints sorted by `id`
81-
- stable IDs for services/edges/endpoints
82-
- canonical JSON writer with recursive object-key ordering (future-safe for map fields)
137+
- canonical JSON output with stable object-key ordering
83138
- optional `--discovered-at` for reproducible timestamps
84139

85-
## Supported trace formats (MVP)
140+
Runtime mode is intentionally bounded, not lossless:
141+
142+
- one active tumbling window is retained in memory
143+
- the previous emitted snapshot is retained for diffs and carry-forward runtime timestamps
144+
- `runtime.max_in_memory_spans` bounds retained spans per active window
145+
- late spans follow `drop` or `current_window` policy
146+
- spans beyond the configured in-memory cap are dropped and surfaced via metrics/logs
147+
- empty windows are advanced without emitting empty snapshots
148+
149+
## Discovery overlays
150+
151+
Discovery overlays are additive metadata inputs with explicit precedence by file order. They are intended for discovery-side enrichment, not policy evaluation.
152+
153+
Supported examples include:
154+
155+
- service labels and failure-eligibility labels
156+
- endpoint predicate references
157+
- workload or endpoint weights
158+
- SLO references or tags
159+
- replica overrides
86160

87-
- Normalized JSON: `{"spans": [...]}` payload with canonical span fields.
88-
- Raw OTel JSON: `resourceSpans/scopeSpans/spans` payload.
161+
See [configs/discovery.overlay.sample.yaml](configs/discovery.overlay.sample.yaml).
89162

90-
Details: [docs/trace-input-format.md](docs/trace-input-format.md)
163+
## Metrics
91164

92-
## Schema publishing
165+
The runtime service exports Prometheus/OpenMetrics metrics including:
93166

94-
Schema publishing is automated via GitHub Pages and release tags.
167+
- `spans_ingested_total`
168+
- `spans_dropped_total`
169+
- `snapshots_emitted_total`
170+
- `snapshot_build_duration_seconds`
171+
- `current_services`
172+
- `current_edges`
173+
- `current_endpoints`
174+
- `window_lag_seconds`
175+
- `last_snapshot_unixtime`
176+
- `snapshot_age_seconds`
177+
- `diff_added_*`
178+
- `diff_removed_*`
179+
- `diff_changed_*`
95180

96-
- Workflow: `.github/workflows/publish-schema.yml`
97-
- Trigger: tags matching `schema-v*` (for example `schema-v1.0.0`)
98-
- Published paths:
99-
- `https://mb3r-lab.github.io/Bering/schema/model/v1.0.0/model.schema.json`
100-
- `https://mb3r-lab.github.io/Bering/schema/model/latest/model.schema.json`
101-
- `https://mb3r-lab.github.io/Bering/schema/index.json`
181+
## Additional docs
102182

103-
Operational steps are documented in [docs/schema-publishing.md](docs/schema-publishing.md).
183+
- [docs/architecture.md](docs/architecture.md)
184+
- [docs/runtime-config.md](docs/runtime-config.md)
185+
- [docs/trace-input-format.md](docs/trace-input-format.md)
186+
- [docs/schema-publishing.md](docs/schema-publishing.md)
187+
- [docs/migration-notes.md](docs/migration-notes.md)
188+
- [docs/mvp-scope-and-limits.md](docs/mvp-scope-and-limits.md)
104189

105190
## CI and local checks
106191

0 commit comments

Comments
 (0)