From 23040fc998b00bcf69707c2218553010e2000d49 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 6 Feb 2025 17:18:53 -0500 Subject: [PATCH] Debug ai cost management prs, fix cluster audit logs (#1856) --- assets/src/generated/graphql.ts | 4 +++- charts/ai-proxy/Chart.yaml | 2 +- charts/ai-proxy/templates/deployment.yaml | 3 +++ charts/ai-proxy/templates/serviceaccount.yaml | 8 ++++++++ charts/ai-proxy/values.yaml | 5 +++++ go/client/models_gen.go | 18 ++++++++++-------- lib/console/graphql/deployments/cluster.ex | 16 +++++++++------- lib/console/schema/cluster_audit_log.ex | 9 +++++---- .../20250206161947_add_log_response_code.exs | 9 +++++++++ schema/schema.graphql | 5 ++++- .../deployments/cluster_queries_test.exs | 8 +++++--- 11 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 charts/ai-proxy/templates/serviceaccount.yaml create mode 100644 priv/repo/migrations/20250206161947_add_log_response_code.exs diff --git a/assets/src/generated/graphql.ts b/assets/src/generated/graphql.ts index dc63ed437..77cf25cef 100644 --- a/assets/src/generated/graphql.ts +++ b/assets/src/generated/graphql.ts @@ -1221,17 +1221,19 @@ export type ClusterAuditAttributes = { method: Scalars['String']['input']; /** the path made for the given request */ path: Scalars['String']['input']; + responseCode?: InputMaybe; }; export type ClusterAuditLog = { __typename?: 'ClusterAuditLog'; + actor?: Maybe; cluster?: Maybe; id: Scalars['ID']['output']; insertedAt?: Maybe; method: Scalars['String']['output']; path: Scalars['String']['output']; + responseCode?: Maybe; updatedAt?: Maybe; - user?: Maybe; }; export type ClusterAuditLogConnection = { diff --git a/charts/ai-proxy/Chart.yaml b/charts/ai-proxy/Chart.yaml index d4b4b5b27..03c244074 100644 --- a/charts/ai-proxy/Chart.yaml +++ b/charts/ai-proxy/Chart.yaml @@ -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" diff --git a/charts/ai-proxy/templates/deployment.yaml b/charts/ai-proxy/templates/deployment.yaml index 5a4b50f1e..6152867f9 100644 --- a/charts/ai-proxy/templates/deployment.yaml +++ b/charts/ai-proxy/templates/deployment.yaml @@ -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 }} diff --git a/charts/ai-proxy/templates/serviceaccount.yaml b/charts/ai-proxy/templates/serviceaccount.yaml new file mode 100644 index 000000000..d4e735ccb --- /dev/null +++ b/charts/ai-proxy/templates/serviceaccount.yaml @@ -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 }} \ No newline at end of file diff --git a/charts/ai-proxy/values.yaml b/charts/ai-proxy/values.yaml index 58ea2d6a4..81f54eb6f 100644 --- a/charts/ai-proxy/values.yaml +++ b/charts/ai-proxy/values.yaml @@ -115,3 +115,8 @@ affinity: {} env: [] envFrom: [] + +serviceAccount: + create: true + name: 'ai-proxy' + annotations: {} \ No newline at end of file diff --git a/go/client/models_gen.go b/go/client/models_gen.go index 6f2089030..9c4076a74 100644 --- a/go/client/models_gen.go +++ b/go/client/models_gen.go @@ -942,17 +942,19 @@ type ClusterAuditAttributes struct { // the http method from the given request Method string `json:"method"` // the path made for the given request - Path string `json:"path"` + Path string `json:"path"` + ResponseCode *int64 `json:"responseCode,omitempty"` } type ClusterAuditLog struct { - ID string `json:"id"` - Method string `json:"method"` - Path string `json:"path"` - Cluster *Cluster `json:"cluster,omitempty"` - User *User `json:"user,omitempty"` - InsertedAt *string `json:"insertedAt,omitempty"` - UpdatedAt *string `json:"updatedAt,omitempty"` + ID string `json:"id"` + Method string `json:"method"` + Path string `json:"path"` + ResponseCode *int64 `json:"responseCode,omitempty"` + Cluster *Cluster `json:"cluster,omitempty"` + Actor *User `json:"actor,omitempty"` + InsertedAt *string `json:"insertedAt,omitempty"` + UpdatedAt *string `json:"updatedAt,omitempty"` } type ClusterAuditLogConnection struct { diff --git a/lib/console/graphql/deployments/cluster.ex b/lib/console/graphql/deployments/cluster.ex index d9e503d57..d43357b64 100644 --- a/lib/console/graphql/deployments/cluster.ex +++ b/lib/console/graphql/deployments/cluster.ex @@ -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 @@ -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 diff --git a/lib/console/schema/cluster_audit_log.ex b/lib/console/schema/cluster_audit_log.ex index d9a6985ec..797b64c32 100644 --- a/lib/console/schema/cluster_audit_log.ex +++ b/lib/console/schema/cluster_audit_log.ex @@ -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 @@ -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 diff --git a/priv/repo/migrations/20250206161947_add_log_response_code.exs b/priv/repo/migrations/20250206161947_add_log_response_code.exs new file mode 100644 index 000000000..f447258b4 --- /dev/null +++ b/priv/repo/migrations/20250206161947_add_log_response_code.exs @@ -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 diff --git a/schema/schema.graphql b/schema/schema.graphql index 9135d977d..cb914457a 100644 --- a/schema/schema.graphql +++ b/schema/schema.graphql @@ -4687,6 +4687,8 @@ input ClusterAuditAttributes { "the path made for the given request" path: String! + + responseCode: Int } input ClusterRegistrationCreateAttributes { @@ -5520,8 +5522,9 @@ type ClusterAuditLog { id: ID! method: String! path: String! + responseCode: Int cluster: Cluster - user: User + actor: User insertedAt: DateTime updatedAt: DateTime } diff --git a/test/console/graphql/queries/deployments/cluster_queries_test.exs b/test/console/graphql/queries/deployments/cluster_queries_test.exs index 7e6b07f8a..fadaaa49a 100644 --- a/test/console/graphql/queries/deployments/cluster_queries_test.exs +++ b/test/console/graphql/queries/deployments/cluster_queries_test.exs @@ -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