Skip to content

Commit 44f5faa

Browse files
committed
Add loger, tally and renames and decouple the server from controllers
1 parent c4ceb4c commit 44f5faa

48 files changed

Lines changed: 847 additions & 554 deletions

Some content is hidden

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

.envrc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
GOPATH=$(pwd)
2-
export GOPATH
31
PATH_add tools
42

5-
6-
WORKSPACE_ROOT=$(pwd)
7-
export WORKSPACE_ROOT
3+
REPO_ROOT=$(pwd)
4+
export REPO_ROOT

.github/workflows/build_and_test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
- opened
1010
- reopened
1111
- synchronize
12-
- ready_for_review
1312

1413
jobs:
1514
build-and-test:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ MODULE.bazel.lock
55
.vscode/
66
.idea/
77
.claude/
8+
.ijwb/
89

910

1011
# Built binaries

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ go_deps.from_file(go_mod = "//:go.mod")
3737
use_repo(
3838
go_deps,
3939
"com_github_gogo_protobuf",
40+
"com_github_uber_go_tally_v4",
4041
"org_golang_google_grpc",
4142
"org_golang_google_protobuf",
4243
"org_uber_go_fx",
4344
"org_uber_go_yarpc",
45+
"org_uber_go_zap",
4446
)

Makefile

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,10 @@ proto:
2020
--proto_path=speculator/proto speculator/proto/speculator.proto
2121
@echo "Protobuf files generated successfully!"
2222

23-
# Build all services and examples using Bazel
23+
# Build everything in the project using Bazel
2424
build:
25-
@echo "Building all services with Bazel..."
26-
@$(BAZEL) build //gateway:gateway
27-
@$(BAZEL) build //orchestrator:orchestrator
28-
@$(BAZEL) build //speculator:speculator
29-
@echo "Building example servers and clients..."
30-
@$(BAZEL) build //examples/server/gateway:gateway
31-
@$(BAZEL) build //examples/server/orchestrator:orchestrator
32-
@$(BAZEL) build //examples/server/speculator:speculator
33-
@$(BAZEL) build //examples/client/gateway:gateway
34-
@$(BAZEL) build //examples/client/orchestrator:orchestrator
35-
@$(BAZEL) build //examples/client/speculator:speculator
25+
@echo "Building all targets with Bazel..."
26+
@$(BAZEL) build //...
3627
@echo "Copying binaries to ./bin/..."
3728
@mkdir -p bin
3829
@cp -f bazel-bin/examples/server/gateway/gateway_/gateway bin/gateway_server 2>/dev/null || \

README.md

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Submit Queue consists of three main services:
1111
## gRPC API
1212

1313
Each service has its own proto definitions and exposes its own gRPC API:
14-
- **GatewayService**: Gateway API with Ping method (port 8081)
15-
- **OrchestratorService**: Orchestrator API with Ping method (port 8082)
16-
- **SpeculatorService**: Speculator API with Ping method (port 8083)
14+
- **SubmitQueueGateway**: Gateway API with Ping method (port 8081)
15+
- **SubmitQueueOrchestrator**: Orchestrator API with Ping method (port 8082)
16+
- **SubmitQueueSpeculator**: Speculator API with Ping method (port 8083)
1717

1818
### Quick Start
1919

@@ -41,7 +41,7 @@ make run-client-gateway MESSAGE="hello"
4141
go run examples/client/gateway/main.go -message "hello"
4242

4343
# Or using grpcurl
44-
grpcurl -plaintext -d '{"message": "hello"}' localhost:8081 uber.devexp.submitqueue.gateway.GatewayService/Ping
44+
grpcurl -plaintext -d '{"message": "hello"}' localhost:8081 uber.devexp.submitqueue.gateway.SubmitQueueGateway/Ping
4545
```
4646

4747
For detailed instructions, see [examples/README.md](examples/README.md).
@@ -50,6 +50,23 @@ For detailed instructions, see [examples/README.md](examples/README.md).
5050

5151
See [docs/architecture/STRUCTURE.md](docs/architecture/STRUCTURE.md) for a detailed breakdown of the project structure.
5252

53+
## Architecture
54+
55+
The project follows clean architecture principles with clear separation of concerns:
56+
57+
- **Controllers** (`core/controller/`): Pure business logic, independent of transport layer
58+
- Only depend on logger, metrics, and protobuf types
59+
- Example: `PingController` handles ping business logic
60+
61+
- **Server Adapters** (`examples/server/`): gRPC transport layer
62+
- Wrap controllers and implement gRPC service interfaces
63+
- Handle protocol-specific concerns (e.g., `UnimplementedServiceServer`)
64+
65+
- **Observability**: Built-in logging and metrics
66+
- Structured logging with [Zap](https://github.com/uber-go/zap)
67+
- Metrics collection with [Tally](https://github.com/uber-go/tally)
68+
- Development servers use human-readable console logging
69+
5370
## Development
5471

5572
### Prerequisites
@@ -159,7 +176,6 @@ bazel build //...
159176

160177
# Build specific components
161178
bazel build //gateway/protopb
162-
bazel build //gateway:gateway
163179
bazel build //examples/server/gateway:gateway
164180
bazel build //examples/client/gateway:gateway
165181

@@ -226,7 +242,8 @@ message PingResponse {
226242
string message = 1;
227243
string service_name = 2;
228244
int64 timestamp = 3;
229-
string hostname = 4; // New field added
245+
string hostname = 4;
246+
string new_field = 5; // New field added
230247
}
231248
```
232249

