From 72b7829d3e396a57e721b07ad7e46d6196f010c6 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 5 Apr 2023 13:57:22 -0400 Subject: [PATCH] fixes from video (#235) --- controller/limits/agent.go | 14 +++++++++----- controller/metrics/amqpSink.go | 2 ++ .../010_v0_4_0_frontend_private_share.sql | 6 +++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/controller/limits/agent.go b/controller/limits/agent.go index f2ff9d4c..1f05fd18 100644 --- a/controller/limits/agent.go +++ b/controller/limits/agent.go @@ -70,13 +70,17 @@ func (a *Agent) Stop() { func (a *Agent) CanCreateEnvironment(acctId int, trx *sqlx.Tx) (bool, error) { if a.cfg.Enforcing { - alj, err := a.str.FindLatestAccountLimitJournal(acctId, trx) - if err != nil { + if empty, err := a.str.IsAccountLimitJournalEmpty(acctId, trx); err == nil && !empty { + alj, err := a.str.FindLatestAccountLimitJournal(acctId, trx) + if err != nil { + return false, err + } + if alj.Action == store.LimitAction { + return false, nil + } + } else if err != nil { return false, err } - if alj.Action == store.LimitAction { - return false, nil - } if a.cfg.Environments > Unlimited { envs, err := a.str.FindEnvironmentsForAccount(acctId, trx) diff --git a/controller/metrics/amqpSink.go b/controller/metrics/amqpSink.go index 451bdb7b..520e86b7 100644 --- a/controller/metrics/amqpSink.go +++ b/controller/metrics/amqpSink.go @@ -6,6 +6,7 @@ import ( "github.com/openziti/zrok/controller/env" "github.com/pkg/errors" amqp "github.com/rabbitmq/amqp091-go" + "github.com/sirupsen/logrus" "time" ) @@ -57,6 +58,7 @@ func newAmqpSink(cfg *AmqpSinkConfig) (*amqpSink, error) { func (s *amqpSink) Handle(event ZitiEventJson) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() + logrus.Infof("pushing '%v'", event) return s.ch.PublishWithContext(ctx, "", s.queue.Name, false, false, amqp.Publishing{ ContentType: "application/json", Body: []byte(event), diff --git a/controller/store/sql/postgresql/010_v0_4_0_frontend_private_share.sql b/controller/store/sql/postgresql/010_v0_4_0_frontend_private_share.sql index cabf651d..c08c193d 100644 --- a/controller/store/sql/postgresql/010_v0_4_0_frontend_private_share.sql +++ b/controller/store/sql/postgresql/010_v0_4_0_frontend_private_share.sql @@ -14,7 +14,7 @@ create table frontends ( reserved boolean not null default(false), created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp), - deleted boolean not null default(false), + deleted boolean not null default(false) ); insert into frontends (id, environment_id, token, z_id, url_template, public_name, reserved, created_at, updated_at, deleted) @@ -25,7 +25,7 @@ select setval('frontends_id_seq', (select max(id) from frontends)); drop table frontends_old; alter index frontends_pkey1 rename to frontends_pkey; -alter index frontends_public_name_key1 to frontends_public_name_key; -alter index frontends_token_key1 to frontends_token_key; +alter index frontends_public_name_key1 rename to frontends_public_name_key; +alter index frontends_token_key1 rename to frontends_token_key; alter table frontends rename constraint frontends_environment_id_fkey1 to frontends_environment_id_fkey;