OLD | NEW |
1 package traceservice | 1 package traceservice |
2 | 2 |
3 // Generate the go code from the protocol buffer definitions. | 3 // Generate the go code from the protocol buffer definitions. |
4 //go:generate protoc --go_out=plugins=grpc:. traceservice.proto | 4 //go:generate protoc --go_out=plugins=grpc:. traceservice.proto |
5 | 5 |
6 import ( | 6 import ( |
7 "bytes" | 7 "bytes" |
8 "encoding/binary" | 8 "encoding/binary" |
9 "fmt" | 9 "fmt" |
10 "strings" | 10 "strings" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 293 } |
294 } | 294 } |
295 return nil | 295 return nil |
296 } | 296 } |
297 if err := ts.db.View(get); err != nil { | 297 if err := ts.db.View(get); err != nil { |
298 return nil, fmt.Errorf("Failed to add values to tracedb: %s", er
r) | 298 return nil, fmt.Errorf("Failed to add values to tracedb: %s", er
r) |
299 } | 299 } |
300 return resp, nil | 300 return resp, nil |
301 } | 301 } |
302 | 302 |
303 func (ts *TraceServiceImpl) AddParams(ctx context.Context, in *AddParamsRequest)
(*EmptyResponse, error) { | 303 func (ts *TraceServiceImpl) AddParams(ctx context.Context, in *AddParamsRequest)
(*Empty, error) { |
304 // Serialize the Params for each trace as a proto and collect the tracei
ds. | 304 // Serialize the Params for each trace as a proto and collect the tracei
ds. |
305 // We do this outside the add func so there's less work taking place in
the | 305 // We do this outside the add func so there's less work taking place in
the |
306 // Update transaction. | 306 // Update transaction. |
307 params := map[string][]byte{} | 307 params := map[string][]byte{} |
308 var err error | 308 var err error |
309 for key, value := range in.Params { | 309 for key, value := range in.Params { |
310 ti := &StoredEntry{ | 310 ti := &StoredEntry{ |
311 Params: value, | 311 Params: value, |
312 } | 312 } |
313 params[key], err = proto.Marshal(ti) | 313 params[key], err = proto.Marshal(ti) |
314 if err != nil { | 314 if err != nil { |
315 return nil, fmt.Errorf("Failed to serialize the Params:
%s", err) | 315 return nil, fmt.Errorf("Failed to serialize the Params:
%s", err) |
316 } | 316 } |
317 } | 317 } |
318 | 318 |
319 // Add the Params for each traceid to the bucket. | 319 // Add the Params for each traceid to the bucket. |
320 add := func(tx *bolt.Tx) error { | 320 add := func(tx *bolt.Tx) error { |
321 t := tx.Bucket([]byte(TRACE_BUCKET_NAME)) | 321 t := tx.Bucket([]byte(TRACE_BUCKET_NAME)) |
322 for traceid, _ := range in.Params { | 322 for traceid, _ := range in.Params { |
323 if err := t.Put([]byte(traceid), params[traceid]); err !
= nil { | 323 if err := t.Put([]byte(traceid), params[traceid]); err !
= nil { |
324 return fmt.Errorf("Failed to write the trace inf
o for %s: %s", traceid, err) | 324 return fmt.Errorf("Failed to write the trace inf
o for %s: %s", traceid, err) |
325 } | 325 } |
326 } | 326 } |
327 return nil | 327 return nil |
328 } | 328 } |
329 if err := ts.db.Update(add); err != nil { | 329 if err := ts.db.Update(add); err != nil { |
330 return nil, fmt.Errorf("Failed to add values to tracedb: %s", er
r) | 330 return nil, fmt.Errorf("Failed to add values to tracedb: %s", er
r) |
331 } | 331 } |
332 » return &EmptyResponse{}, nil | 332 » return &Empty{}, nil |
333 } | 333 } |
334 | 334 |
335 func (ts *TraceServiceImpl) Add(ctx context.Context, in *AddRequest) (*EmptyResp
onse, error) { | 335 func (ts *TraceServiceImpl) Add(ctx context.Context, in *AddRequest) (*Empty, er
ror) { |
336 glog.Info("Add() begin.") | 336 glog.Info("Add() begin.") |
337 if in == nil { | 337 if in == nil { |
338 return nil, fmt.Errorf("Received nil request.") | 338 return nil, fmt.Errorf("Received nil request.") |
339 } | 339 } |
340 if in.Commitid == nil { | 340 if in.Commitid == nil { |
341 return nil, fmt.Errorf("Received nil CommitID") | 341 return nil, fmt.Errorf("Received nil CommitID") |
342 } | 342 } |
343 if in.Entries == nil { | 343 if in.Entries == nil { |
344 return nil, fmt.Errorf("Received nil Entries") | 344 return nil, fmt.Errorf("Received nil Entries") |
345 } | 345 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // Write to the datastore. | 379 // Write to the datastore. |
380 if err := c.Put(key, data.ToBytes()); err != nil { | 380 if err := c.Put(key, data.ToBytes()); err != nil { |
381 return fmt.Errorf("Failed to write the trace info for %s
: %s", key, err) | 381 return fmt.Errorf("Failed to write the trace info for %s
: %s", key, err) |
382 } | 382 } |
383 return nil | 383 return nil |
384 } | 384 } |
385 | 385 |
386 if err := ts.db.Update(add); err != nil { | 386 if err := ts.db.Update(add); err != nil { |
387 return nil, fmt.Errorf("Failed to add values to tracedb: %s", er
r) | 387 return nil, fmt.Errorf("Failed to add values to tracedb: %s", er
r) |
388 } | 388 } |
389 » return &EmptyResponse{}, nil | 389 » return &Empty{}, nil |
390 } | 390 } |
391 | 391 |
392 func (ts *TraceServiceImpl) Remove(ctx context.Context, in *RemoveRequest) (*Emp
tyResponse, error) { | 392 func (ts *TraceServiceImpl) Remove(ctx context.Context, in *RemoveRequest) (*Emp
ty, error) { |
393 if in == nil { | 393 if in == nil { |
394 return nil, fmt.Errorf("Received nil request.") | 394 return nil, fmt.Errorf("Received nil request.") |
395 } | 395 } |
396 remove := func(tx *bolt.Tx) error { | 396 remove := func(tx *bolt.Tx) error { |
397 c := tx.Bucket([]byte(COMMIT_BUCKET_NAME)) | 397 c := tx.Bucket([]byte(COMMIT_BUCKET_NAME)) |
398 key, err := CommitIDToBytes(in.Commitid) | 398 key, err := CommitIDToBytes(in.Commitid) |
399 if err != nil { | 399 if err != nil { |
400 return err | 400 return err |
401 } | 401 } |
402 return c.Delete(key) | 402 return c.Delete(key) |
403 } | 403 } |
404 if err := ts.db.Update(remove); err != nil { | 404 if err := ts.db.Update(remove); err != nil { |
405 return nil, fmt.Errorf("Failed to remove values from tracedb: %s
", err) | 405 return nil, fmt.Errorf("Failed to remove values from tracedb: %s
", err) |
406 } | 406 } |
407 » ret := &EmptyResponse{} | 407 » ret := &Empty{} |
408 return ret, nil | 408 return ret, nil |
409 } | 409 } |
410 | 410 |
411 func (ts *TraceServiceImpl) List(ctx context.Context, listRequest *ListRequest)
(*ListResponse, error) { | 411 func (ts *TraceServiceImpl) List(ctx context.Context, listRequest *ListRequest)
(*ListResponse, error) { |
412 if listRequest == nil { | 412 if listRequest == nil { |
413 return nil, fmt.Errorf("Received nil request.") | 413 return nil, fmt.Errorf("Received nil request.") |
414 } | 414 } |
415 // Convert the begin and end timestamps into RFC3339 strings we can use
for prefix matching. | 415 // Convert the begin and end timestamps into RFC3339 strings we can use
for prefix matching. |
416 begin := []byte(time.Unix(listRequest.Begin, 0).Format(time.RFC3339)) | 416 begin := []byte(time.Unix(listRequest.Begin, 0).Format(time.RFC3339)) |
417 end := []byte(time.Unix(listRequest.End, 0).Format(time.RFC3339)) | 417 end := []byte(time.Unix(listRequest.End, 0).Format(time.RFC3339)) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 510 |
511 return nil | 511 return nil |
512 } | 512 } |
513 if err := ts.db.View(load); err != nil { | 513 if err := ts.db.View(load); err != nil { |
514 return nil, fmt.Errorf("GetParams: Failed to load data: %s", err
) | 514 return nil, fmt.Errorf("GetParams: Failed to load data: %s", err
) |
515 } | 515 } |
516 | 516 |
517 return ret, nil | 517 return ret, nil |
518 } | 518 } |
519 | 519 |
| 520 func (ts *TraceServiceImpl) Ping(ctx context.Context, empty *Empty) (*Empty, err
or) { |
| 521 return &Empty{}, nil |
| 522 } |
| 523 |
520 // Close closes the underlying datastore and it not part of the TraceServiceServ
er interface. | 524 // Close closes the underlying datastore and it not part of the TraceServiceServ
er interface. |
521 func (ts *TraceServiceImpl) Close() error { | 525 func (ts *TraceServiceImpl) Close() error { |
522 return ts.db.Close() | 526 return ts.db.Close() |
523 } | 527 } |
OLD | NEW |