Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nats-jetstream scaler to use account ID instead of name #6415

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +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))
- **Metrics API Scaler**: Prometheus metrics can have multiple labels ([#6077](https://github.com/kedacore/keda/issues/6077))

### 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
Loading