[management/client] Integrate Job API with Job Stream and Client Engine#4428
[management/client] Integrate Job API with Job Stream and Client Engine#4428aliamerj merged 17 commits intofeature/remote-debugfrom
Conversation
integrate api with stream and implement some client side
| // blocking until error | ||
| err = c.receiveUpdatesEvents(stream, serverPubKey, msgHandler) | ||
| if err != nil { | ||
| if err != nil && err != io.EOF{ |
There was a problem hiding this comment.
I noticed that when sending a job, I was repeatedly seeing logs from the sync with EFO. To fix this, I updated this not ideal but for now,
the problem is when sending stream request for peer both sync and job triggered and one get valid request and the other get nothing , so we get this error and disconnect the peer , I think we need we to drop the io.EOF check in sync as i did for the job
| case *mgmProto.JobRequest_Bundle: | ||
| uploadKey, err := e.handleBundle(params.Bundle) | ||
| if err != nil { | ||
| return &mgmProto.JobResponse{ | ||
| ID: msg.ID, | ||
| Status: mgmProto.JobStatus_failed, | ||
| Reason: []byte(err.Error()), | ||
| } | ||
| } | ||
| return &mgmProto.JobResponse{ | ||
| ID: msg.ID, | ||
| Status: mgmProto.JobStatus_succeeded, | ||
| WorkloadResults: &mgmProto.JobResponse_Bundle{ | ||
| Bundle: &mgmProto.BundleResult{ | ||
| UploadKey: uploadKey, | ||
| }, |
There was a problem hiding this comment.
Here you are creating unnecessary code duplication. The only generic part is WorkloadResults. The rest is identical and can be build after the switch
There was a problem hiding this comment.
The generic part are
- Status could be succeeded or failed
- Reason could be nil or error message
- WorkloadResults could be nil or the result
so the identical part is just job id
| var job types.Job | ||
| if err := job.ApplyResponse(jobResponse); err != nil { | ||
| return status.Errorf(status.Internal, err.Error()) | ||
| } |
There was a problem hiding this comment.
I would move this conversion to the GRPC layer to not drag proto sturct to deep into the code
| func (e *Engine) getPeerClient() (*grpc.ClientConn, error) { | ||
| conn, err := grpc.NewClient( | ||
| strings.TrimPrefix(e.daemonAddress, "tcp://"), | ||
| grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to connect to daemon error: %v\n"+ | ||
| "If the daemon is not running please run: "+ | ||
| "\nnetbird service install \nnetbird service start\n", err) | ||
| } | ||
|
|
||
| return conn, nil | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't think this is the way to go. The engine is part of the daemon so we are basically connecting to ourself.
There was a problem hiding this comment.
yes, i understand , that is why i needed help to understand what is the best why to call bundle ,
is passing grpc client and call it from it or passing address string and call the bundle or without the grpc and call the debugging directly ?
and also considering the other os
| // todo do not throw error in case of cancelled context | ||
| ctx = internal.CtxInitState(ctx) | ||
| c.connectClient = internal.NewConnectClient(ctx, cfg, c.recorder) | ||
| c.connectClient = internal.NewConnectClient(ctx, cfg, c.recorder, "") |
There was a problem hiding this comment.
- Do we need to pass the
logFilehere
|
|
||
| connectClient := internal.NewConnectClient(ctx, config, r) | ||
| //todo: do we need to pass logFile here ? | ||
| connectClient := internal.NewConnectClient(ctx, config, r, "") |
There was a problem hiding this comment.
- Do we need to pass the
logFilehere
| client := internal.NewConnectClient(ctx, c.config, recorder) | ||
|
|
||
| //todo: do we need to pass logFile here ? | ||
| client := internal.NewConnectClient(ctx, c.config, recorder, "") |
There was a problem hiding this comment.
- Do we need to pass the
logFilehere
|
|
||
| c.connectClient = internal.NewConnectClient(ctx, cfg, c.recorder) | ||
| //todo: do we need to pass logFile here ? | ||
| c.connectClient = internal.NewConnectClient(ctx, cfg, c.recorder, "") |
There was a problem hiding this comment.
- Do we need to pass the
logFilehere
| runOperation := func() error { | ||
| log.Tracef("running client connection") | ||
| s.connectClient = internal.NewConnectClient(ctx, config, statusRecorder) | ||
| s.connectClient = internal.NewConnectClient(ctx, config, statusRecorder, s.logFile) |
There was a problem hiding this comment.
here the only place we we pass the logFile
|
…ne (#4428) * integrate api integrate api with stream and implement some client side * fix typo and fix validation * use real daemon address * redo the connect via address * Refactor the debug bundle generator to be ready to use from engine (#4469) * fix tests * fix lint * fix bug with stream * try refactor status 1 * fix convert fullStatus to statusOutput & add logFile * fix tests * fix tests * fix not enough arguments in call to nbstatus.ConvertToStatusOutputOverview * fix status_test * fix(engine): avoid deadlock when stopping engine during debug bundle * use atomic for lock-free * use new lock --------- Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com>
…ne (#4428) * integrate api integrate api with stream and implement some client side * fix typo and fix validation * use real daemon address * redo the connect via address * Refactor the debug bundle generator to be ready to use from engine (#4469) * fix tests * fix lint * fix bug with stream * try refactor status 1 * fix convert fullStatus to statusOutput & add logFile * fix tests * fix tests * fix not enough arguments in call to nbstatus.ConvertToStatusOutputOverview * fix status_test * fix(engine): avoid deadlock when stopping engine during debug bundle * use atomic for lock-free * use new lock --------- Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com>

Describe your changes
This PR connects the Job API with the peer job stream and updates both server and client code to work together.
What was done:
Issue ticket number and link #4354
Stack
feature/remote-debug-Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__