From 47fba6c947ab15fdb8149c3ea03279c8fac19814 Mon Sep 17 00:00:00 2001 From: Aaron Ji Date: Mon, 19 Jun 2023 11:01:37 +0800 Subject: [PATCH] fix apollo that config update failed while without apollo.WithOriginalConfig option --- contrib/config/apollo/watcher.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/contrib/config/apollo/watcher.go b/contrib/config/apollo/watcher.go index ad8424209..b97f71c01 100644 --- a/contrib/config/apollo/watcher.go +++ b/contrib/config/apollo/watcher.go @@ -25,20 +25,23 @@ type customChangeListener struct { func (c *customChangeListener) onChange(namespace string, changes map[string]*storage.ConfigChange) []*config.KeyValue { kv := make([]*config.KeyValue, 0, 2) - if strings.Contains(namespace, ".") && !strings.HasSuffix(namespace, "."+properties) && - (format(namespace) == yaml || format(namespace) == yml || format(namespace) == json) { - value, err := c.apollo.client.GetConfigCache(namespace).Get("content") - if err != nil { - log.Warnw("apollo get config failed", "err", err) - return nil + if c.apollo.opt.originConfig { + if strings.Contains(namespace, ".") && !strings.HasSuffix(namespace, "."+properties) && + (format(namespace) == yaml || format(namespace) == yml || format(namespace) == json) { + value, err := c.apollo.client.GetConfigCache(namespace).Get("content") + if err != nil { + log.Errorw("apollo get config failed, be aware that apollo should enable \"apollo.WithOriginalConfig()\" option", "err", err) + return nil + } else { + kv = append(kv, &config.KeyValue{ + Key: namespace, + Value: []byte(value.(string)), + Format: format(namespace), + }) + + return kv + } } - kv = append(kv, &config.KeyValue{ - Key: namespace, - Value: []byte(value.(string)), - Format: format(namespace), - }) - - return kv } next := make(map[string]interface{})