Add condor_jobview to show logfile even without indexer. Add api to s…#2
Add condor_jobview to show logfile even without indexer. Add api to s…#2mmascher wants to merge 1 commit into
Conversation
…how logfile from condor id
| # Do directory/file names need to be sanitized? | ||
| if given_guid: | ||
| cur.execute("SELECT * FROM file_index WHERE GUID='{}'".format(jobID)) | ||
| cur.execute("SELECT * FROM file_index WHERE GUID LIKE '{}'".format(jobID)) |
There was a problem hiding this comment.
Do you expect partial GUIDs?
Why otherwise use a LIKE that is generally less performance than a comparison?
There was a problem hiding this comment.
Yes, tt could be useful to access logs from condor job id for example. Although now that I implemented the new condor_jobview API this is not needed by CMS anymore.
| log_location = os.path.join(log_location_dir, datetime.datetime.now().strftime("%Y-%m-%d") + ".txt") | ||
| with open(log_location, "a") as log_file: | ||
| log_file.write(error_level + " - " + str(int(datetime.datetime.now().timestamp())) + " - " + message + "\n") | ||
| log_file.write(error_level + " - " + "{:%Y-%m-%d %H:%M:%S%z}".format(datetime.datetime.now()) + " - " + message + "\n") |
There was a problem hiding this comment.
datetime.now is by default naive (no time zone info). To print full iso8601 w/ timezone use:
datetime.datetime.now().astimezone().isoformat() or not to have microseconds datetime.datetime.now().astimezone().replace(microsecond=0).isoformat() and to have a single format string:
log_file.write(f"{error_level} - {datetime.datetime.now().astimezone().replace(microsecond=0).isoformat()} - {message}\n")
| def api_condorjob_file(factory, feuser, entry_name, condor_job_id): | ||
| # Get configuration | ||
|
|
||
| return "/data/glideinmonitor/upload/%s/user_%s/glidein_gfactory_instance/entry_%s/job.%s" % (factory, feuser, entry_name, condor_job_id) |
There was a problem hiding this comment.
Would be better to use a configuration variable for the root directory. Is this similar to GWMS_Log_Dir except the client subdir?
| function var_win(data, name) { | ||
| // Open a variable's contents in a new window | ||
| let newWindow = window.open("", name, "width=600, height=800"); | ||
| newWindow.document.write("<pre>" + data + "</pre>"); | ||
| newWindow.document.title = name; | ||
| } | ||
|
|
||
|
|
||
| function var_download(text, filename) { | ||
| // Variable downloader | ||
| let blob = new Blob([text], {type: "text/plain;charset=utf-8"}); | ||
| saveAs(blob, filename); | ||
| } | ||
|
|
||
|
|
||
| function parseTarString(text) { | ||
| // Parses a inflated gzip file that's still in a tar? format | ||
| // Returns a 2D array containing the name and text of each file | ||
| let curr_file = -1; | ||
| let content = []; | ||
|
|
||
| const lines = text.split('\n'); | ||
| for (let i = 0; i < lines.length; i++) { | ||
| // For each line, check if the line is a TAR file header | ||
| if (lines[i].includes(String.fromCharCode(0)) && lines[i].includes("ustar")) { | ||
| // Increment the index of the content variable | ||
| curr_file += 1; | ||
| content[curr_file] = ["", ""]; | ||
|
|
||
| // Get the file name from the header | ||
| let charStart = 0; | ||
| while (lines[i].charCodeAt(charStart) === 0) { |
There was a problem hiding this comment.
I think this should be refactored together w/ jobview.js int 3 files to avoid repeating some functions in multiple files.
There was a problem hiding this comment.
I agree, should I open a new ticket for this refactoring?
| return api_job_info(job_guid, True) | ||
| info = api_job_info(job_guid, True) | ||
| return redirect("/job/" + str(json.loads(info)["ID"]), code=303) |
There was a problem hiding this comment.
Here you redirect, should there be also a route "/api/job_info/condor_job/..." with a redirect to "/condor_job/...."
There was a problem hiding this comment.
This is to have a way to show the job information in a browser given a job_guid (reusing the html page for job). With condor_job there is no such use case IMHO because you only have one way to access the page (the condor job id)
…how logfile from condor id
This change is