Ejecutar, configurar, ejecutar: cómo aceleramos la implementación de configuraciones en Badoo

Los archivos de configuración (configs) son una parte integral de la mayoría de las aplicaciones, pero, como muestra la práctica, este no es el tema de discusión más popular. La mayoría de las veces, las conversaciones sobre configuraciones se limitan a discutir cómo trabajar con ellas directamente en el código: cómo estructurarlas, usar variables de entorno o no, dónde almacenar las contraseñas, etc. 





, , , — (). , - .





, 1000+ . 





, Badoo , .






. , .





Badoo , . - , , . , « - , ».





— , , , ( , , , . .). 





— , . , .





« » (disable hosts). :





  • - , (, , );





  • Deploy;





  • , PHP-.





:





if (\DownChecker\Host::isDisabled($host)) {
   $this->errcode = self::ERROR_CONNECT_FAILED;
   return false;
}
      
      



« » mcode. SSH .





:





  • tar-;





  • rsync scp;





  • ;





  • .





mcode — , , . , , 99% (). — , , -. - , . . 





, mcode . , .





, - . , (, ). -, . 





, . , . , .





: , () ?





, , , :





  • — , , ;





  • , , , ; 





  • , , , OPCache, .





, ( ) , (, cron), . , , , . 





. 2000 , PHP-. / , (2k rps), . — , Publisher-Subscriber (PubSub). Redis, ( Memcache, ). 





Consul, (watches)   . PubSub . Consul, AutoConfig.





AutoConfig

:





  • , ;





  • , Consul; , Consul ( );





  • Consul watch, -, ;





  • .





:









$record = \AutoConfig\AutoConfigRecord::initByKeyData('myKey', 'Hello, Habr!', 'Eugene Tupikov');
$storage = new \AutoConfig\AutoConfigStorage();
$storage->deployRecord($record);
      
      







$reader = new \AutoConfig\AutoConfigReader();
$config = $reader->getFromCurrentSpace('myKey');
      
      







$storage = new \AutoConfig\AutoConfigStorage();
$storage->removeKey('example');
      
      



Consul watch

Consul watch HTTP API, .





.





curl -X PUT --data 'hello, habr!' http://127.0.0.1:8500/v1/kv/habr-key
      
      







curl -v http://127.0.0.1:8500/v1/kv/habr-key
      
      



API , HTTP- X-Consul-Index , .





...
...
< X-Consul-Index: 266834870
< X-Consul-Knownleader: true
...
...
<
[
  {
    "LockIndex": 0,
    "Key": "habr-key",
    "Flags": 0,
    "Value": "aGVsbG8sIGhhYnIh",
    "CreateIndex": 266833109,
    "ModifyIndex": 266834870
  }
]
      
      



X-Consul-Index index





curl http://127.0.0.1:8500/v1/kv/habr-key?index=266834870

  ...


      
      



index API , -.









curl -X PUT --data 'updated value' http://127.0.0.1:8500/v1/kv/habr-key
      
      



, ( Value ModifyIndex):





[
  {
    "LockIndex": 0,
    "Key": "habr-key",
    "Flags": 0,
    "Value": "dXBkYXRlZCB2YWx1ZQ==",
    "CreateIndex": 266833109,
    "ModifyIndex": 266835734
  }
]
      
      







consul watch -type=key -key=habr_key <handler>
      
      



Consul watch .





, . , auto_config.





consul watch -type=keyprefix -prefix=auto_config/ <handler>
      
      



. . , , . , .





GitHub Issue , , . Consul , .





, Consul . Consul Watch.





:





return [
    'value' => [
        'version' => 437036,
        'keys' => [
            'my/awesome/key' => '80003ff43027c2cc5862385fdf608a45',
            ...
            ...
        ],
        'created_at' => 1612687434
    ]
]
      
      



, :





  • ;





  • ( );





  • HTTP API ;





  • .





Consul

Consul — , AutoConfig , .





( )





Consul — , Raft. Consul — 512 . , , , . 





. 512 . , , — 64.





, :





  • ( 1000 ) , ;





  • AutoConfig 450 , ( );





  • , ,





    • N ;





    • , , .









Consul -. , - . , - , — , . , (Retry), .





. , , Consul, .





 

, , — .





, , .





, . , AutoConfig A/B-, , Service Discovery .





— 16 000, — 120 .





!





, .








All Articles