-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added viper tarantool 3 configuration provider
We have added the ability to read static config by viper for tarantool 3
- Loading branch information
maksim.konovalov
committed
Dec 24, 2024
1 parent
249e9ba
commit 0db61e5
Showing
14 changed files
with
321 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package moonlibs | ||
|
||
// ----- Moonlibs configuration ----- | ||
|
||
// Config is a representation of the topology configuration for tarantool version below 3. | ||
// based on https://github.com/moonlibs/config?tab=readme-ov-file#example-of-etcd-configuration-etcdclustermaster. | ||
type Config struct { | ||
Topology SourceTopologyConfig `json:"topology"` | ||
} | ||
|
||
type SourceTopologyConfig struct { | ||
Clusters map[string]ClusterInfo `json:"clusters,omitempty" yaml:"clusters" ` | ||
Instances map[string]InstanceInfo `json:"instances,omitempty" yaml:"instances"` | ||
} | ||
|
||
type ClusterInfo struct { | ||
ReplicasetUUID string `yaml:"replicaset_uuid" mapstructure:"replicaset_uuid"` | ||
} | ||
|
||
type InstanceInfo struct { | ||
Cluster string | ||
Box struct { | ||
Listen string `json:"listen,omitempty" yaml:"listen" mapstructure:"listen"` | ||
InstanceUUID string `yaml:"instance_uuid" mapstructure:"instance_uuid" json:"instanceUUID,omitempty"` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package moonlibs | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/google/uuid" | ||
vshardrouter "github.com/tarantool/go-vshard-router" | ||
) | ||
|
||
func (cfg *Config) Convert() map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo { | ||
if cfg.Topology.Instances == nil { | ||
panic("instances is nil") | ||
} | ||
|
||
if cfg.Topology.Clusters == nil { | ||
panic("clusters is nil") | ||
} | ||
|
||
// prepare vshard router config | ||
vshardRouterTopology := make(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo) | ||
|
||
for rsName, rs := range cfg.Topology.Clusters { | ||
rsUUID, err := uuid.Parse(rs.ReplicasetUUID) | ||
if err != nil { | ||
panic("Can't parse replicaset uuid: %s") | ||
} | ||
|
||
rsInstances := make([]vshardrouter.InstanceInfo, 0) | ||
|
||
for _, instInfo := range cfg.Topology.Instances { | ||
if instInfo.Cluster != rsName { | ||
continue | ||
} | ||
|
||
instUUID, err := uuid.Parse(instInfo.Box.InstanceUUID) | ||
if err != nil { | ||
log.Printf("Can't parse replicaset uuid: %s", err) | ||
|
||
panic(err) | ||
} | ||
|
||
rsInstances = append(rsInstances, vshardrouter.InstanceInfo{ | ||
Addr: instInfo.Box.Listen, | ||
UUID: instUUID, | ||
}) | ||
} | ||
|
||
vshardRouterTopology[vshardrouter.ReplicasetInfo{ | ||
Name: rsName, | ||
UUID: rsUUID, | ||
}] = rsInstances | ||
} | ||
|
||
return vshardRouterTopology | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.