Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding use_ajax flag to MLFlow instances #44

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
MLFLOW_TRACKING_URI: "http://localhost:5000"
MLFLOW_API_URI: "http://localhost:5000/api"
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
Expand Down
1 change: 0 additions & 1 deletion docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ uri
generatefilterfromentity_type
generatefilterfromparams
generatefilterfromattributes
healthcheck
```
26 changes: 13 additions & 13 deletions src/types/mlflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
Base type which defines location and version for MLFlow API service.

# Fields
- `baseuri::String`: base MLFlow tracking URI, e.g. `http://localhost:5000`
- `apiversion`: used API version, e.g. `2.0`
- `headers`: HTTP headers to be provided with the REST API requests (useful for authetication tokens)
- `apiroot::String`: API root URL, e.g. `http://localhost:5000/api`
- `apiversion::Union{Integer, AbstractFloat}`: used API version, e.g. `2.0`
- `headers::Dict`: HTTP headers to be provided with the REST API requests (useful for authetication tokens)
Default is `false`, using the REST API endpoint.

# Constructors

- `MLFlow(baseuri; apiversion=2.0,headers=Dict())`
- `MLFlow()` - defaults to `MLFlow(ENV["MLFLOW_TRACKING_URI"])` or `MLFlow("http://localhost:5000")`
- `MLFlow(apiroot; apiversion=2.0,headers=Dict())`
- `MLFlow()` - defaults to `MLFlow(ENV["MLFLOW_API_URI"])` or `MLFlow("http://localhost:5000")`

# Examples

Expand All @@ -26,17 +27,16 @@ mlf = MLFlow(remote_url, headers=Dict("Authorization" => "Bearer <your-secret-to

"""
struct MLFlow
baseuri::String
apiroot::String
apiversion::Union{Integer, AbstractFloat}
headers::Dict
end
MLFlow(baseuri; apiversion=2.0,headers=Dict()) = MLFlow(baseuri, apiversion,headers)
MLFlow(apiroot; apiversion=2.0, headers=Dict()) = MLFlow(apiroot, apiversion, headers)
function MLFlow()
baseuri = "http://localhost:5000"
if haskey(ENV, "MLFLOW_TRACKING_URI")
baseuri = ENV["MLFLOW_TRACKING_URI"]
apiroot = "http://localhost:5000/api"
if haskey(ENV, "MLFLOW_API_URI")
apiroot = ENV["MLFLOW_API_URI"]
end
return MLFlow(baseuri)
return MLFlow(apiroot)
end

Base.show(io::IO, t::MLFlow) = show(io, ShowCase(t, [:baseuri,:apiversion], new_lines=true))
Base.show(io::IO, t::MLFlow) = show(io, ShowCase(t, [:apiroot,:apiversion], new_lines=true))
18 changes: 1 addition & 17 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
"""
healthcheck(mlf::MLFlow)

Checks if MLFlow server is up and running. Returns `true` if it is, `false`
otherwise.
"""
function healthcheck(mlf)
uri = "$(mlf.baseuri)/health"
try
response = HTTP.get(uri)
return String(response.body) == "OK"
catch e
return false
end
end

"""
uri(mlf::MLFlow, endpoint="", query=missing)

Expand All @@ -25,7 +9,7 @@ MLFlowClient.uri(mlf, "experiments/get", Dict(:experiment_id=>10))
```
"""
function uri(mlf::MLFlow, endpoint="", query=missing)
u = URI("$(mlf.baseuri)/ajax-api/$(mlf.apiversion)/mlflow/$(endpoint)")
u = URI("$(mlf.apiroot)/$(mlf.apiversion)/mlflow/$(endpoint)")
!ismissing(query) && return URI(u; query=query)
u
end
Expand Down
2 changes: 1 addition & 1 deletion test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function mlflow_server_is_running(mlf::MLFlow)
end

# creates an instance of mlf
# skips test if mlflow is not available on default location, ENV["MLFLOW_TRACKING_URI"]
# skips test if mlflow is not available on default location, ENV["MLFLOW_API_URI"]
macro ensuremlf()
e = quote
mlf = MLFlow()
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
if ~haskey(ENV, "MLFLOW_API_URI")
error("WARNING: MLFLOW_API_URI is not set. To run this tests, you need to set the URI of your MLFlow server API")
end

include("base.jl")

include("test_functional.jl")
include("test_experiments.jl")
include("test_runs.jl")
include("test_loggers.jl")
26 changes: 12 additions & 14 deletions test/test_functional.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@testset "MLFlow" begin
mlf = MLFlow()
@test mlf.baseuri == ENV["MLFLOW_TRACKING_URI"]
@test mlf.apiroot == ENV["MLFLOW_API_URI"]
@test mlf.apiversion == 2.0
@test mlf.headers == Dict()
mlf = MLFlow("https://localhost:5001", apiversion=3.0)
@test mlf.baseuri == "https://localhost:5001"
mlf = MLFlow("https://localhost:5001/api", apiversion=3.0)
@test mlf.apiroot == "https://localhost:5001/api"
@test mlf.apiversion == 3.0
@test mlf.headers == Dict()
let custom_headers = Dict("Authorization" => "Bearer EMPTY")
mlf = MLFlow("https://localhost:5001", apiversion=3.0, headers=custom_headers)
@test mlf.baseuri == "https://localhost:5001"
mlf = MLFlow("https://localhost:5001/api", apiversion=3.0, headers=custom_headers)
@test mlf.apiroot == "https://localhost:5001/api"
@test mlf.apiversion == 3.0
@test mlf.headers == custom_headers
end
Expand All @@ -21,8 +21,8 @@ end
secret_token = "SECRET"

custom_headers = Dict("Authorization" => "Bearer $secret_token")
mlf = MLFlow("https://localhost:5001", apiversion=3.0, headers=custom_headers)
@test mlf.baseuri == "https://localhost:5001"
mlf = MLFlow("https://localhost:5001/api", apiversion=3.0, headers=custom_headers)
@test mlf.apiroot == "https://localhost:5001/api"
@test mlf.apiversion == 3.0
@test mlf.headers == custom_headers
show(io, mlf)
Expand All @@ -35,17 +35,15 @@ end
using MLFlowClient: uri, headers
using URIs: URI

@test healthcheck(MLFlow()) == true

let baseuri = "http://localhost:5001", apiversion = "2.0", endpoint = "experiments/get"
mlf = MLFlow(baseuri; apiversion)
let apiroot = "http://localhost:5001/api", apiversion = 2.0, endpoint = "experiments/get"
mlf = MLFlow(apiroot; apiversion=apiversion)
apiuri = uri(mlf, endpoint)
@test apiuri == URI("$baseuri/ajax-api/$apiversion/mlflow/$endpoint")
@test apiuri == URI("$apiroot/$apiversion/mlflow/$endpoint")
end
let baseuri = "http://localhost:5001", auth_headers = Dict("Authorization" => "Bearer 123456"),
let apiroot = "http://localhost:5001/api", auth_headers = Dict("Authorization" => "Bearer 123456"),
custom_headers = Dict("Content-Type" => "application/json")

mlf = MLFlow(baseuri; headers=auth_headers)
mlf = MLFlow(apiroot; headers=auth_headers)
apiheaders = headers(mlf, custom_headers)
@test apiheaders == Dict("Authorization" => "Bearer 123456", "Content-Type" => "application/json")
end
Expand Down
Loading