8000 feat(worker): add log on start job about prj... (#3539) · ovh/cds@1287ec1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 1287ec1

Browse files
yesnaultbnjjj
authored andcommitted
feat(worker): add log on start job about prj... (#3539)
1 parent 49bac8b commit 1287ec1

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

engine/worker/builtin.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,16 @@ func (w *currentWorker) runGRPCPlugin(ctx context.Context, a *sdk.Action, buildI
153153
}
154154

155155
result, err := actionPluginClient.Run(ctx, &query)
156+
pluginDetails := fmt.Sprintf("plugin %s v%s", manifest.Name, manifest.Version)
156157
if err != nil {
157-
log.Error("plugin failure %s v%s err: %v", manifest.Name, manifest.Version, err)
158+
t := fmt.Sprintf("failure %s err: %v", pluginDetails, err)
159+
syncStd(t)
160+
log.Error(t)
158161
pluginFail(chanRes, sendLog, fmt.Sprintf("Error running action: %v", err))
159162
return
160163
}
161164

162-
_ = os.Stdout.Sync()
163-
_ = os.Stderr.Sync()
165+
syncStd(pluginDetails)
164166

165167
chanRes <- sdk.Result{
166168
Status: result.GetStatus(),
@@ -182,6 +184,15 @@ func (w *currentWorker) runGRPCPlugin(ctx context.Context, a *sdk.Action, buildI
182184
}
183185
}
184186

187+
func syncStd(p string) {
188+
if err := os.Stdout.Sync(); err != nil {
189+
log.Error("os.Stdout.Sync %s err:%v", p, err)
190+
}
191+
if err := os.Stderr.Sync(); err != nil {
192+
log.Error("os.Stderr.Sync %s err:%v", p, err)
193+
}
194+
}
195+
185196
func pluginFail(chanRes chan<- sdk.Result, sendLog LoggerFunc, reason string) {
186197
res := sdk.Result{
187198
Reason: reason,

engine/worker/run.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,23 @@ func (w *currentWorker) processActionVariables(a *sdk.Action, parent *sdk.Action
9191

9292
func (w *currentWorker) startAction(ctx context.Context, a *sdk.Action, buildID int64, params *[]sdk.Parameter, secrets []sdk.Variable, stepOrder int, stepName string) sdk.Result {
9393
// Process action build arguments
94+
var project, workflow, node, job string
9495
for _, abp := range *params {
9596
// Process build variable for root action
9697
for j := range a.Parameters {
9798
if abp.Name == a.Parameters[j].Name {
9899
a.Parameters[j].Value = abp.Value
99100
}
101+
switch abp.Name {
102+
case "cds.project":
103+
project = abp.Value
104+
case "cds.worklow":
105+
workflow = abp.Value
106+
case "cds.node":
107+
node = abp.Value
108+
case "cds.job":
109+
job = abp.Value
110+
}
100111
}
101112
}
102113

@@ -113,6 +124,7 @@ func (w *currentWorker) startAction(ctx context.Context, a *sdk.Action, buildID
113124
}
114125
}
115126

127+
log.Info("startAction> project:%s workflow:%s node:%s job:%s", project, workflow, node, job)
116128
return w.runJob(ctx, a, buildID, params, secrets, stepOrder, stepName)
117129
}
118130

engine/worker/run_plugin.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func startGRPCPlugin(ctx context.Context, pluginName string, w *currentWorker, p
8181
var errBi error
8282
binary, errBi = w.client.PluginGetBinaryInfos(pluginName, currentOS, currentARCH)
8383
if errBi != nil || binary == nil {
84-
return nil, sdk.WrapError(errBi, "Unable to get plugin binary infos... Aborting")
84+
return nil, sdk.WrapError(errBi, "plugin:%s Unable to get plugin binary infos... Aborting", pluginName)
8585
}
8686
}
8787

@@ -106,17 +106,17 @@ func startGRPCPlugin(ctx context.Context, pluginName string, w *currentWorker, p
106106
log.Info("Starting GRPC Plugin %s in dir %s", binary.Name, dir)
107107
fileContent, err := ioutil.ReadFile(path.Join(w.basedir, binary.GetName()))
108108
if err != nil {
109-
return nil, sdk.WrapError(err, "Unable to get plugin binary file... Aborting")
109+
return nil, sdk.WrapError(err, "plugin:%s unable to get plugin binary file... Aborting", pluginName)
110110
}
111111

112112
switch {
113113
case sdk.IsTar(fileContent):
114114
if err := sdk.Untar(w.basedir, bytes.NewReader(fileContent)); err != nil {
115-
return nil, sdk.WrapError(err, "Unable to untar binary file")
115+
return nil, sdk.WrapError(err, "plugin:%s unable to untar binary file", pluginName)
116116
}
117117
case sdk.IsGz(fileContent):
118118
if err := sdk.UntarGz(w.basedir, bytes.NewReader(fileContent)); err != nil {
119-
return nil, sdk.WrapError(err, "Unable to untarGz binary file")
119+
return nil, sdk.WrapError(err, "plugin:%s unable to untarGz binary file", pluginName)
120120
}
121121
}
122122

@@ -129,13 +129,13 @@ func startGRPCPlugin(ctx context.Context, pluginName string, w *currentWorker, p
129129
cmd = path.Join(w.basedir, cmd)
130130
_, err = exec.LookPath(cmd)
131131
if err != nil {
132-
return nil, sdk.WrapError(err, "Unable to start GRPC plugin, binary command not found.")
132+
return nil, sdk.WrapError(err, "plugin:%s unable to start GRPC plugin, binary command not found.", pluginName)
133133
}
134134
}
135135
args := append(binary.Entrypoints, binary.Args...)
136136

137137
if err := grpcplugin.StartPlugin(ctx, dir, cmd, args, envs, mOut, mErr); err != nil {
138-
return nil, sdk.WrapError(err, "Unable to start GRPC plugin... Aborting")
138+
return nil, sdk.WrapError(err, "plugin:%s unable to start GRPC plugin... Aborting", pluginName)
139139
}
140140
log.Info("GRPC Plugin %s started", binary.Name)
141141

@@ -149,15 +149,15 @@ func startGRPCPlugin(ctx context.Context, pluginName string, w *currentWorker, p
149149
if err != nil && len(buff.String()) > 0 {
150150
buff.Reset()
151151
if time.Now().Before(tsStart.Add(5 * time.Second)) {
152-
log.Warning("Error on ReadByte, retry in 500ms...")
152+
log.Warning("plugin:%s error on ReadByte, retry in 500ms...", pluginName)
153153
time.Sleep(500 * time.Millisecond)
154154
continue
155155
}
156-
log.Error("error on ReadByte(len buff %d, content: %s): %v", len(buff.String()), buff.String(), err)
156+
log.Error("plugin:%s error on ReadByte(len buff %d, content: %s): %v", pluginName, len(buff.String()), buff.String(), err)
157157
return nil, fmt.Errorf("unable to get socket address from started binary")
158158
}
159159
if err := buff.WriteByte(b); err != nil {
160-
log.Error("error on write byte: %v", err)
160+
log.Error("plugin:%s error on write byte: %v", pluginName, err)
161161
break
162162
}
163163
if strings.HasSuffix(buff.String(), "is ready to accept new connection\n") {

0 commit comments

Comments
 (0)
0