@@ -28,6 +28,7 @@ import (
2828 "crypto/sha1"
2929 "encoding/hex"
3030 "fmt"
31+ "github.com/AliceO2Group/Control/common/logger/infologger"
3132 "os"
3233 "os/exec"
3334 "path/filepath"
@@ -70,7 +71,9 @@ func extractConfigURIs(dplCommand string) (uris []string) {
7071// jitDplGenerate takes a resolved dplCommand as an argument,
7172// generates the corresponding tasks and workflow
7273// and returns the resolved dplWorkflow as a string
73- func jitDplGenerate (confSvc ConfigurationService , varStack map [string ]string , workflowRepo repos.IRepo , dplCommand string ) (jitWorkflowName string , err error ) {
74+ func jitDplGenerate (confSvc ConfigurationService , varStack map [string ]string , workflowRepo repos.IRepo , dplCommand string , userWfName string ) (jitWorkflowName string , err error ) {
75+ envId , _ := varStack ["environment_id" ]
76+
7477 var payloads []string
7578
7679 configURIs := extractConfigURIs (dplCommand )
@@ -119,7 +122,9 @@ func jitDplGenerate(confSvc ConfigurationService, varStack map[string]string, wo
119122 o2VersionCmd := exec .Command ("bash" , "-c" , "rpm -qa o2-O2 o2-QualityControl" )
120123 o2VersionOut , err := o2VersionCmd .Output ()
121124 if err != nil {
122- log .Warn ("JIT couldn't get O2 / QualityControl version: " + err .Error ())
125+ log .WithField ("partition" , envId ).
126+ WithField ("level" , infologger .IL_Support ).
127+ Warn ("JIT couldn't get O2 / QualityControl version: " + err .Error ())
123128 }
124129
125130 // Get the env vars necessary for JIT
@@ -145,9 +150,16 @@ func jitDplGenerate(confSvc ConfigurationService, varStack map[string]string, wo
145150 // Only generate new tasks & workflows if the files don't exist
146151 // If they exist, hash comparison guarantees validity
147152 if _ , err = os .Stat (filepath .Join (workflowRepo .GetCloneDir (), "workflows" , jitWorkflowName + ".yaml" )); err == nil {
148- log .Tracef ("Workflow '%s' already exists, skipping DPL creation" , jitWorkflowName )
153+ log .WithField ("partition" , envId ).
154+ WithField ("level" , infologger .IL_Support ).
155+ WithField ("hash" , jitWorkflowName ).
156+ Infof ("Reusing JIT workflow templates for '%s'" , userWfName )
149157 return jitWorkflowName , nil
150158 }
159+ log .WithField ("partition" , envId ).
160+ WithField ("level" , infologger .IL_Support ).
161+ WithField ("hash" , jitWorkflowName ).
162+ Infof ("Generating JIT workflow templates for '%s'" , userWfName )
151163
152164 // TODO: Before executing we need to check that this is a valid dpl command
153165 // If not, any command may be injected on the aliecs host
@@ -163,17 +175,23 @@ func jitDplGenerate(confSvc ConfigurationService, varStack map[string]string, wo
163175 var dplOut []byte
164176 dplOut , err = dplCmd .CombinedOutput ()
165177 if err != nil {
166- log .Errorf ("failed to run DPL command due to error '%s'" , err .Error ())
167- log .Errorf ("failed DPL command output: %s" , string (dplOut ))
178+ log .WithField ("partition" , envId ).
179+ WithField ("level" , infologger .IL_Support ).
180+ Errorf ("failed to run DPL command due to error '%s'" , err .Error ())
181+ log .WithField ("partition" , envId ).
182+ WithField ("level" , infologger .IL_Support ).
183+ Errorf ("failed DPL command output: %s" , string (dplOut ))
168184 return "" , fmt .Errorf ("failed to run DPL command due to error '%w'. See FLP Infologger for DPL command output" , err )
169185 } else {
170- log .Trace ("DPL command out: " + string (dplOut ))
186+ log .WithField ("partition" , envId ).
187+ WithField ("level" , infologger .IL_Support ).
188+ Trace ("DPL command out: " + string (dplOut ))
171189 }
172190
173191 return jitWorkflowName , nil
174192}
175193
176- func generateDplSubworkflow (confSvc ConfigurationService , varStack map [string ]string , workflowRepo repos.IRepo , dplCommand string ) (jitWorkflowName string , err error ) {
194+ func generateDplSubworkflow (confSvc ConfigurationService , varStack map [string ]string , workflowRepo repos.IRepo , dplCommand string , userWfName string ) (jitWorkflowName string , err error ) {
177195 if dplCommand == "none" {
178196 return "" , fmt .Errorf ("dplCommand is 'none'" )
179197 }
@@ -185,7 +203,7 @@ func generateDplSubworkflow(confSvc ConfigurationService, varStack map[string]st
185203 return "" , fmt .Errorf ("JIT failed in template resolution of the dpl_command: %w" , err )
186204 }
187205
188- return jitDplGenerate (confSvc , varStack , workflowRepo , "source /etc/profile.d/o2.sh &&" + dplCommand )
206+ return jitDplGenerate (confSvc , varStack , workflowRepo , "source /etc/profile.d/o2.sh &&" + dplCommand , userWfName )
189207}
190208
191209func generateDplSubworkflowFromUri (confSvc ConfigurationService , varStack map [string ]string , workflowRepo repos.IRepo , dplCommandUri string , fallbackToTemplate bool ) (jitWorkflowName string , err error ) {
@@ -199,7 +217,10 @@ func generateDplSubworkflowFromUri(confSvc ConfigurationService, varStack map[st
199217 // if a file in JIT is missing, it will try to fallback to a standard workflow template in 'workflows/'.
200218 // effectively, this allows us to have an intermediate switch workflow to select different JIT commands
201219 // for different nodes.
202- log .Debugf ("JIT: There is no file 'jit/%s' with a DPL command, falling back the template at 'workflows/%s'" , dplCommandUri , dplCommandUri )
220+ envId , _ := varStack ["environment_id" ]
221+ log .WithField ("partition" , envId ).
222+ WithField ("level" , infologger .IL_Support ).
223+ Debugf ("JIT: There is no file 'jit/%s' with a DPL command, falling back the template at 'workflows/%s'" , dplCommandUri , dplCommandUri )
203224 return dplCommandUri , nil
204225 } else {
205226 return "" , fmt .Errorf ("Failed to read DPL command from '%s': %w\n " , dplCommandUri , err )
@@ -213,7 +234,7 @@ func generateDplSubworkflowFromUri(confSvc ConfigurationService, varStack map[st
213234 return "" , fmt .Errorf ("JIT failed in template resolution of the dpl_command: %w" , err )
214235 }
215236
216- jitWorkflowName , err = jitDplGenerate (confSvc , varStack , workflowRepo , "source /etc/profile.d/o2.sh && " + dplCommand )
237+ jitWorkflowName , err = jitDplGenerate (confSvc , varStack , workflowRepo , "source /etc/profile.d/o2.sh && " + dplCommand , dplCommandUri )
217238 if err != nil {
218239 detector := varStack ["detector" ]
219240 return "" , fmt .Errorf ("for JIT workflow '%s' and detector '%s': %w" , dplCommandUri , detector , err )
0 commit comments