@@ -111,11 +111,26 @@ type (
111111 MuxTransports []MuxTransportConfig `yaml:"mux"`
112112 HealthCheck * HealthCheckConfig `yaml:"healthCheck"`
113113 NamespaceNameTranslation NameTranslationConfig `yaml:"namespaceNameTranslation"`
114- SearchAttributeTranslation NameTranslationConfig `yaml:"searchAttributeTranslation"`
114+ SearchAttributeTranslation SATranslationConfig `yaml:"searchAttributeTranslation"`
115115 Metrics * MetricsConfig `yaml:"metrics"`
116116 ProfilingConfig ProfilingConfig `yaml:"profiling"`
117117 }
118118
119+ SATranslationConfig struct {
120+ NamespaceMappings []SANamespaceMapping `yaml:"namespaceMappings"`
121+ }
122+
123+ SANamespaceMapping struct {
124+ Name string `yaml:"name"`
125+ NamespaceId string `yaml:"namespaceId"`
126+ Mappings []SAMapping `yaml:"mappings"`
127+ }
128+
129+ SAMapping struct {
130+ LocalName string `yaml:"localFieldName"`
131+ RemoteName string `yaml:"remoteFieldName"`
132+ }
133+
119134 ProfilingConfig struct {
120135 PProfHTTPAddress string `yaml:"pprofAddress"`
121136 }
@@ -320,3 +335,36 @@ func (c *ProfilingConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
320335 type plain ProfilingConfig
321336 return unmarshal ((* plain )(c ))
322337}
338+
339+ func (s SATranslationConfig ) IsEnabled () bool {
340+ return len (s .NamespaceMappings ) > 0
341+ }
342+
343+ // ToMaps returns request and response mappings.
344+ func (s SATranslationConfig ) ToMaps (inBound bool ) (map [string ]map [string ]string , map [string ]map [string ]string ) {
345+ reqMap := make (map [string ]map [string ]string )
346+ respMap := make (map [string ]map [string ]string )
347+ for _ , ns := range s .NamespaceMappings {
348+ reqMap [ns .NamespaceId ] = make (map [string ]string , len (ns .Mappings ))
349+ respMap [ns .NamespaceId ] = make (map [string ]string , len (ns .Mappings ))
350+
351+ if inBound {
352+ // For inbound listener,
353+ // - incoming requests from remote server are modifed to match local server
354+ // - outgoing responses to local server are modified to match remote server
355+ for _ , tr := range ns .Mappings {
356+ reqMap [ns.NamespaceId ][tr.RemoteName ] = tr .LocalName
357+ respMap [ns.NamespaceId ][tr.LocalName ] = tr .RemoteName
358+ }
359+ } else {
360+ // For outbound listener,
361+ // - incoming requests from local server are modifed to match remote server
362+ // - outgoing responses to remote server are modified to match local server
363+ for _ , tr := range ns .Mappings {
364+ reqMap [ns.NamespaceId ][tr.LocalName ] = tr .RemoteName
365+ respMap [ns.NamespaceId ][tr.RemoteName ] = tr .LocalName
366+ }
367+ }
368+ }
369+ return reqMap , respMap
370+ }
0 commit comments