From 0dfc2e572bcf672de5de7f75409064f3a459185b Mon Sep 17 00:00:00 2001 From: Camille Dela Rosa Date: Wed, 11 Dec 2024 14:55:56 +1100 Subject: [PATCH 1/6] Fix nats-jetstream scaler to use account ID instead of name Signed-off-by: Camille Dela Rosa --- CHANGELOG.md | 1 + pkg/scalers/nats_jetstream_scaler.go | 5 +++-- pkg/scalers/nats_jetstream_scaler_test.go | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e85235b4e1..43521d4e50c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,7 @@ New deprecation(s): - **AWS SQS Scaler**: Improve error handling for SQS queue metrics ([#6178](https://github.com/kedacore/keda/issues/6178)) - **Azure Event Hub Scaler**: Checkpointer errors are correctly handled ([#6084](https://github.com/kedacore/keda/issues/6084)) - **Metrics API Scaler**: Prometheus metrics can have multiple labels ([#6077](https://github.com/kedacore/keda/issues/6077)) +- **JetStream**: NATS API uses account ID and not account name to filter by account ### Deprecations diff --git a/pkg/scalers/nats_jetstream_scaler.go b/pkg/scalers/nats_jetstream_scaler.go index 47a0bbe1f36..d4fa6943ef2 100644 --- a/pkg/scalers/nats_jetstream_scaler.go +++ b/pkg/scalers/nats_jetstream_scaler.go @@ -64,6 +64,7 @@ type jetStreamCluster struct { } type accountDetail struct { + Id string `json:id` Name string `json:"name"` Streams []*streamDetail `json:"stream_detail"` } @@ -278,7 +279,7 @@ func (s *natsJetStreamScaler) getNATSJetstreamMonitoringData(ctx context.Context } for _, jetStreamAccount := range jetStreamAccountResp.Accounts { - if jetStreamAccount.Name == s.metadata.account { + if jetStreamAccount.Id == s.metadata.account { for _, stream := range jetStreamAccount.Streams { if stream.Name == s.metadata.stream { for _, consumer := range stream.Consumers { @@ -305,7 +306,7 @@ func (s *natsJetStreamScaler) setNATSJetStreamMonitoringData(jetStreamAccountRes // find and assign the stream that we are looking for. for _, jsAccount := range jetStreamAccountResp.Accounts { - if jsAccount.Name == s.metadata.account { + if jsAccount.Id == s.metadata.account { for _, stream := range jsAccount.Streams { if stream.Name == s.metadata.stream { s.stream = stream diff --git a/pkg/scalers/nats_jetstream_scaler_test.go b/pkg/scalers/nats_jetstream_scaler_test.go index c77811011f7..3ba765896e2 100644 --- a/pkg/scalers/nats_jetstream_scaler_test.go +++ b/pkg/scalers/nats_jetstream_scaler_test.go @@ -131,7 +131,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer"}}, }}, @@ -145,7 +145,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -159,7 +159,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystream", State: streamState{LastSequence: 1}, Consumers: []consumerDetail{{Name: "pull_consumer_bad", NumPending: 100}}, }}, @@ -173,7 +173,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystreamBad", State: streamState{LastSequence: 1}, Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -187,7 +187,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -202,7 +202,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ }, &jetStreamEndpointResponse{ MetaCluster: metaCluster{ClusterSize: 3}, - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100, Cluster: consumerCluster{Leader: "leader"}}}, }}, @@ -217,7 +217,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ }, &jetStreamEndpointResponse{ MetaCluster: metaCluster{ClusterSize: 3}, - Accounts: []accountDetail{{Name: "$G", + Accounts: []accountDetail{{Name: "$G", Id: "$G", Streams: []*streamDetail{{Name: "mystream"}}, }}, }, false, true}, From a1b26f7d45309b6d6a29635c08222af27fd14602 Mon Sep 17 00:00:00 2001 From: Camille Dela Rosa Date: Wed, 11 Dec 2024 15:14:51 +1100 Subject: [PATCH 2/6] fix validate issue Signed-off-by: Camille Dela Rosa --- pkg/scalers/nats_jetstream_scaler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/scalers/nats_jetstream_scaler.go b/pkg/scalers/nats_jetstream_scaler.go index d4fa6943ef2..a0159c57366 100644 --- a/pkg/scalers/nats_jetstream_scaler.go +++ b/pkg/scalers/nats_jetstream_scaler.go @@ -64,7 +64,7 @@ type jetStreamCluster struct { } type accountDetail struct { - Id string `json:id` + Id string `json:"id"` Name string `json:"name"` Streams []*streamDetail `json:"stream_detail"` } From 29ea05a63ac08a62651925801bc6aa86468c6bcd Mon Sep 17 00:00:00 2001 From: Camille Dela Rosa Date: Wed, 11 Dec 2024 15:24:41 +1100 Subject: [PATCH 3/6] fix lint Signed-off-by: Camille Dela Rosa --- pkg/scalers/nats_jetstream_scaler.go | 6 +++--- pkg/scalers/nats_jetstream_scaler_test.go | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/scalers/nats_jetstream_scaler.go b/pkg/scalers/nats_jetstream_scaler.go index a0159c57366..33b8b7b08be 100644 --- a/pkg/scalers/nats_jetstream_scaler.go +++ b/pkg/scalers/nats_jetstream_scaler.go @@ -64,7 +64,7 @@ type jetStreamCluster struct { } type accountDetail struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` Streams []*streamDetail `json:"stream_detail"` } @@ -279,7 +279,7 @@ func (s *natsJetStreamScaler) getNATSJetstreamMonitoringData(ctx context.Context } for _, jetStreamAccount := range jetStreamAccountResp.Accounts { - if jetStreamAccount.Id == s.metadata.account { + if jetStreamAccount.ID == s.metadata.account { for _, stream := range jetStreamAccount.Streams { if stream.Name == s.metadata.stream { for _, consumer := range stream.Consumers { @@ -306,7 +306,7 @@ func (s *natsJetStreamScaler) setNATSJetStreamMonitoringData(jetStreamAccountRes // find and assign the stream that we are looking for. for _, jsAccount := range jetStreamAccountResp.Accounts { - if jsAccount.Id == s.metadata.account { + if jsAccount.ID == s.metadata.account { for _, stream := range jsAccount.Streams { if stream.Name == s.metadata.stream { s.stream = stream diff --git a/pkg/scalers/nats_jetstream_scaler_test.go b/pkg/scalers/nats_jetstream_scaler_test.go index 3ba765896e2..eb0a71f22e1 100644 --- a/pkg/scalers/nats_jetstream_scaler_test.go +++ b/pkg/scalers/nats_jetstream_scaler_test.go @@ -131,7 +131,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer"}}, }}, @@ -145,7 +145,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -159,7 +159,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", State: streamState{LastSequence: 1}, Consumers: []consumerDetail{{Name: "pull_consumer_bad", NumPending: 100}}, }}, @@ -173,7 +173,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystreamBad", State: streamState{LastSequence: 1}, Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -187,7 +187,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -202,7 +202,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ }, &jetStreamEndpointResponse{ MetaCluster: metaCluster{ClusterSize: 3}, - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100, Cluster: consumerCluster{Leader: "leader"}}}, }}, @@ -217,7 +217,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ }, &jetStreamEndpointResponse{ MetaCluster: metaCluster{ClusterSize: 3}, - Accounts: []accountDetail{{Name: "$G", Id: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream"}}, }}, }, false, true}, From 28caa4e3697966a05c993c68def203c2ce4af4be Mon Sep 17 00:00:00 2001 From: Camille Dela Rosa Date: Wed, 11 Dec 2024 15:25:56 +1100 Subject: [PATCH 4/6] add PR in changelog Signed-off-by: Camille Dela Rosa --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43521d4e50c..7f6b476e5db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,7 +139,7 @@ New deprecation(s): - **AWS SQS Scaler**: Improve error handling for SQS queue metrics ([#6178](https://github.com/kedacore/keda/issues/6178)) - **Azure Event Hub Scaler**: Checkpointer errors are correctly handled ([#6084](https://github.com/kedacore/keda/issues/6084)) - **Metrics API Scaler**: Prometheus metrics can have multiple labels ([#6077](https://github.com/kedacore/keda/issues/6077)) -- **JetStream**: NATS API uses account ID and not account name to filter by account +- **JetStream**: NATS API uses account ID and not account name to filter by account ([#6415] (https://github.com/kedacore/keda/pull/6415)) ### Deprecations From 6132ab906bbe50e4128d7c53e419523e77ae6f40 Mon Sep 17 00:00:00 2001 From: Camille Dela Rosa Date: Wed, 11 Dec 2024 15:44:32 +1100 Subject: [PATCH 5/6] pre-commit Signed-off-by: Camille Dela Rosa --- CHANGELOG.md | 2 +- pkg/scalers/nats_jetstream_scaler_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f6b476e5db..83b23ebb4b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -138,8 +138,8 @@ New deprecation(s): - **AWS Secret Manager**: Pod identity overrides are honored ([#6195](https://github.com/kedacore/keda/issues/6195)) - **AWS SQS Scaler**: Improve error handling for SQS queue metrics ([#6178](https://github.com/kedacore/keda/issues/6178)) - **Azure Event Hub Scaler**: Checkpointer errors are correctly handled ([#6084](https://github.com/kedacore/keda/issues/6084)) -- **Metrics API Scaler**: Prometheus metrics can have multiple labels ([#6077](https://github.com/kedacore/keda/issues/6077)) - **JetStream**: NATS API uses account ID and not account name to filter by account ([#6415] (https://github.com/kedacore/keda/pull/6415)) +- **Metrics API Scaler**: Prometheus metrics can have multiple labels ([#6077](https://github.com/kedacore/keda/issues/6077)) ### Deprecations diff --git a/pkg/scalers/nats_jetstream_scaler_test.go b/pkg/scalers/nats_jetstream_scaler_test.go index eb0a71f22e1..8c35c4ad0c0 100644 --- a/pkg/scalers/nats_jetstream_scaler_test.go +++ b/pkg/scalers/nats_jetstream_scaler_test.go @@ -131,7 +131,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer"}}, }}, @@ -145,7 +145,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -159,7 +159,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", State: streamState{LastSequence: 1}, Consumers: []consumerDetail{{Name: "pull_consumer_bad", NumPending: 100}}, }}, @@ -173,7 +173,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystreamBad", State: streamState{LastSequence: 1}, Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -187,7 +187,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ 0, "s0-nats-jetstream-mystream", }, &jetStreamEndpointResponse{ - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100}}, }}, @@ -202,7 +202,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ }, &jetStreamEndpointResponse{ MetaCluster: metaCluster{ClusterSize: 3}, - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream", Consumers: []consumerDetail{{Name: "pull_consumer", NumPending: 100, Cluster: consumerCluster{Leader: "leader"}}}, }}, @@ -217,7 +217,7 @@ var testNATSJetStreamMockResponses = []parseNATSJetStreamMockResponsesTestData{ }, &jetStreamEndpointResponse{ MetaCluster: metaCluster{ClusterSize: 3}, - Accounts: []accountDetail{{Name: "$G", ID: "$G", + Accounts: []accountDetail{{Name: "$G", ID: "$G", Streams: []*streamDetail{{Name: "mystream"}}, }}, }, false, true}, From d39294430149118cf58e00d3006eee8d761286ac Mon Sep 17 00:00:00 2001 From: Camille Dela Rosa Date: Wed, 11 Dec 2024 16:54:02 +1100 Subject: [PATCH 6/6] fix changelog pattern Signed-off-by: Camille Dela Rosa --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83b23ebb4b1..f5202b69244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -138,7 +138,7 @@ New deprecation(s): - **AWS Secret Manager**: Pod identity overrides are honored ([#6195](https://github.com/kedacore/keda/issues/6195)) - **AWS SQS Scaler**: Improve error handling for SQS queue metrics ([#6178](https://github.com/kedacore/keda/issues/6178)) - **Azure Event Hub Scaler**: Checkpointer errors are correctly handled ([#6084](https://github.com/kedacore/keda/issues/6084)) -- **JetStream**: NATS API uses account ID and not account name to filter by account ([#6415] (https://github.com/kedacore/keda/pull/6415)) +- **JetStream**: NATS API uses account ID and not account name to filter by account ([#6415](https://github.com/kedacore/keda/pull/6415)) - **Metrics API Scaler**: Prometheus metrics can have multiple labels ([#6077](https://github.com/kedacore/keda/issues/6077)) ### Deprecations