Skip to content

Commit

Permalink
fix: alert_queries should use text column types (#1975)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc authored Feb 23, 2024
1 parent 34328e4 commit 345a6ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Logflare.Repo.Migrations.AlterAlertQueriesTableTextField do
use Ecto.Migration

def change do
alter table(:alert_queries) do
modify :query, :text, from: :string
modify :description, :text, from: :string
end
end
end
17 changes: 17 additions & 0 deletions test/logflare/alerting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ defmodule Logflare.AlertingTest do
assert alert_query.token
end

test "bug: create_alert_query/1 with very long query", %{user: user} do
assert {:ok, %AlertQuery{}} =
Alerting.create_alert_query(user, %{
@valid_attrs
| query: """
with pg as (
select round(count(t.id) / 360 ) as rate from `postgres.logs` t
where t.timestamp > timestamp_sub(current_timestamp(), interval 5 minute)
), cf as (
select round(count(t.id) / 360 ) as rate from `cloudflare.logs.prod` t
where t.timestamp > timestamp_sub(current_timestamp(), interval 5 minute)
)
select pg.rate as pg_per_sec, cf.rate as cf_per_sec from pg, cf
"""
})
end

test "create_alert_query/1 with invalid data returns error changeset", %{user: user} do
assert {:error, %Ecto.Changeset{}} = Alerting.create_alert_query(user, @invalid_attrs)
# invalid cron
Expand Down

0 comments on commit 345a6ad

Please sign in to comment.