api7 / apisix-mesh-agent

Apache License 2.0
79 stars 10 forks source link

The Internal of apisix-mesh-agent #3

Closed tokers closed 3 years ago

tokers commented 3 years ago

The big five parts of apisix-mesh-agent are:

provisoner

It's a generic concept, which doesn't care the configuration source type, it can be xDS or UDPA or whatever anything else. It just defines the most basic behavior that a configuration provider should have.

type Provisioner interface {
    Channel() <- chan Event
}

It only provides a method Channel that returns a read only channel, one can watch this channel and got events from there.

For xDS, which is the first provisioner we must implement, will define a function NewXDSProvisioner to initialize a xDS typed provisioner.

The Event contains the event type, event source (useful for logging), event data.

type Event struct {
    Type string
    Value interface{}
    Source string
}

adaptor

adaptor is also a generic concept which embedded inside the provisioner, before a provisioner sends event to the channel, it converts the data from the original type to the APISIX form.

For the xDS provisioner, we'll have a XDSAdaptor interface.

type XDSAdaptor interface {
    AdaptRoute()
    AdaptUpstream()
    AdaptSSL()
    ......
}

cache

cache defines how apisix-mesh-agent maintains the data, we'll provide an in-memory solution.

type Cache interface {
    Add()
    Update()
    Delete()
    Get()
    List()
}

etcd server

The etcd server exposes HTTP endpoints and accepts requests to get data from cache. Since there'll so many watch requests there, etcd server should also maintains a channel to accepts changes and reflects them to clients.

type EtcdServer interface {
    Channel() chan interface{}
    ....
}

controller

The controller, which watches on the provisioner channel and gets data there and reflects them to cache, then it sends these changes to the channel of etcd server (watch).

It also exposes other HTTP APIs to let administrator to know the internal states, like cache, metrics.

tokers commented 3 years ago

Already added to document.