Skip to content

Commit

Permalink
Fix nats-jetstream scaler to use account ID instead of name
Browse files Browse the repository at this point in the history
Signed-off-by: Camille Dela Rosa <[email protected]>
  • Loading branch information
cmay-zh committed Dec 11, 2024
1 parent 88ddc39 commit 0dfc2e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions pkg/scalers/nats_jetstream_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type jetStreamCluster struct {
}

type accountDetail struct {
Id string `json:id`
Name string `json:"name"`
Streams []*streamDetail `json:"stream_detail"`
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/scalers/nats_jetstream_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
}},
Expand All @@ -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}},
}},
Expand All @@ -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}},
}},
Expand All @@ -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}},
}},
Expand All @@ -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}},
}},
Expand All @@ -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"}}},
}},
Expand All @@ -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},
Expand Down

0 comments on commit 0dfc2e5

Please sign in to comment.