Skip to content

Latest commit

 

History

History
121 lines (87 loc) · 5.66 KB

configuration-api-with-apollo.md

File metadata and controls

121 lines (87 loc) · 5.66 KB

Implement Configuration API with ctripcorp/apollo

Goals

Implement Configuration API(level-2) with ctripcorp/apollo.

Schema

From Configuration API to apollo schema

The mapping rule is:

Params in Configuration API apollo schema
app_id //ignore it when querying or subscribing,use app_id in config file instead
group namespace
label //append to key. So the actual key stored in apollo will be 'key@$label'
tag // put into another configuration item with json format

The actual key stored in apollo will be key@$label and the value will be raw value.

Tags will be stored in a special namespace sidecar_config_tags,

with key=group@$key@$label and value=

{
  "tag1": "tag1value",
  "tag2": "tag2value"
}

Q: Why not store value and tags in a single configuration item to reduce times of queries,like:

{
    "value":"raw value",
    "tags":{
        "tag1":"tag1value",
        "tag2":"tag2value"
    }
}

A: Legacy systems using apollo can't migrate to our sidecar if we design like this.

How to migrate legacy systems

  1. Get and subscribe APIs are compatible.Users can easily put legacy systems onto our sidecar if they don't use save/delete APIs.Just keep label field blank in config.json,and the sidecar will use the raw key instead of key@$label to interact with apollo.

  2. Save/delete APIs might be incompatible.The sidecar use fixed cluster field configurated in config.json and fixed env field in code,which means users can't pass cluster and env field as a parameter for save/delete API when they want to change some configuration items with other appid.

config.json for sidecar

{
  "config_store": {
    "type": "apollo",
    "address": [
      "http://106.54.227.205:8080"
    ],
    "metadata": {
      "app_id": "testApplication_yang",
      "cluster": "dev",
      "namespace_name": "dubbo,product.joe",
      "is_backup_config": true,
      "secret": "6ce3ff7e96a24335a9634fe9abca6d51"
    }
  }
}

API

Which Go SDK for apollo should I Use?

We are using the official maintained sdk, the others sdks you can find in this repo.

Some problems with the sdk:

  1. Users must declare all namespaces in AppConfig before connecting to the server and constructing a client,like:
	c := &config.AppConfig{
		AppID:          "testApplication_yang",
		Cluster:        "dev",
		IP:             "http://106.54.227.205:8080",
		NamespaceName:  "dubbo",  // declare before connecting to the server
		IsBackupConfig: true,
		Secret:         "6ce3ff7e96a24335a9634fe9abca6d51",
	}
	client,err:=agollo.StartWithConfig(func() (*config.AppConfig, error) {
		return c, nil
	})
  1. Nowhere to configurate env field.

  2. No save/delete API.

  3. No bulk query API.

  4. No sure about the concurrent safety.

  5. Nowhere to configurate or use Apollo Meta Server

  6. Not sure about the consistency property between local cache and backend database.

  7. The two operations(set kv+set tags) are not transaction,which may cause inconsistency.

Which apollo sdk API should I use?

Configuration API apollo sdk API
GetConfiguration cache := client.GetConfigCache(c.NamespaceName)
value,_ := client.Get("key")
SaveConfiguration use open API via http. update + commit
DeleteConfiguration use open API via http. delete + commit
SubscribeConfiguration https://github.com/apolloconfig/agollo/wiki/%E7%9B%91%E5%90%AC%E5%8F%98%E6%9B%B4%E4%BA%8B%E4%BB%B6

How to subscribe all config changes of the specified app

Subscribe all namespaces declared in config.json