Skip to content

Commit 6413472

Browse files
committed
Add very alpha for signals schema and description
1 parent c014522 commit 6413472

14 files changed

+2583
-0
lines changed

signals/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.PHONY: generate test clean
2+
3+
generate:
4+
cd ./schema && cue exp gengotypes && mv cue_types_gen.go ../gen/go/cue_types_gen.go
5+
6+
# Optional: add a clean target to remove generated files
7+
clean:
8+
rm -f ./gen/go/gen/cue_types_gen.go
9+
10+
test:
11+
@echo "Running CUE validation tests..."
12+
@echo "Testing valid files (should pass):"
13+
@for file in ./schema/tests/test_*_ok.json; do \
14+
if [ -f "$$file" ]; then \
15+
echo " Testing $$file (should pass)"; \
16+
if cue vet ./schema/*.cue "$$file"; then \
17+
echo " ✓ PASS: $$file"; \
18+
else \
19+
echo " ✗ FAIL: $$file (expected to pass)"; \
20+
exit 1; \
21+
fi; \
22+
fi; \
23+
done
24+
@echo "Testing invalid files (should fail):"
25+
@for file in ./schema/tests/test_*_bad.json; do \
26+
if [ -f "$$file" ]; then \
27+
echo " Testing $$file (should fail)"; \
28+
if cue vet ./schema/*.cue "$$file" 2>/dev/null; then \
29+
echo " ✗ FAIL: $$file (expected to fail but passed)"; \
30+
exit 1; \
31+
else \
32+
echo " ✓ PASS: $$file (correctly failed validation)"; \
33+
fi; \
34+
fi; \
35+
done
36+
@echo "All tests completed successfully!"

signals/README.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Signals Framework
2+
3+
A language-agnostic framework for defining, processing, and visualizing observability signals across multiple data sources and dashboard systems.
4+
5+
## Overview
6+
7+
The signals framework provides a standardized way to define observability metrics (signals) that can be processed into dashboard visualizations. It supports multiple data sources (Prometheus, Loki, OTEL) and can generate dashboards for various visualization systems.
8+
9+
## Language-Agnostic Interface Specifications
10+
11+
To ensure consistent implementation across all target languages, the framework provides formal interface specifications:
12+
13+
### 1. Method Interface Specification (`signal_methods.md`)
14+
15+
Defines the exact methods that must be implemented for the Signal class/object in every language:
16+
17+
- **Builder Methods**: `withTopK()`, `withExprWrappersMixin()`, `withOffset()`, etc.
18+
- **Panel Rendering**: `asTimeSeries()`, `asStat()`, `asGauge()`, `asTable()`, etc.
19+
- **Panel Composition**: `asPanelMixin()`, `asTarget()`, `asTableColumn()`, etc.
20+
- **Expression Generation**: `asPanelExpression()`, `asRuleExpression()`
21+
- **Utilities**: `getVariablesMultiChoice()`
22+
23+
### 2. OpenAPI Interface (`signal_interface.yaml`)
24+
25+
REST API specification that can be used to:
26+
- Generate client stubs for each language
27+
- Validate method signatures and data structures
28+
- Ensure consistent input/output contracts
29+
30+
### 3. Core Schema (`signal.cue`, `signal_source.cue`)
31+
32+
CUE schema definitions that provide:
33+
- Type-safe signal and signal group definitions
34+
- Validation rules for all signal properties
35+
- Data structure contracts for cross-language compatibility
36+
37+
## Implementation Strategy
38+
39+
### Language-Specific Implementation
40+
41+
Each target language must implement the Signal interface following these guidelines:
42+
43+
**Jsonnet** (Reference Implementation)
44+
```jsonnet
45+
local signals = signal.init(config);
46+
signals.mySignal.withTopK(10).asTimeSeries()
47+
```
48+
49+
**TypeScript**
50+
```typescript
51+
const signal = new Signal(config);
52+
signal.withTopK(10).asTimeSeries();
53+
```
54+
55+
**Python**
56+
```python
57+
signal = Signal(config)
58+
signal.with_top_k(10).as_time_series()
59+
```
60+
61+
**Go**
62+
```go
63+
panel := signal.WithTopK(10).AsTimeSeries()
64+
```
65+
66+
### Consistency Requirements
67+
68+
All implementations must:
69+
70+
1. **Method Signatures**: Match the interface specification exactly
71+
2. **Expression Transformation**: Follow the same auto-transformation rules
72+
3. **Template Expansion**: Support identical variable templates
73+
4. **Panel Structure**: Generate compatible Grafana panel objects
74+
5. **Testing**: Include comprehensive test suites
75+
76+
## Core Functions
77+
78+
The framework implements these core functions consistently across languages:
79+
80+
### 1. Signal Definition & Validation
81+
```
82+
Input: Signal configuration (JSON/YAML/Code)
83+
Output: Validated Signal object with transformation rules
84+
```
85+
86+
### 2. Expression Processing
87+
```
88+
Input: Signal + context (datasource, aggregation level)
89+
Output: PromQL/LogQL expressions with auto-transformations
90+
```
91+
92+
### 3. Panel Generation
93+
```
94+
Input: Signal + panel type
95+
Output: Complete Grafana panel configuration
96+
```
97+
98+
### 4. Dashboard Assembly
99+
```
100+
Input: Signal collection + metadata
101+
Output: Complete dashboard with panels and variables
102+
```
103+
104+
## Expression Transformation Rules
105+
106+
All implementations follow these automatic transformations:
107+
108+
- **Counter**: `rate(metric[interval])` or similar range functions
109+
- **Histogram**: `histogram_quantile(0.95, rate(metric[interval])) by (le)`
110+
- **Gauge/Info/Raw**: No transformation
111+
- **Aggregation**: `sum by (labels) (expression)` when aggregation is enabled
112+
113+
## Supported Languages
114+
115+
-**Jsonnet** - Reference implementation (common-lib)
116+
- 🔄 **TypeScript** - Web/Node.js environments
117+
- 🔄 **Python** - Data science and automation
118+
- 🔄 **Go** - Performance-critical applications
119+
120+
## Schema Definitions
121+
122+
- **`signal.cue`** - Core signal and signal group schema with validation
123+
- **`signal_source.cue`** - Data source-specific configuration schema
124+
- **`signal_interface.yaml`** - OpenAPI specification for method contracts
125+
- **`signal_methods.md`** - Detailed method interface documentation
126+
127+
## Getting Started
128+
129+
### 1. Define Signals
130+
Create signal definitions using the CUE schema:
131+
```jsonnet
132+
{
133+
name: "CPU Usage",
134+
type: "gauge",
135+
unit: "percent",
136+
sources: {
137+
prometheus: {
138+
expr: "100 - avg(rate(cpu_idle[5m])) * 100"
139+
}
140+
}
141+
}
142+
```
143+
144+
### 2. Validate Definitions
145+
```bash
146+
make test # Validates against CUE schema
147+
```
148+
149+
### 3. Implement Language Bindings
150+
Use the interface specifications to implement Signal classes in your target language:
151+
152+
- Follow `signal_methods.md` for method signatures
153+
- Use `signal_interface.yaml` for code generation
154+
- Implement expression transformation rules
155+
- Add comprehensive tests
156+
157+
### 4. Generate Dashboards
158+
```typescript
159+
const signal = new Signal(config);
160+
const dashboard = new Dashboard()
161+
.addPanel(signal.asTimeSeries())
162+
.addVariables(Signal.getVariablesMultiChoice([signal]));
163+
```
164+
165+
## File Structure
166+
167+
```
168+
signals/
169+
├── schema/
170+
│ ├── signal.cue # Core schema definitions
171+
│ ├── signal_source.cue # Source-specific schema
172+
│ ├── signal_interface.yaml # OpenAPI method contracts
173+
│ ├── signal_methods.md # Method interface spec
174+
│ └── tests/ # Validation test files
175+
├── gen/ # Generated code output
176+
├── architecture.md # Architecture documentation
177+
├── requirements.md # Functional requirements
178+
└── README.md # This file
179+
```
180+
181+
## Development Workflow
182+
183+
1. **Schema First**: Define/modify schemas in CUE files
184+
2. **Validate**: Ensure test files pass validation
185+
3. **Interface**: Update method specifications if needed
186+
4. **Implement**: Code language-specific implementations
187+
5. **Test**: Verify cross-language compatibility
188+
6. **Generate**: Use for dashboard/alert generation
189+
190+
This approach ensures that regardless of the implementation language, all Signal objects behave consistently and generate compatible dashboard outputs.

0 commit comments

Comments
 (0)