From d7dea230365e88643dd6a352e23b671022d2b960 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 13 Jan 2024 22:00:55 +0100 Subject: [PATCH] Don't rely on subscription configuration to get subscription name When using the API directly, there is not subscription configuration (it is set in the app module) and we cannot use it to get the name. Instead, use the name provided in the function call. This is a regression introduced in #331. --- pkg/target/subscribe.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/target/subscribe.go b/pkg/target/subscribe.go index cd82d443..b8b0d740 100644 --- a/pkg/target/subscribe.go +++ b/pkg/target/subscribe.go @@ -68,7 +68,7 @@ SUBSC: switch req.GetSubscribe().GetMode() { case gnmi.SubscriptionList_STREAM: - err = t.handleStreamSubscriptionRcv(nctx, subscribeClient, subConfig) + err = t.handleStreamSubscriptionRcv(nctx, subscribeClient, subscriptionName, subConfig) if err != nil { t.errors <- &TargetError{ SubscriptionName: subscriptionName, @@ -83,7 +83,7 @@ SUBSC: goto SUBSC } case gnmi.SubscriptionList_ONCE: - err = t.handleONCESubscriptionRcv(nctx, subscribeClient, subConfig) + err = t.handleONCESubscriptionRcv(nctx, subscribeClient, subscriptionName, subConfig) if err != nil { t.errors <- &TargetError{ SubscriptionName: subscriptionName, @@ -103,7 +103,7 @@ SUBSC: return case gnmi.SubscriptionList_POLL: go t.listenPolls(nctx) - err = t.handlePollSubscriptionRcv(nctx, subscribeClient, subConfig) + err = t.handlePollSubscriptionRcv(nctx, subscribeClient, subscriptionName, subConfig) if err != nil { t.errors <- &TargetError{ SubscriptionName: subscriptionName, @@ -257,7 +257,7 @@ func (t *Target) listenPolls(ctx context.Context) { } } -func (t *Target) handleStreamSubscriptionRcv(ctx context.Context, stream gnmi.GNMI_SubscribeClient, subConfig *types.SubscriptionConfig) error { +func (t *Target) handleStreamSubscriptionRcv(ctx context.Context, stream gnmi.GNMI_SubscribeClient, subscriptionName string, subConfig *types.SubscriptionConfig) error { for { if ctx.Err() != nil { return nil @@ -267,14 +267,14 @@ func (t *Target) handleStreamSubscriptionRcv(ctx context.Context, stream gnmi.GN return err } t.subscribeResponses <- &SubscribeResponse{ - SubscriptionName: subConfig.Name, + SubscriptionName: subscriptionName, SubscriptionConfig: subConfig, Response: response, } } } -func (t *Target) handleONCESubscriptionRcv(ctx context.Context, stream gnmi.GNMI_SubscribeClient, subConfig *types.SubscriptionConfig) error { +func (t *Target) handleONCESubscriptionRcv(ctx context.Context, stream gnmi.GNMI_SubscribeClient, subscriptionName string, subConfig *types.SubscriptionConfig) error { for { if ctx.Err() != nil { return nil @@ -284,7 +284,7 @@ func (t *Target) handleONCESubscriptionRcv(ctx context.Context, stream gnmi.GNMI return err } t.subscribeResponses <- &SubscribeResponse{ - SubscriptionName: subConfig.Name, + SubscriptionName: subscriptionName, SubscriptionConfig: subConfig, Response: response, } @@ -295,7 +295,7 @@ func (t *Target) handleONCESubscriptionRcv(ctx context.Context, stream gnmi.GNMI } } -func (t *Target) handlePollSubscriptionRcv(ctx context.Context, stream gnmi.GNMI_SubscribeClient, subConfig *types.SubscriptionConfig) error { +func (t *Target) handlePollSubscriptionRcv(ctx context.Context, stream gnmi.GNMI_SubscribeClient, subscriptionName string, subConfig *types.SubscriptionConfig) error { for { select { case <-ctx.Done(): @@ -306,7 +306,7 @@ func (t *Target) handlePollSubscriptionRcv(ctx context.Context, stream gnmi.GNMI return err } t.subscribeResponses <- &SubscribeResponse{ - SubscriptionName: subConfig.Name, + SubscriptionName: subscriptionName, SubscriptionConfig: subConfig, Response: response, }