@@ -23,12 +23,18 @@ import { ClientStatusResponse } from "./generated/envoy/service/status/v3/Client
23
23
import { Timestamp } from "./generated/google/protobuf/Timestamp" ;
24
24
import { AdsTypeUrl , CDS_TYPE_URL_V2 , CDS_TYPE_URL_V3 , EDS_TYPE_URL_V2 , EDS_TYPE_URL_V3 , LDS_TYPE_URL_V2 , LDS_TYPE_URL_V3 , RDS_TYPE_URL_V2 , RDS_TYPE_URL_V3 } from "./resources" ;
25
25
import { HandleResponseResult } from "./xds-stream-state/xds-stream-state" ;
26
- import { sendUnaryData , ServerDuplexStream , ServerUnaryCall , status , experimental , loadPackageDefinition } from '@grpc/grpc-js' ;
26
+ import { sendUnaryData , ServerDuplexStream , ServerUnaryCall , status , experimental , loadPackageDefinition , logVerbosity } from '@grpc/grpc-js' ;
27
27
import { loadSync } from "@grpc/proto-loader" ;
28
28
import { ProtoGrpcType as CsdsProtoGrpcType } from "./generated/csds" ;
29
29
30
30
import registerAdminService = experimental . registerAdminService ;
31
31
32
+ const TRACER_NAME = 'csds' ;
33
+
34
+ function trace ( text : string ) : void {
35
+ experimental . trace ( logVerbosity . DEBUG , TRACER_NAME , text ) ;
36
+ }
37
+
32
38
33
39
function dateToProtoTimestamp ( date ?: Date | null ) : Timestamp | null {
34
40
if ( ! date ) {
@@ -72,7 +78,8 @@ export function setCsdsClientNode(node: Node) {
72
78
* @param typeUrl The resource type URL
73
79
* @param names The list of resource names that are being requested
74
80
*/
75
- export function updateRequestedNameList ( typeUrl : AdsTypeUrl , names : string [ ] ) {
81
+ export function updateCsdsRequestedNameList ( typeUrl : AdsTypeUrl , names : string [ ] ) {
82
+ trace ( 'Update type URL ' + typeUrl + ' with names [' + names + ']' ) ;
76
83
const currentTime = dateToProtoTimestamp ( new Date ( ) ) ;
77
84
const configMap = configStatus [ typeUrl ] ;
78
85
for ( const name of names ) {
@@ -100,12 +107,13 @@ export function updateRequestedNameList(typeUrl: AdsTypeUrl, names: string[]) {
100
107
* @param versionInfo The version info field from this response
101
108
* @param updates The lists of resources that passed and failed validation
102
109
*/
103
- export function updateResourceResponse ( typeUrl : AdsTypeUrl , versionInfo : string , updates : HandleResponseResult ) {
110
+ export function updateCsdsResourceResponse ( typeUrl : AdsTypeUrl , versionInfo : string , updates : HandleResponseResult ) {
104
111
const currentTime = dateToProtoTimestamp ( new Date ( ) ) ;
105
112
const configMap = configStatus [ typeUrl ] ;
106
113
for ( const { name, raw} of updates . accepted ) {
107
114
const mapEntry = configMap . get ( name ) ;
108
115
if ( mapEntry ) {
116
+ trace ( 'Updated ' + typeUrl + ' resource ' + name + ' to state ACKED' ) ;
109
117
mapEntry . client_status = 'ACKED' ;
110
118
mapEntry . version_info = versionInfo ;
111
119
mapEntry . xds_config = raw ;
@@ -116,6 +124,7 @@ export function updateResourceResponse(typeUrl: AdsTypeUrl, versionInfo: string,
116
124
for ( const { name, error, raw} of updates . rejected ) {
117
125
const mapEntry = configMap . get ( name ) ;
118
126
if ( mapEntry ) {
127
+ trace ( 'Updated ' + typeUrl + ' resource ' + name + ' to state NACKED' ) ;
119
128
mapEntry . client_status = 'NACKED' ;
120
129
mapEntry . error_state = {
121
130
failed_configuration : raw ,
@@ -128,6 +137,7 @@ export function updateResourceResponse(typeUrl: AdsTypeUrl, versionInfo: string,
128
137
for ( const name of updates . missing ) {
129
138
const mapEntry = configMap . get ( name ) ;
130
139
if ( mapEntry ) {
140
+ trace ( 'Updated ' + typeUrl + ' resource ' + name + ' to state DOES_NOT_EXIST' ) ;
131
141
mapEntry . client_status = 'DOES_NOT_EXIST' ;
132
142
mapEntry . version_info = versionInfo ;
133
143
mapEntry . xds_config = null ;
@@ -144,16 +154,18 @@ function getCurrentConfig(): ClientConfig {
144
154
genericConfigList . push ( configValue ) ;
145
155
}
146
156
}
147
- return {
157
+ const config = {
148
158
node : clientNode ,
149
159
generic_xds_configs : genericConfigList
150
160
} ;
161
+ trace ( 'Sending curent config ' + JSON . stringify ( config , undefined , 2 ) ) ;
162
+ return config ;
151
163
}
152
164
153
165
const csdsImplementation : ClientStatusDiscoveryServiceHandlers = {
154
166
FetchClientStatus ( call : ServerUnaryCall < ClientStatusRequest__Output , ClientStatusResponse > , callback : sendUnaryData < ClientStatusResponse > ) {
155
167
const request = call . request ;
156
- if ( request . node_matchers !== null ) {
168
+ if ( request . node_matchers . length > 0 ) {
157
169
callback ( {
158
170
code : status . INVALID_ARGUMENT ,
159
171
details : 'Node matchers not supported'
@@ -166,7 +178,7 @@ const csdsImplementation: ClientStatusDiscoveryServiceHandlers = {
166
178
} ,
167
179
StreamClientStatus ( call : ServerDuplexStream < ClientStatusRequest__Output , ClientStatusResponse > ) {
168
180
call . on ( 'data' , ( request : ClientStatusRequest__Output ) => {
169
- if ( request . node_matchers !== null ) {
181
+ if ( request . node_matchers . length > 0 ) {
170
182
call . emit ( 'error' , {
171
183
code : status . INVALID_ARGUMENT ,
172
184
details : 'Node matchers not supported'
0 commit comments