|
7 | 7 | discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
|
8 | 8 |
|
9 | 9 | "github.com/openservicemesh/osm/pkg/envoy"
|
| 10 | + "github.com/openservicemesh/osm/pkg/messaging" |
10 | 11 | "github.com/openservicemesh/osm/pkg/metricsstore"
|
11 | 12 | "github.com/openservicemesh/osm/pkg/utils"
|
12 | 13 | )
|
@@ -44,18 +45,59 @@ func (s *Server) OnStreamOpen(ctx context.Context, streamID int64, typ string) e
|
44 | 45 | }
|
45 | 46 |
|
46 | 47 | s.proxyRegistry.RegisterProxy(proxy)
|
| 48 | + go func() { |
| 49 | + // Register for proxy config updates broadcasted by the message broker |
| 50 | + proxyUpdatePubSub := s.msgBroker.GetProxyUpdatePubSub() |
| 51 | + proxyUpdateChan := proxyUpdatePubSub.Sub(messaging.ProxyUpdateTopic, messaging.GetPubSubTopicForProxyUUID(proxy.UUID.String())) |
| 52 | + defer s.msgBroker.Unsub(proxyUpdatePubSub, proxyUpdateChan) |
| 53 | + |
| 54 | + certRotations, unsubRotations := s.certManager.SubscribeRotations(proxy.Identity.String()) |
| 55 | + defer unsubRotations() |
| 56 | + |
| 57 | + for { |
| 58 | + select { |
| 59 | + case <-proxyUpdateChan: |
| 60 | + log.Debug().Str("proxy", proxy.String()).Msg("Broadcast update received") |
| 61 | + s.update(proxy) |
| 62 | + case <-certRotations: |
| 63 | + log.Debug().Str("proxy", proxy.String()).Msg("Certificate has been updated for proxy") |
| 64 | + s.update(proxy) |
| 65 | + case <-ctx.Done(): |
| 66 | + return |
| 67 | + } |
| 68 | + } |
| 69 | + }() |
47 | 70 | return nil
|
48 | 71 | }
|
49 | 72 |
|
| 73 | +func (s *Server) update(proxy *envoy.Proxy) { |
| 74 | + ch := s.workqueues.AddJob(&proxyResponseJob{ |
| 75 | + proxy: proxy, |
| 76 | + xdsServer: s, |
| 77 | + typeURIs: envoy.XDSResponseOrder, |
| 78 | + done: make(chan struct{}), |
| 79 | + }) |
| 80 | + <-ch |
| 81 | + close(ch) |
| 82 | +} |
| 83 | + |
50 | 84 | // OnStreamClosed is called on stream closed
|
51 | 85 | func (s *Server) OnStreamClosed(streamID int64) {
|
52 | 86 | log.Debug().Msgf("OnStreamClosed id: %d", streamID)
|
53 | 87 | s.proxyRegistry.UnregisterProxy(streamID)
|
| 88 | + |
| 89 | + metricsstore.DefaultMetricsStore.ProxyConnectCount.Dec() |
54 | 90 | }
|
55 | 91 |
|
56 |
| -// OnStreamRequest is called when a request happens on an open string |
57 |
| -func (s *Server) OnStreamRequest(a int64, req *discovery.DiscoveryRequest) error { |
| 92 | +// OnStreamRequest is called when a request happens on an open connection |
| 93 | +func (s *Server) OnStreamRequest(streamID int64, req *discovery.DiscoveryRequest) error { |
58 | 94 | log.Debug().Msgf("OnStreamRequest node: %s, type: %s, v: %s, nonce: %s, resNames: %s", req.Node.Id, req.TypeUrl, req.VersionInfo, req.ResponseNonce, req.ResourceNames)
|
| 95 | + |
| 96 | + proxy := s.proxyRegistry.GetConnectedProxy(streamID) |
| 97 | + if proxy != nil { |
| 98 | + metricsstore.DefaultMetricsStore.ProxyXDSRequestCount.WithLabelValues(proxy.UUID.String(), proxy.Identity.String(), req.TypeUrl).Inc() |
| 99 | + } |
| 100 | + |
59 | 101 | return nil
|
60 | 102 | }
|
61 | 103 |
|
|
0 commit comments