@@ -240,8 +257,8 @@ make proto
240257
# - gateway/protopb/gateway_grpc.pb.go
241258
# - gateway/protopb/gateway.pb.yarpc.go
242259

243-
# Now update the service implementation
244-
# Edit gateway/core/controller/ping.go to populate the hostname field
260+
# Now update the controller implementation
261+
# Edit gateway/core/controller/ping.go to populate the new field in the PingResponse
245262
```
246263

247264
### Testing
@@ -261,7 +278,7 @@ make proto
261278
3. **Or use grpcurl:**
262279
```bash
263280
grpcurl -plaintext -d '{"message": "hello"}' \
264-
localhost:8081 uber.devexp.submitqueue.gateway.GatewayService/Ping
281+
localhost:8081 uber.devexp.submitqueue.gateway.SubmitQueueGateway/Ping
265282
```
266283

267284
#### Testing All Services
@@ -299,7 +316,7 @@ make test
299316
1. **Update the proto file:**
300317
```protobuf
301318
// In gateway/proto/gateway.proto
302-
service GatewayService {
319+
service SubmitQueueGateway {
303320
rpc Ping(PingRequest) returns (PingResponse) {}
304321
rpc NewMethod(NewRequest) returns (NewResponse) {} // Add new method
305322
}
@@ -313,17 +330,44 @@ make test
313330
make proto
314331
```
315332

316-
3. **Implement the method in the service:**
333+
3. **Implement the method in the controller:**
334+
```go
335+
// In gateway/core/controller/ (create a new controller file)
336+
type NewController struct {
337+
logger *zap.Logger
338+
metricsScope tally.Scope
339+
}
340+
341+
func NewNewController(logger *zap.Logger, scope tally.Scope) *NewController {
342+
if logger == nil {
343+
logger = zap.NewNop()
344+
}
345+
if scope == nil {
346+
scope = tally.NoopScope
347+
}
348+
return &NewController{logger: logger, metricsScope: scope}
349+
}
350+
351+
func (c *NewController) NewMethod(ctx context.Context, req *pb.NewRequest) (*pb.NewResponse, error) {
352+
// Business logic here
353+
c.logger.Info("new method called")
354+
c.metricsScope.Counter("new_method_total").Inc(1)
355+
// ...
356+
}
357+
```
358+
359+
4. **Create server wrapper in example:**
317360
```go
318-
// In gateway/core/controller/ping.go (or create a new file)
319-
func (s *PingServiceImpl) NewMethod(ctx context.Context, req *pb.NewRequest) (*pb.NewResponse, error) {
320-
// Implementation here
361+
// In examples/server/gateway/main.go
362+
// Add method delegation to GatewayServer struct:
363+
func (s *GatewayServer) NewMethod(ctx context.Context, req *pb.NewRequest) (*pb.NewResponse, error) {
364+
return s.newController.NewMethod(ctx, req)
321365
}
322366
```
323367

324-
4. **Update clients to call the new method**
368+
5. **Update clients to call the new method**
325369

326-
5. **Rebuild and test:**
370+
6. **Rebuild and test:**
327371
```bash
328372
make build
329373
```

examples/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This directory contains example gRPC servers and clients for each service in the
66

77
Each service has its own proto definitions and gRPC API:
88

9-
- **Gateway**: GatewayService API (port 8081)
10-
- **Orchestrator**: OrchestratorService API (port 8082)
11-
- **Speculator**: SpeculatorService API (port 8083)
9+
- **SubmitQueueGateway**: Gateway API (port 8081)
10+
- **SubmitQueueOrchestrator**: Orchestrator API (port 8082)
11+
- **SubmitQueueSpeculator**: Speculator API (port 8083)
1212

1313
## Building and Running
1414

@@ -141,13 +141,13 @@ go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
141141
Test the ping service:
142142
```bash
143143
# Test gateway (port 8081)
144-
grpcurl -plaintext -d '{"message": "hello"}' localhost:8081 uber.devexp.submitqueue.gateway.GatewayService/Ping
144+
grpcurl -plaintext -d '{"message": "hello"}' localhost:8081 uber.devexp.submitqueue.gateway.SubmitQueueGateway/Ping
145145

146146
# Test orchestrator (port 8082)
147-
grpcurl -plaintext -d '{"message": "hello"}' localhost:8082 uber.devexp.submitqueue.orchestrator.OrchestratorService/Ping
147+
grpcurl -plaintext -d '{"message": "hello"}' localhost:8082 uber.devexp.submitqueue.orchestrator.SubmitQueueOrchestrator/Ping
148148

149149
# Test speculator (port 8083)
150-
grpcurl -plaintext -d '{"message": "hello"}' localhost:8083 uber.devexp.submitqueue.speculator.SpeculatorService/Ping
150+
grpcurl -plaintext -d '{"message": "hello"}' localhost:8083 uber.devexp.submitqueue.speculator.SubmitQueueSpeculator/Ping
151151
```
152152

153153
List available services:
@@ -159,9 +159,9 @@ grpcurl -plaintext localhost:8083 list
159159

160160
Describe a service:
161161
```bash
162-
grpcurl -plaintext localhost:8081 describe uber.devexp.submitqueue.gateway.GatewayService
163-
grpcurl -plaintext localhost:8082 describe uber.devexp.submitqueue.orchestrator.OrchestratorService
164-
grpcurl -plaintext localhost:8083 describe uber.devexp.submitqueue.speculator.SpeculatorService
162+
grpcurl -plaintext localhost:8081 describe uber.devexp.submitqueue.gateway.SubmitQueueGateway
163+
grpcurl -plaintext localhost:8082 describe uber.devexp.submitqueue.orchestrator.SubmitQueueOrchestrator
164+
grpcurl -plaintext localhost:8083 describe uber.devexp.submitqueue.speculator.SubmitQueueSpeculator
165165
```
166166

167167
## API Reference
@@ -172,17 +172,17 @@ Each service exposes a Ping method with the same request/response structure but
172172

173173
#### Gateway Service
174174

175-
**Service**: `uber.devexp.submitqueue.gateway.GatewayService`
175+
**Service**: `uber.devexp.submitqueue.gateway.SubmitQueueGateway`
176176
**Proto**: `gateway/proto/gateway.proto`
177177

178178
#### Orchestrator Service
179179

180-
**Service**: `uber.devexp.submitqueue.orchestrator.OrchestratorService`
180+
**Service**: `uber.devexp.submitqueue.orchestrator.SubmitQueueOrchestrator`
181181
**Proto**: `orchestrator/proto/orchestrator.proto`
182182

183183
#### Speculator Service
184184

185-
**Service**: `uber.devexp.submitqueue.speculator.SpeculatorService`
185+
**Service**: `uber.devexp.submitqueue.speculator.SubmitQueueSpeculator`
186186
**Proto**: `speculator/proto/speculator.proto`
187187

188188
### Ping Method
@@ -205,7 +205,7 @@ message PingResponse {
205205

206206
**Example:**
207207
```bash
208-
grpcurl -plaintext -d '{"message": "test"}' localhost:8081 uber.devexp.submitqueue.gateway.GatewayService/Ping
208+
grpcurl -plaintext -d '{"message": "test"}' localhost:8081 uber.devexp.submitqueue.gateway.SubmitQueueGateway/Ping
209209
```
210210

211211
Expected response:
@@ -249,7 +249,7 @@ import (
249249

250250
// Use the clients
251251
conn, _ := grpc.NewClient("localhost:8081", grpc.WithTransportCredentials(insecure.NewCredentials()))
252-
client := gatewaypb.NewGatewayServiceClient(conn)
252+
client := gatewaypb.NewSubmitQueueGatewayClient(conn)
253253
resp, _ := client.Ping(context.Background(), &gatewaypb.PingRequest{Message: "hello"})
254254
```
255255

examples/client/gateway/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func run(addr, message string, timeout time.Duration) error {
3636
defer conn.Close()
3737

3838
// Create a client
39-
client := pb.NewGatewayServiceClient(conn)
39+
client := pb.NewSubmitQueueGatewayClient(conn)
4040

4141
// Create context with timeout
4242
ctx, cancel := context.WithTimeout(context.Background(), timeout)

examples/client/orchestrator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func run(addr, message string, timeout time.Duration) error {
3636
defer conn.Close()
3737

3838
// Create a client
39-
client := pb.NewOrchestratorServiceClient(conn)
39+
client := pb.NewSubmitQueueOrchestratorClient(conn)
4040

4141
// Create context with timeout
4242
ctx, cancel := context.WithTimeout(context.Background(), timeout)

examples/client/speculator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func run(addr, message string, timeout time.Duration) error {
3636
defer conn.Close()
3737

3838
// Create a client
39-
client := pb.NewSpeculatorServiceClient(conn)
39+
client := pb.NewSubmitQueueSpeculatorClient(conn)
4040

4141
// Create context with timeout
4242
ctx, cancel := context.WithTimeout(context.Background(), timeout)

0 commit comments

Comments
 (0)