@@ -475,15 +475,6 @@ function _restcall_mocked(method, url, headers, payload; query)
475475 else
476476 serve_legacy (logengine, Dict (query))
477477 end
478- elseif in (method, (:HEAD , :GET )) && endswith (url, " /juliaruncloud/get_logs_v2" )
479- logengine = get (MOCK_JULIAHUB_STATE, :logengine , nothing )
480- if isnothing (logengine)
481- JuliaHub. _RESTResponse (500 , " MOCK_JULIAHUB_STATE[:logengine] not set up" )
482- elseif ! logengine. kafkalogging
483- JuliaHub. _RESTResponse (404 , " MOCK_JULIAHUB_STATE[:logengine]: Kafka disabled" )
484- else
485- serve_kafka (logengine, method, Dict (query))
486- end
487478 elseif (method == :GET ) && occursin (" /juliaruncloud/product_image_groups" , url)
488479 Dict (
489480 " image_groups" => Dict (
@@ -532,91 +523,10 @@ end
532523
533524Base. @kwdef mutable struct LogEngine
534525 jobs:: Dict{String, LogEngineJob} = Dict ()
535- kafkalogging:: Bool = false
536- # The real legacy endpoint has a limit of 10k. Similarly, for the real
537- # kafka endpoint this is determined by the max_bytes of the response,
538- # so it can actually vary.
526+ # The real legacy endpoint has a limit of 10k
539527 max_response_size:: Int = 10
540528end
541529
542- function serve_kafka (logengine:: LogEngine , method:: Symbol , query:: AbstractDict )
543- jobname = get (query, " jobname" , nothing )
544- job = get (logengine. jobs, jobname, nothing )
545- # If the client is doing a HEAD request, then we immediately return the
546- # approriate empty response.
547- if method == :HEAD
548- if isnothing (jobname)
549- return JuliaHub. _RESTResponse (400 , " " )
550- elseif isnothing (job)
551- return JuliaHub. _RESTResponse (404 , " " )
552- else
553- return JuliaHub. _RESTResponse (200 , " " )
554- end
555- end
556- # Error handing for the GET requests (like for HEAD, but with a body)
557- if isnothing (jobname)
558- return JuliaHub. _RESTResponse (400 , " jobname is missing" )
559- elseif isnothing (job)
560- return JuliaHub. _RESTResponse (404 , " No such job $jobname " )
561- end
562- # Return the normal response
563- offset = get (query, " offset" , nothing )
564- # We'll construct the full list of logs for the job, including the meta message
565- # at the end if necessary.
566- logs:: Vector{Any} = map (enumerate (job. logs)) do (i, log)
567- # Make the indexing start from 0, to match the Kafka offset logic
568- (i - 1 , log)
569- end
570- # We'll add the meta=bottom message, if needed.
571- if ! job. isrunning
572- push! (logs, (length (logs), :bottom ))
573- end
574- logs = if isnothing (offset)
575- start = max (1 , length (logs) - logengine. max_response_size + 1 )
576- logs[start: end ]
577- elseif offset + 1 <= length (logs)
578- start = offset + 1
579- stop = min (start + logengine. max_response_size - 1 , length (logs))
580- logs[start: stop]
581- else
582- [] # For out of range offsets we just return an empty list of logs
583- end
584- start_timestamp = Dates. now ()
585- logs = map (logs) do (i, log)
586- value = if isa (log, Symbol)
587- Dict (" meta" => string (log))
588- else
589- Dict (
590- " timestamp" =>
591- JuliaHub. _log_legacy_datetime_to_ms (start_timestamp + Dates. Second (i)),
592- " log" => Dict (
593- " message" => String (log),
594- " keywords" => Dict (
595- " typeof(logger)" => " LoggingExtras..." ,
596- " jrun_hostname" => " jr-ecogm4cccn-x5z4g" ,
597- " jrun_worker_id" => 1 ,
598- " jrun_thread_id" => 1 ,
599- " jrun_time" => start_timestamp,
600- " jrun_process_id" => 27 ,
601- ),
602- " metadata" => Dict (
603- " line" => 141 ,
604- " id" => " Main_JuliaRunJob_53527a33" ,
605- " _module" => " Main.JuliaRunJob" ,
606- " filepath" => " /opt/juliahub/master_startup.jl" ,
607- " group" => " master_startup" ,
608- " level" => " Info" ,
609- " steam" => " stdout" ,
610- ),
611- ),
612- )
613- end
614- Dict (" offset" => i, " value" => value)
615- end
616- logs_json = JSON. json (Dict (" consumer_id" => 1234 , " logs" => logs))
617- return JuliaHub. _RESTResponse (200 , logs_json)
618- end
619-
620530function serve_legacy (logengine:: LogEngine , query:: AbstractDict )
621531 jobname = get (query, " jobname" , nothing )
622532 job = get (logengine. jobs, jobname, nothing )
0 commit comments