華爲雲物聯網四年配置中心實踐

{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"自17年入職華爲之後,一直在使用配置中心,4年期間經歷了自研配置中心到Apollo再到自研配置中心和Apollo並存的場景。總結了一下這幾年的配置中心演進流程,想把我們在配置中心上的一些實踐分享給大家,實現共同進步。Apollo是一款非常優秀的開源軟件,如果對Apollo存在理解錯誤,還望大家不吝賜教,謝謝。"}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"使用到的配置分類"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"從場景分類"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"運維配置,即程序只讀的配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"人工配置。通過人工在配置中心界面進行配置,而程序只進行讀取,如數據庫配置、郵箱服務器配置、網卡配置、子網地址配置等。這部分配置數據不要求代碼動態寫入。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"業務配置,即程序可寫的配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們是一個SaaS服務,每個用戶在上面都有一些業務配置。如用戶的證書配置、用戶服務器的流控配置等,這些業務配置相對"},{"type":"text","marks":[{"type":"strong"}],"text":"運維配置"},{"type":"text","text":"來說更加複雜,且可能會有唯一性限制,如按用戶id唯一。這部分配置數據一般由用戶操作觸發,代碼動態寫入,並且通知到各個微服務實例。通常,我們希望這些配置能在界面展示,且支持人爲修改。上述邏輯如果由各微服務自己實現,會存在大量重複代碼,並且質量無法保證。我們希望由一個公共組件來統一實現這個能力。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"從配置是否會有列表可分爲單值配置或多值配置"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"單值配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"整個配置下只是多對key、value。value不是很複雜的格式,往往是整數或字符串。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/ba\/bae99c658b7422d22b354cfcb09b50ad.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"多值配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"多值配置更加複雜,往往是"},{"type":"text","marks":[{"type":"strong"}],"text":"單值配置"},{"type":"text","text":"在不同的key下,有不同的值。比如下面的配置,用戶一和用戶二的線程池大小和隊列不同"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/98\/98a9f191c88020240bac327f5ff2dad0.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"第一階段自研配置中心"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在做雲服務之前,我們的配置中心層級數較少。我們以軟件的形式交付給客戶,軟件運行時分爲管理面和業務面,配置中心管理着管理面和業務面的配置,最爲複雜的場景是多套業務面,這個時候需要保證不同集羣、不同微服務下的配置不衝突,配置層級爲集羣、微服務、配置。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/af\/afc0972e1657687dfb54de2bc9a1c43f.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此時的配置中心是完全自研的,不包含藍綠、灰度配置這些功能,它獨具特色的地方有以下兩點:"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"單配置單表"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在存儲模型上,每個配置對應一張數據表。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對多值配置比較友好,尤其是複雜業務配置,可以支持各種主鍵約束。對單值配置,稍微重型了一些。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"配置的強Schema限制。這些限制包括類型、大小、長度、是否敏感等限制。這種限制既能爲界面修改配置提供良好的體驗(如:不同格式不同的輸入框、敏感字段,前臺輸入明文,後臺入庫加密等),也能在通過接口寫入配置時做充分的校驗。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"通過回調方式來確保配置的可靠"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"舉個例子,添加一個配置的流程是這樣的"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/4e\/4e057fc7e6492f407937708a2b392e6f.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可能這裏,有讀者想要問了,這個流程能確保什麼可靠呢。這個流程通過調用微服務接口來校驗配置是否可靠,如IP地址是否合法、對端地址是否可達、配置數量是否超過規格等等,來保證配置基本可用。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"總的來說,這個自研的配置中心在當時綜合體驗還是不錯的。但是也有一些問題有待改進,比如單配置下配置項數量過多時,因爲底層有部分接口單配置下所有數據都通過一個http請求來承載,會導致響應超時等問題。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"第二階段Apollo"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"開始第二階段實踐的原因主要是,我們進行了組織切換,業務重心轉向做雲服務,同時團隊進行DevOps轉型。原先的老配置中心是由另一個團隊維護的,組織切換完之後,如果還要使用,就要我們自己維護。所以我們需要在繼續維護老配置中心和引入開源Apollo中間進行選擇。除了上文中提到的運維配置和業務配置,這個時候我們的需求還有改變:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"配置的層級愈發豐富了"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"要構建灰度發佈微服務的能力"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"老配置中心一方面由於組織切換原因不提供維護了,另一方面不能支撐豐富的配置層級,也不具備灰度發佈的能力。這個時候,Apollo的一些特性吸引了我們,這些特性正是老配置中心所缺乏的,例如(部分引用自Apollogithub主頁)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"豐富的層級,從app_id到cluster,namespace,key-value的層級能滿足我們region、集羣、微服務的層級訴求;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"支持配置的灰度發佈,比如點了發佈後,只對部分應用實例生效,等觀察一段時間沒問題後再推給所有應用實例;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所有的配置發佈都有版本概念,從而可以方便的支持配置的回滾;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"應用和配置的管理都有完善的權限管理機制,對配置的管理還分爲了編輯和發佈兩個環節,從而減少人爲的錯誤;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所有的操作都有審計日誌,可以方便的追蹤問題。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此我們選型引入了Apollo,我和我的主管,還有一個其他同事參與了這項工作。我們在Apollo開源代碼的基礎上做了比較大的改動,主要原因有以下幾點:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"節約成本,將註冊中心、數據庫替換成我們當前正在使用的組件,因爲這兩個依賴不是Apollo的核心依賴"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"繼承老配置中心強Schema的優點"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"保留回調確認配置的流程,提前攔截錯誤的配置,降低代碼處理異常配置的複雜度"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過spi或環境變量的方式兼容存量老局點使用老配置中心的場景"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"結合上述原因,我們最終是這麼實踐的:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據庫切換爲postgre數據庫、註冊中心切換到servicecomb"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在namespace上實現了Schema,每個namespace都可以註冊對應的Schema,Schema要求數據必須是json格式,且json內對應的value必須滿足Schema定義的規範(如ip地址、小數、整數等)"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Schema舉例:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"plain"},"content":[{"type":"text","text":"[\n {\n \"name\":\"name\",\n \"type\":\"string\"\n },\n {\n \"name\":\"age\",\n \"type\":\"int\",\n \"max\":120\n },\n {\n \"name\":\"ip\",\n \"type\":\"ipv4\"\n }\n]\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼數據應該是這樣的:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"plain"},"content":[{"type":"text","text":"{\n \"name\":\"hezhangjian\",\n \"age\":23,\n \"ip\":\"127.0.0.1\"\n}\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在添加或修改配置的時候,實現了回調功能,由回調業務服務確認配置能否添加或修改;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"配置分層:雲服務對應Apollo的app_id,把內部的環境對應到Apollo上的集羣,然後將微服務名+配置名拼接成配置名稱。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下圖展示了業務概念和Apollo概念的對應關係,有些配置是單值配置,有些是多值配置,所以配置項這一層級是可選的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/b4\/b4c398b942ca44675ee8b28e19eb6920.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在這段時間的實踐中,我們也發現瞭如下的一些問題。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"併發問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其中最致命的就是併發問題,首先Apollo所有配置都存在一張表中,其次由於Apollo設計之初主要考慮的是運維人員手動在界面上操作,代碼無併發語義(或者說沒給客戶端併發語義),使得我們通過代碼寫入配置時難以解決併發問題。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"性能問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"打開namespace列表頁面,需要顯示這個app_id下的所有namespace,因爲我們單app_id會存放單個雲服務的所有配置,這個量很大,且界面不支持分頁,導致頁面加載緩慢。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"體驗問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Apollo的namespace界面未提供搜索功能(可能Apollo設計之初也沒想支持這麼多),想要從namespace中定位到我們想要查看或修改的namespace,只能藉助瀏覽器的搜索能力。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"第三階段Apollo與自研配置中心並存"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除了上述幾個問題,還有一些原因使得我們開始了第三階段的實踐:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原來自上而下的配置分層模型,微服務間配置沒隔離,不僅不易進行權限管理,而且不適合DevOps 單微服務自治的發佈理念;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"第二階段對Apollo改動太多,組織結構變動,沒有足夠的人力維護;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"隨着集羣越來越多,回調功能需要網絡的雙向打通,網絡維護不太方便;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們對Apollo界面以及接口基於業務做的改動較多,導致其他兄弟部門難以共用Apollo"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當時大家對是否保留"},{"type":"text","marks":[{"type":"strong"}],"text":"Schema"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"strong"}],"text":"回調檢查"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"strong"}],"text":"代碼寫配置"},{"type":"text","text":"這三個功能點有較大的爭議。我個人最希望保留"},{"type":"text","marks":[{"type":"strong"}],"text":"Schema"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"strong"}],"text":"回調檢查"},{"type":"text","text":",因爲它們優點顯著,而且接口是兼容的,可以與其他部門共用,但是增加了"},{"type":"text","marks":[{"type":"strong"}],"text":"Schema"},{"type":"text","text":"這個概念和"},{"type":"text","marks":[{"type":"strong"}],"text":"回調檢查"},{"type":"text","text":"這個流程,會增加學習成本。而代碼寫配置,由於要解決併發問題,代碼改動量較大,我不建議保留。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大家經過激烈的討論,最終還是廢棄了"},{"type":"text","marks":[{"type":"strong"}],"text":"Schema"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"strong"}],"text":"回調檢查"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"strong"}],"text":"代碼寫配置"},{"type":"text","text":"這三個功能點,僅僅把運維配置放在Apollo。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然後,我們把業務配置,放在了一個自研的強Schema的配置中心上,這個配置中心,僅負責單集羣的配置,每個集羣部署一套,滿足了我們的業務需求。自研強Schema配置中心的核心要點有,單配置單表、通過註冊中心回調來檢測配置是否合法、藉助mqtt協議來實現長鏈接推送,無單點瓶頸。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"而我們的運維配置中心Apollo迴歸到了開源的版本,重整了配置的結構,"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/64\/64e5e1754b607ea975751aad6c63365c.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對運維配置而言好處有:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"配置模型適合單微服務發佈;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"配置按微服務組織,一個頁面上的namespace不會很多。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"缺點:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Schema缺失後,不會對操作人員在界面的配置進行校驗,即使配置格式或者內容錯誤也能配置成功。界面上配置密碼不支持明文(Apollo無法感知是否爲敏感字段),必須提前使用其他工具將明文轉換爲密文,然後再進行配置;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"回調檢查功能去掉後,有些配置,如網卡網段配錯,操作人員不能即時得到響應。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"最佳實踐"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"業務配置經過我們的實踐,確實不適合使用開源的Apollo。運維配置使用原生的Apollo,但是現在還不具備"},{"type":"text","marks":[{"type":"strong"}],"text":"回調檢查"},{"type":"text","text":"和"},{"type":"text","marks":[{"type":"strong"}],"text":"Schema"},{"type":"text","text":"的功能,希望Apollo能在後續版本中支持"},{"type":"text","marks":[{"type":"strong"}],"text":"Schema"},{"type":"text","text":",或者弱化的"},{"type":"text","marks":[{"type":"strong"}],"text":"json"},{"type":"text","text":"格式檢查功能。下面是我們在如下場景下的最佳實踐。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"SRE在界面上的運維配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過Apollo來實現功能,至於配置如何組織,根據大家的組織結構、技術架構來對應Apollo上的概念,可按照微服務->部署環境或部署環境->微服務的層級來組織配置。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"複雜的參數校驗"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"建議在Apollo上面自建portal包裹一層,後端服務可先進行一層處理,這一層處理可以做比較複雜的格式化校驗甚至"},{"type":"text","marks":[{"type":"strong"}],"text":"回調檢查"},{"type":"text","text":",再調用Apollo OpenApi將配置寫入Apollo。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"業務配置的技術選型"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最大的挑戰是業務配置由用戶觸發,請求的併發不易處理。思路有兩個,一個是在Apollo原生代碼的基礎上,通過數據庫分佈式鎖來解決併發問題。第二個是借鑑我們的思路,通過單配置單表、mqtt協議實現通知等核心技術點,自研業務配置中心。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"業務配置的部署"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"需要根據業務配置的數量來考慮是否合設業務配置中心。單集羣場景下,毫無疑問只需要一個業務配置中心,甚至如果使用Apollo實現,可以考慮和運維配置中心合設。多集羣場景下,部署一個業務配置中心,還是多個業務配置中心,我們自己的實踐中,一個集羣往往要支撐數萬用戶,我們採取了每個業務集羣部署一套業務配置中心的策略。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"作者簡介:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"賀張儉,華爲雲IoT高級工程師。關注雲原生、IoT、消息中間件、APM"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章