Skip to content

Commit

Permalink
Add test case for availability router
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jan 10, 2025
1 parent 663398c commit 2133931
Show file tree
Hide file tree
Showing 7 changed files with 679 additions and 3 deletions.
1 change: 1 addition & 0 deletions availability.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"responses":[{"_shards":{"failed":0,"skipped":0,"successful":3,"total":3},"aggregations":{"arrakis":{"buckets":[{"doc_count":7010,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":43072706160},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"livebook"},{"doc_count":7009,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":457936032},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"insterra-testing"},{"doc_count":7008,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":4137743538512},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"nas-box"},{"doc_count":7007,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":223143856},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"apm"},{"doc_count":7007,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":1684621920},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"elastic"},{"doc_count":7007,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":1629082992},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"kibana"},{"doc_count":7007,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":286888960},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"minio"},{"doc_count":7007,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":502670816},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"postgresql"},{"doc_count":6977,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":22915831552},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"win11"},{"doc_count":627,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":141514000},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"uplink"},{"doc_count":457,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":122049801248},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"immich"},{"doc_count":457,"filesystem_used_bytes":{"top":[{"metrics":{"system.filesystem.used.bytes":14625002368},"sort":["2025-01-10T05:56:30.214Z"]}]},"key":"ollama"}],"doc_count_error_upper_bound":0,"sum_other_doc_count":0},"filesystem_used_bytes":{"value":4345332738416.0}},"hits":{"hits":[],"max_score":null,"total":{"relation":"gte","value":10000}},"status":200,"timed_out":false,"took":5},{"_shards":{"failed":0,"skipped":0,"successful":3,"total":3},"aggregations":{"arrakis":{"buckets":[{"doc_count":749,"key":"apm","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"elastic","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.001},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"insterra-testing","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"kibana","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.001},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"livebook","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.001},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"minio","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"nas-box","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"postgresql","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.001},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":749,"key":"win11","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":513,"key":"uplink","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":415,"key":"immich","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.001},"sort":["2025-01-10T04:34:00.250Z"]}]}},{"doc_count":415,"key":"ollama","load_norm_5":{"top":[{"metrics":{"system.load.norm.5":0.0},"sort":["2025-01-10T04:34:00.250Z"]}]}}],"doc_count_error_upper_bound":0,"sum_other_doc_count":0},"load_norm_5":{"value":0.005}},"hits":{"hits":[],"max_score":null,"total":{"relation":"eq","value":8084}},"status":200,"timed_out":false,"took":1},{"_shards":{"failed":0,"skipped":0,"successful":3,"total":3},"aggregations":{"arrakis":{"buckets":[{"doc_count":7010,"key":"livebook","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":213258240},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7009,"key":"insterra-testing","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":33275904},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7008,"key":"nas-box","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":206090240},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7007,"key":"apm","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":91762688},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7007,"key":"elastic","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":36014866432},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7007,"key":"kibana","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":612876288},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7007,"key":"minio","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":187273216},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":7007,"key":"postgresql","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":100323328},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":6977,"key":"win11","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":0},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":627,"key":"uplink","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":1126400},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":457,"key":"immich","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":1360203776},"sort":["2025-01-10T05:56:30.214Z"]}]}},{"doc_count":457,"key":"ollama","memory_used_bytes":{"top":[{"metrics":{"system.memory.actual.used.bytes":1026732032},"sort":["2025-01-10T05:56:30.214Z"]}]}}],"doc_count_error_upper_bound":0,"sum_other_doc_count":0},"memory_used_bytes":{"value":39847788544.0}},"hits":{"hits":[],"max_score":null,"total":{"relation":"gte","value":10000}},"status":200,"timed_out":false,"took":6}],"took":7}
4 changes: 3 additions & 1 deletion lib/uplink/availability.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ defmodule Uplink.Availability do

Metrics.query!(monitor, query)
|> case do
%{status: 200, body: %{"responses" => responses}} ->
%{status: 200, body: %{"responses" => responses} = body} ->
File.write!("availability.json", Jason.encode!(body))

resources =
nodes
|> Response.parse(responses)
Expand Down
8 changes: 8 additions & 0 deletions lib/uplink/availability/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ defmodule Uplink.Availability.Resource do
use Ecto.Schema
import Ecto.Changeset

@derive Jason.Encoder

@primary_key false
embedded_schema do
field :node, :string

embeds_one :total, Total, primary_key: false do
@derive Jason.Encoder

field :cpu_cores, :integer
field :memory_bytes, :decimal
field :storage_bytes, :decimal
end

embeds_one :used, Used, primary_key: false do
@derive Jason.Encoder

field :load_norm_5, :decimal
field :memory_bytes, :decimal
field :storage_bytes, :decimal
end

embeds_one :available, Available, primary_key: false do
@derive Jason.Encoder

field :processing, :decimal
field :memory, :decimal
field :storage, :decimal
Expand Down
2 changes: 1 addition & 1 deletion lib/uplink/availability/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Uplink.Availability.Router do
use Uplink.Web

alias Uplink.Secret
alias Uplink.Availability.Resource
alias Uplink.Availability

plug :match

Expand Down
Loading

0 comments on commit 2133931

Please sign in to comment.