Skip to content

Commit ddde82b

Browse files
committed
Implementing getmetrichistory
1 parent 6d094dc commit ddde82b

File tree

7 files changed

+54
-295
lines changed

7 files changed

+54
-295
lines changed

src/MLFlowClient.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,8 @@ export
7979
logmetric,
8080
logparam
8181

82+
include("services/misc.jl")
83+
export
84+
getmetrichistory
85+
8286
end

src/api.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ headers(mlf::MLFlow, custom_headers::AbstractDict) = merge(mlf.headers, custom_h
3131
Performs a HTTP GET to a specified endpoint. kwargs are turned into GET params.
3232
"""
3333
function mlfget(mlf, endpoint; kwargs...)
34-
apiuri = uri(mlf, endpoint; parameters=kwargs |> Dict)
34+
apiuri = uri(mlf, endpoint;
35+
parameters=Dict(k => v for (k, v) in kwargs if v !== missing))
3536
apiheaders = headers(mlf, ("Content-Type" => "application/json") |> Dict)
3637

3738
try

src/services/misc.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
getmetrichistory(instance::MLFlow, run_id::String, metric_key::String;
3+
page_token::String="", max_results::Int32=1)
4+
5+
Get a list of all values for the specified metric for a given run.
6+
7+
# Arguments
8+
- `instance`: [`MLFlow`](@ref) configuration.
9+
- `run_id`: ID of the run from which to fetch metric values.
10+
- `metric_key`: Name of the metric.
11+
- `page_token`: Token indicating the page of metric history to fetch.
12+
- `max_results`: Maximum number of logged instances of a metric for a run to
13+
return per call.
14+
"""
15+
function getmetrichistory(instance::MLFlow, run_id::String, metric_key::String;
16+
page_token::String="",
17+
max_results::Union{Int64, Missing}=missing
18+
)::Tuple{Array{Metric}, Union{String, Nothing}}
19+
result = mlfget(instance, "metrics/get-history"; run_id=run_id,
20+
metric_key=metric_key, page_token=page_token,
21+
max_results=
22+
(ismissing(max_results) ? max_results : (max_results |> Int32)))
23+
24+
metrics = result["metrics"] |> (x -> [Metric(y) for y in x])
25+
next_page_token = get(result, "next_page_token", nothing)
26+
27+
return metrics, next_page_token
28+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ include("base.jl")
77
include("services/experiment.jl")
88
include("services/run.jl")
99
include("services/loggers.jl")
10+
include("services/misc.jl")

test/services/misc.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@testset verbose = true "get metric history" begin
2+
@ensuremlf
3+
4+
experiment_id = createexperiment(mlf, UUIDs.uuid4() |> string)
5+
run = createrun(mlf, experiment_id)
6+
for i in 1:20
7+
logmetric(mlf, run, "missy", i |> Float64)
8+
end
9+
10+
@testset "default search" begin
11+
metrics, next_page_token = getmetrichistory(mlf, run.info.run_id,
12+
"missy")
13+
14+
@test length(metrics) == 20
15+
@test next_page_token |> isnothing
16+
end
17+
18+
deleteexperiment(mlf, experiment_id)
19+
end

test/test_functional.jl

Lines changed: 0 additions & 122 deletions
This file was deleted.

test/test_runs.jl

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)