Skip to content

Commit

Permalink
Debug ai cost management prs, fix cluster audit logs (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Feb 6, 2025
1 parent a2b8405 commit 23040fc
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 25 deletions.
4 changes: 3 additions & 1 deletion assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,17 +1221,19 @@ export type ClusterAuditAttributes = {
method: Scalars['String']['input'];
/** the path made for the given request */
path: Scalars['String']['input'];
responseCode?: InputMaybe<Scalars['Int']['input']>;
};

export type ClusterAuditLog = {
__typename?: 'ClusterAuditLog';
actor?: Maybe<User>;
cluster?: Maybe<Cluster>;
id: Scalars['ID']['output'];
insertedAt?: Maybe<Scalars['DateTime']['output']>;
method: Scalars['String']['output'];
path: Scalars['String']['output'];
responseCode?: Maybe<Scalars['Int']['output']>;
updatedAt?: Maybe<Scalars['DateTime']['output']>;
user?: Maybe<User>;
};

export type ClusterAuditLogConnection = {
Expand Down
2 changes: 1 addition & 1 deletion charts/ai-proxy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: ai-proxy
description: A Helm chart for ai-proxy
type: application
version: 0.2.1
version: 0.2.2
appVersion: "v1.2.0"
3 changes: 3 additions & 0 deletions charts/ai-proxy/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- if .Values.serviceAccount.create }}
serviceAccountName: ai-proxy
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
Expand Down
8 changes: 8 additions & 0 deletions charts/ai-proxy/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.serviceAccount.name }}
annotations:
{{ toYaml .Values.serviceAccount.annotations | nindent 4 }}
{{ end }}
5 changes: 5 additions & 0 deletions charts/ai-proxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,8 @@ affinity: {}
env: []

envFrom: []

serviceAccount:
create: true
name: 'ai-proxy'
annotations: {}
18 changes: 10 additions & 8 deletions go/client/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions lib/console/graphql/deployments/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ defmodule Console.GraphQl.Deployments.Cluster do
end

input_object :cluster_audit_attributes do
field :cluster_id, non_null(:id), description: "the cluster this request was made on"
field :method, non_null(:string), description: "the http method from the given request"
field :path, non_null(:string), description: "the path made for the given request"
field :cluster_id, non_null(:id), description: "the cluster this request was made on"
field :method, non_null(:string), description: "the http method from the given request"
field :path, non_null(:string), description: "the path made for the given request"
field :response_code, :integer
end

input_object :cluster_registration_create_attributes do
Expand Down Expand Up @@ -908,12 +909,13 @@ defmodule Console.GraphQl.Deployments.Cluster do
end

object :cluster_audit_log do
field :id, non_null(:id)
field :method, non_null(:string)
field :path, non_null(:string)
field :id, non_null(:id)
field :method, non_null(:string)
field :path, non_null(:string)
field :response_code, :integer

field :cluster, :cluster, resolve: dataloader(Deployments)
field :user, :user, resolve: dataloader(User)
field :actor, :user, resolve: dataloader(User)

timestamps()
end
Expand Down
9 changes: 5 additions & 4 deletions lib/console/schema/cluster_audit_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ defmodule Console.Schema.ClusterAuditLog do
@expires [days: -30]

schema "cluster_audit_logs" do
field :method, :string
field :path, :string
field :method, :string
field :path, :string
field :response_code, :integer

belongs_to :cluster, Cluster
belongs_to :actor, User
Expand All @@ -27,13 +28,13 @@ defmodule Console.Schema.ClusterAuditLog do
from(al in query, order_by: ^order)
end

@valid ~w(method path cluster_id actor_id)a
@valid ~w(method path response_code cluster_id actor_id)a

def changeset(model, attrs \\ %{}) do
model
|> cast(attrs, @valid)
|> foreign_key_constraint(:user_id)
|> foreign_key_constraint(:cluster_id)
|> validate_required(@valid)
|> validate_required(~w(method path cluster_id actor_id)a)
end
end
9 changes: 9 additions & 0 deletions priv/repo/migrations/20250206161947_add_log_response_code.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Console.Repo.Migrations.AddLogResponseCode do
use Ecto.Migration

def change do
alter table(:cluster_audit_logs) do
add :response_code, :integer
end
end
end
5 changes: 4 additions & 1 deletion schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4687,6 +4687,8 @@ input ClusterAuditAttributes {

"the path made for the given request"
path: String!

responseCode: Int
}

input ClusterRegistrationCreateAttributes {
Expand Down Expand Up @@ -5520,8 +5522,9 @@ type ClusterAuditLog {
id: ID!
method: String!
path: String!
responseCode: Int
cluster: Cluster
user: User
actor: User
insertedAt: DateTime
updatedAt: DateTime
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,16 @@ defmodule Console.GraphQl.Deployments.ClusterQueriesTest do
query cluster($id: ID!) {
cluster(id: $id) {
auditLogs(first: 5) {
edges { node { id } }
edges { node { id actor { id } } }
}
}
}
""", %{"id" => cluster.id}, %{current_user: user})

assert from_connection(found["auditLogs"])
|> ids_equal(audits)
logs = from_connection(found["auditLogs"])
assert ids_equal(logs, audits)
assert Enum.map(logs, & &1["actor"]["id"])
|> ids_equal(Enum.map(audits, & &1.actor_id))
end

test "it can fetch cluster node metrics" do
Expand Down

0 comments on commit 23040fc

Please sign in to comment.