-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cluster Usage History Recording (#1220)
- Loading branch information
1 parent
3384148
commit 58894a4
Showing
12 changed files
with
201 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Core.Schema.ClusterUsageHistory do | ||
use Piazza.Ecto.Schema | ||
alias Core.Schema.{Account, Cluster} | ||
|
||
schema "cluster_usage_history" do | ||
field :cpu, :integer | ||
field :memory, :integer | ||
|
||
belongs_to :cluster, Cluster | ||
belongs_to :account, Account | ||
|
||
timestamps() | ||
end | ||
|
||
def inserted_after(query \\ __MODULE__, dt) do | ||
from(u in query, where: u.inserted_at >= ^dt) | ||
end | ||
|
||
def for_cluster(query \\ __MODULE__, cluster_id) do | ||
from(u in query, where: u.cluster_id == ^cluster_id) | ||
end | ||
|
||
def for_account(query \\ __MODULE__, account_id) do | ||
from(u in query, where: u.account_id == ^account_id) | ||
end | ||
|
||
def ordered(query \\ __MODULE__, order \\ [asc: :inserted_at]) do | ||
from(u in query, order_by: ^order) | ||
end | ||
|
||
@valid ~w(cpu memory cluster_id account_id)a | ||
|
||
def changeset(model, attrs \\ %{}) do | ||
model | ||
|> cast(attrs, @valid) | ||
|> foreign_key_constraint(:account_id) | ||
|> validate_required([:account_id, :cluster_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/core/priv/repo/migrations/20230828190601_add_cluster_usage.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Core.Repo.Migrations.AddClusterUsage do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:cluster_usage_history, primary_key: false) do | ||
add :id, :uuid, primary_key: true | ||
add :cluster_id, :uuid | ||
add :account_id, :uuid | ||
add :memory, :bigint | ||
add :cpu, :bigint | ||
|
||
timestamps() | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters