SlideShare a Scribd company logo
1 of 92
Download to read offline
Service discovery and
configuration provisioning
mariuszgil srcministry
Mariusz Gil
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Service discovery and configuration provisioning
What is an application? Source code?
Is it a complete solution for client?
Service discovery and configuration provisioning
Service discovery and configuration provisioning
How to manage the configuration?
Old school approach…
<?php

 

define('DB_HOST', 'localhost'); 

define('DB_NAME', 'northwind'); 

define('DB_USER', 'root'); 

define('DB_PASS', 'your_password'); 

 

// This connection allows your application to be used for multi-lingual websites. 

function _connect_to_mysql($is_utf8 = null)

{

$mysql_link = mysql_connect(DB_HOST, DB_USER, DB_PASS)

or die("Could not connect to database server");

mysql_select_db(DB_NAME, $mysql_link)

or die("Could not select database");

 

if (is_null($is_utf8))

{

/* This sets collation for the connection to utf8_general_ci 

because it is the default collation for utf8. 

This enables multi-lingual capability in database. 

*/

mysql_query("SET NAMES 'utf8'");

} 



return $mysql_link; 

}
<?php

 

// ...

 

// ** MySQL settings - You can get this info from your web host ** //

define('DB_NAME', 'database');

 

/** MySQL database username */

define('DB_USER', 'username');

 

/** MySQL database password */

define('DB_PASSWORD', 'password');

 

/** MySQL hostname */

define('DB_HOST', 'localhost');

 

/** Database Charset to use in creating database tables. */

define('DB_CHARSET', 'utf8');

 

/** The Database Collate type. Don't change this if in doubt. */

define('DB_COLLATE', '');
<?php

/**

* The base configuration for WordPress

*

* The wp-config.php creation script uses this file during the

* installation. You don't have to use the web site, you can

* copy this file to "wp-config.php" and fill in the values.

*

* @link https://codex.wordpress.org/Editing_wp-config.php

* @package WordPress

*/

 

// ** MySQL settings - You can get this info from your web host ** //

define('DB_NAME', 'database');

 

/** MySQL database username */

define('DB_USER', 'username');

 

/** MySQL database password */

define('DB_PASSWORD', 'password');

 

/** MySQL hostname */

define('DB_HOST', 'localhost');

 

/** Database Charset to use in creating database tables. */

define('DB_CHARSET', 'utf8');

 

/** The Database Collate type. Don't change this if in doubt. */

define('DB_COLLATE', '');
bash-3.2$ ack DB_NAME
 
wp-includes/load.php
350: $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
 
wp-content/plugins/xcloner-backup-and-restore/restore/XCloner.php
580: $config_data = str_replace("define('DB_NAME', '",
"define('DB_NAME', ‚".$_REQUEST[mysql_db]."');
#", $config_data)
 
wp-content/plugins/w3-total-cache/lib/W3/Db.php
165: parent::__construct(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
How we can improve it?
<?php



use PimpleContainer;



$container = new Container();



$container['db'] = function() {

$host = 'localhost';

$dbName = 'wordpress';

$user = 'root';

$pass = '';



return new PDO("mysql:host={$host};dbname={$dbName}", $user, $pass);

};
<?php



$dice = new DiceDice();



$rule = [

//Mark the class as shared so the same instance is returned each time

'shared' => true,



//The constructor arguments that will be supplied when the instance is created

'constructParams' => [

'mysql:host=127.0.0.1;dbname=mydb',

'username',

'password',

],

];



//Apply the rule to the PDO class

$dice->addRule('PDO', $rule);



//Now any time PDO is requested from Dice, the same instance will be returned

//And will have been constructed with the arguments supplied in 'constructParams'

$pdo = $dice->create('PDO');
<?php



$builder = new DIContainerBuilder();



$builder->addDefinitions([

'foo' => 'hello ',

'bar' => 'world',

]);

$builder->addDefinitions([

'foo' => DIdecorate(function ($previous, InteropContainerContainerInterface $container) {

return $previous . $container->get('bar');

}),

]);

$builder->addDefinitions([

'values' => [

'value 1',

'value 2',

],

]);

$builder->addDefinitions([

// with the same name

'stdClass' => DIobject('stdClass'),

// with name inferred

__NAMESPACE__ . 'ObjectDefinitionClass1' => DIobject(),

// with a different name

'object' => DIobject(__NAMESPACE__ . 'ObjectDefinitionClass1'),

]);



$container = $builder->build();
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# KNP Menu configuration
knp_menu:
twig:
template: knp_menu.html.twig
templating: false
default_renderer: twig
# KNP Paginator configuration
knp_paginator:
page_range: 5
default_options:
page_name: page
# LiipImagine configuration
liip_imagine:
filter_sets:
square_200:
quality: 100
filters:
thumbnail: { size: [200,
200], mode: outbound }
# Configuration parameters
parameters:
database_host: 127.0.0.1
database_port: null
database_name: database
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: 092402938a039b72278b9b05da3f4d4
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Is captcha feature enabled?
Is remember-be feature enabled?
Is remind-me feature enabled?
Is 2-factor authentication enabled?
Is brute-force protection enabled?
How many attempts per login allowed?
What is delay between failed logins?
Is hide-errors protection enabled?
…
Is login feature enabled at all?
What is database host?
What is database port?
What is database user?
What is database password?
What is database name?
What is database encoding?
Is database cache enabled?
What is cache host?
What is cache port?
Where the sessions are stored?
Standard feature
Single form
Many configuration problems
How to update configs?
mysql> DESC wp_options;
+--------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------------+------+-----+---------+----------------+
| option_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| option_name | varchar(64) | NO | UNI | | |
| option_value | longtext | NO | | NULL | |
| autoload | varchar(20) | NO | | yes | |
+--------------+---------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> SELECT * FROM wp_options WHERE option_name LIKE '%enabled%' LIMIT 1;
+-----------+----------------------+--------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+----------------------+--------------+----------+
| 87 | link_manager_enabled | 0 | yes |
+-----------+----------------------+--------------+----------+
1 row in set (0.00 sec)
You need to deploy application to
release changes in configuration
host A
host A host B
Another approach to maintain configs
Decouple your application from
hardcoded configuration details
by
Service discovery and
configuration provisioning tool
Service discovery and configuration provisioning
Service
discovery
Failure
detection
Key Value
storage
Multi DC
ready
host A host B host C host D
192.168.100.56
192.168.100.120
host A host B host C host D
192.168.100.56
192.168.100.120
host A host B host C host D
mysql.service.consul.
redis.service.consul.
agentserver agent agent
host A host B host C host D
mysql.service.consul.
redis.service.consul.
server agent agent agent
Managing services
# curl -X PUT -d '{
"service": {
"name": "memcached",
"tags": ["cache"],
"port": 11211,
"check": {
"name": "memcached status",
"script": "echo stats | nc 127.0.0.1 11211",
"interval": "5s"
}
}
}' http://192.168.33.10:8500/v1/catalog/service/memcached
# curl -X GET http://192.168.33.10:8500/v1/catalog/service/memcached
[{„Node":"vagrant-ubuntu-
trusty-64","Address":"192.168.33.10","ServiceID":"memcached","ServiceName":"memcached","ServiceTags
":["cache"],"ServiceAddress":"","ServicePort":11211,"ServiceEnableTagOverride":false,"CreateIndex":
19,"ModifyIndex":22}]
<?php
require '../vendor/autoload.php';
$sf = new SensioLabsConsulServiceFactory(array(
'base_url' => 'http://192.168.33.10:8500',
));
$catalog = $sf->get('catalog');
$response = $catalog->service('memcached')->json();
# Result data
array (
0 =>
array (
'Node' => 'vagrant-ubuntu-trusty-64',
'Address' => '192.168.33.10',
'ServiceID' => 'memcached',
'ServiceName' => 'memcached',
'ServiceTags' =>
array (
0 => 'cache',
),
'ServiceAddress' => '',
'ServicePort' => 11211,
'ServiceEnableTagOverride' => false,
'CreateIndex' => 19,
'ModifyIndex' => 60,
),
)
DNS interface for services and tags
<node>.node[.dc].<domain>
[tag.]<service>.service[.dc].<domain>
# dig @192.168.33.10 -p 8600 memcached.service.consul
; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @192.168.33.10 -p 8600 memcached.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58136
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;memcached.service.consul. IN A
;; ANSWER SECTION:
memcached.service.consul. 0 IN A 192.168.33.10
;; Query time: 4 msec
;; SERVER: 192.168.33.10#8600(192.168.33.10)
;; WHEN: Fri Jan 29 16:40:37 UTC 2016
;; MSG SIZE rcvd: 82
# dig @192.168.33.10 -p 8600 memcached.service.consul SRV
; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @192.168.33.10 -p 8600 memcached.service.consul SRV
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10299
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;memcached.service.consul. IN SRV
;; ANSWER SECTION:
memcached.service.consul. 0 IN SRV 1 1 11211 vagrant-ubuntu-trusty-64.node.dc1.consul.
;; ADDITIONAL SECTION:
vagrant-ubuntu-trusty-64.node.dc1.consul. 0 IN A 192.168.33.10
;; Query time: 4 msec
;; SERVER: 192.168.33.10#8600(192.168.33.10)
;; WHEN: Fri Jan 29 16:41:06 UTC 2016
;; MSG SIZE rcvd: 182
PHP Benelux Fries Example
Service 1 Service 2
# curl -X PUT -d '{
"Datacenter": "dc1",
"Node": "vagrant-ubuntu-trusty-64",
"Address": "192.168.33.10",
"Service": {
"ID": "fries-1",
"Service": "fries",
"Tags": [
"fries"
],
"Address": "192.168.33.10",
"Port": 1111
}
}' http://192.168.33.10:8500/v1/catalog/register
true
# curl -X PUT -d '{
"Datacenter": "dc1",
"Node": "vagrant-ubuntu-trusty-64",
"Address": "192.168.33.10",
"Service": {
"ID": "fries-2",
"Service": "fries",
"Tags": [
"fries"
],
"Address": "192.168.33.10",
"Port": 2222
}
}' http://192.168.33.10:8500/v1/catalog/register
true
# dig @192.168.33.10 -p 8600 fries.service.consul SRV
; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @192.168.33.10 -p 8600 fries.service.consul SRV
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30707
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;fries.service.consul. IN SRV
;; ANSWER SECTION:
fries.service.consul. 0 IN SRV 1 1 1111 vagrant-ubuntu-trusty-64.node.dc1.consul.
fries.service.consul. 0 IN SRV 1 1 2222 vagrant-ubuntu-trusty-64.node.dc1.consul.
;; ADDITIONAL SECTION:
vagrant-ubuntu-trusty-64.node.dc1.consul. 0 IN A 192.168.33.10
vagrant-ubuntu-trusty-64.node.dc1.consul. 0 IN A 192.168.33.10
;; Query time: 4 msec
;; SERVER: 192.168.33.10#8600(192.168.33.10)
;; WHEN: Fri Jan 29 23:21:22 UTC 2016
;; MSG SIZE rcvd: 310
Service discovery and configuration provisioning
Storing values
# curl -X GET http://192.168.33.10:8500/v1/kv/foo
[{"LockIndex":0,"Key":"foo","Flags":128,"Value":"YmFy","CreateIndex":123,"ModifyIndex":130}]
# curl -X PUT -d 'bar' http://192.168.33.10:8500/v1/kv/foo
true
# curl -X GET http://192.168.33.10:8500/v1/kv/foo
[{"LockIndex":0,"Key":"foo","Flags":0,"Value":"YmFy","CreateIndex":123,"ModifyIndex":123}]
# curl -X PUT -d 'bar' http://192.168.33.10:8500/v1/kv/foo?flags=128
true
<?php



require '../vendor/autoload.php';



$sf = new SensioLabsConsulServiceFactory(array('base_url' => 'http://192.168.33.10:8500'));



$kv = $sf->get('kv');



$kv->put('foo', 'bar' . time());



$response = $kv->get('foo')->json();



$kv->delete('foo');



// Result data

array (

0 =>

array (

'LockIndex' => 0,

'Key' => 'foo',

'Flags' => 0,

'Value' => 'YmFyMTQ1NDA4NTQ3MA==',

'CreateIndex' => 123,

'ModifyIndex' => 147,

),

)
Distributed locks
<?php



require '../vendor/autoload.php';



$sf = new SensioLabsConsulServiceFactory(array('base_url' => 'http://192.168.33.10:8500'));



$session = $sf->get('session');

$kv = $sf->get('kv');



// Start a session

$sessionId = $session->create()->json()['ID'];



// Lock a key / value with the current session

$lockAcquired = $kv->put('session/a-lock', 'a value', ['acquire' => $sessionId])->json();



if (false === $lockAcquired) {

$session->destroy($sessionId);



echo "The lock is already acquire by another node.n";

exit(1);

}



# YOUR CRITICAL SECTION CODE HERE...



$kv->delete('session/a-lock');

$session->destroy($sessionId);
Useful to avoid dogpile effect
Even more useful with leader election
Possibilities...
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Task #1
Replace one search engine to another
Without downtime
<?php



$backend = $userId % 100 < $settings->get('search/elastic/access_threshold', 0)

? $container->get('search.elastic')

: $container->get('search.sphinx');



$suggestions = $backend->search($query);
# curl -X PUT -d '5' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
# curl -X PUT -d '10' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
# curl -X PUT -d '15' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
# curl -X PUT -d '25' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
# curl -X PUT -d '50' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
# curl -X PUT -d '75' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
# curl -X PUT -d '50' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
<?php



$engine = $userId % 100 < $settings->get('search/elastic/access_threshold')

? 'elastic'

: 'sphinx';

$backend = $container->get('search.' . $engine);



$minimalQueryLength = $settings->get('search.' . $engine . '.minimal_length', 3);

$maximalNumberOfSuggestion = $settings->get('search.' . $engine . '.suggestions_limits', 10);



if (length($query) >= $minimalQueryLength) {

$suggestions = $backend->search($query, $maximalNumberOfSuggestion);

}
Task #2
Add CPU/memory to the server
In the middle of the night
<?php



if ($settings->get('recommendations/enabled')) {

# Fetch recommendations for user based on request

# ...

}
# curl -X PUT -d '0' http://192.168.33.10:8500/v1/kv/recommendations/enabled
# halt
# ADD MORE CPU/MEMORY
# curl -X PUT -d '1' http://192.168.33.10:8500/v1/kv/recommendations/enabled
# curl -X PUT -d '{
> "Datacenter": "dc1",
> "Node": "vagrant-ubuntu-trusty-64",
> "ServiceID": "memcached"
> }' http://192.168.33.10:8500/v1/catalog/deregister
true
# curl -X PUT -d '{
> "Datacenter": "dc1",
> "Node": "vagrant-ubuntu-trusty-64",
> "Address": "192.168.33.10",
> "Service": {
> "ID": "memcached",
> "Service": "memcached",
> "Tags": [
> "cache"
> ],
> "Address": "192.168.33.10",
> "Port": 11211
> }
> }' http://192.168.33.10:8500/v1/catalog/register
true
<?php



require '../vendor/autoload.php';



$sf = new SensioLabsConsulServiceFactory(array(

'base_url' => 'http://192.168.33.10:8500',

));



$catalog = $sf->get('catalog');

$serviceDefinitions = $catalog->service('memcached')->json();



$memcached = new Memcache();



foreach ($serviceDefinitions as $serviceDefinition) {

$memcached->addserver($serviceDefinition['ServiceAddress'], $serviceDefinition['ServicePort']);

}
Long running background workers
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Watch the Watches. React
host A host B host C host D
agentserver
web app
agent
background worker
agent
background worker
watch for event
make changes
& fire event
API methods
Agent
/v1/agent/checks
/v1/agent/services
/v1/agent/members
/v1/agent/self
/v1/agent/maintenance
/v1/agent/join/<address>
/v1/agent/force-leave/<node>>
/v1/agent/check/register
/v1/agent/check/deregister/<checkID>
/v1/agent/check/pass/<checkID>
/v1/agent/check/warn/<checkID>
/v1/agent/check/fail/<checkID>
/v1/agent/service/register
/v1/agent/service/deregister/<serviceID>
/v1/agent/service/maintenance/<serviceID>
Catalog
/v1/catalog/register
/v1/catalog/deregister
/v1/catalog/datacenters
/v1/catalog/nodes
/v1/catalog/services
/v1/catalog/service/<service>
/v1/catalog/node/<node>
Health Checks
/v1/health/node/<node>
/v1/health/checks/<service>
/v1/health/service/<service>
/v1/health/state/<state>
Network coordinates
/v1/coordinate/datacenters
/v1/coordinate/nodes
Key / Values
/v1/kv/<key>
Events
/v1/event/fire/<name>
/v1/event/list
ACL
/v1/agent/checks
/v1/agent/services
/v1/agent/members
/v1/agent/self
/v1/agent/maintenance
/v1/agent/join/<address>
/v1/agent/force-leave/<node>>
/v1/agent/check/register
/v1/agent/check/deregister/<checkID>
/v1/agent/check/pass/<checkID>
/v1/agent/check/warn/<checkID>
/v1/agent/check/fail/<checkID>
/v1/agent/service/register
/v1/agent/service/deregister/<serviceID>
/v1/agent/service/maintenance/<serviceID>
Prepared queries
/v1/query
/v1/query/<query>
/v1/query/<query or name>/execute
Sessions
/v1/session/create
/v1/session/destroy/<session>
/v1/session/info/<session>
/v1/session/node/<node>
/v1/session/list
/v1/session/renew
Server status
/v1/status/leader
/v1/status/peers
Alternative solutions
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Service discovery and configuration provisioning
Choose one or implement your own
If you need it. Really need it
Thanks! Enjoy config management!
https://joind.in/talk/198e7
mariuszgil srcministry

More Related Content

What's hot

Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB
 
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014Cliff Seal
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Cliff Seal
 
MongoDB San Francisco DrupalCon 2010
MongoDB San Francisco DrupalCon 2010MongoDB San Francisco DrupalCon 2010
MongoDB San Francisco DrupalCon 2010Karoly Negyesi
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Cassandra Summit 2015
Cassandra Summit 2015Cassandra Summit 2015
Cassandra Summit 2015jbellis
 
Redis for your boss 2.0
Redis for your boss 2.0Redis for your boss 2.0
Redis for your boss 2.0Elena Kolevska
 
神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)guregu
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersBen van Mol
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
Cassandra 2.0 better, faster, stronger
Cassandra 2.0   better, faster, strongerCassandra 2.0   better, faster, stronger
Cassandra 2.0 better, faster, strongerPatrick McFadin
 
Database Wizardry for Legacy Applications
Database Wizardry for Legacy ApplicationsDatabase Wizardry for Legacy Applications
Database Wizardry for Legacy ApplicationsGabriela Ferrara
 
Cassandra summit keynote 2014
Cassandra summit keynote 2014Cassandra summit keynote 2014
Cassandra summit keynote 2014jbellis
 

What's hot (20)

Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
 
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
MongoDB San Francisco DrupalCon 2010
MongoDB San Francisco DrupalCon 2010MongoDB San Francisco DrupalCon 2010
MongoDB San Francisco DrupalCon 2010
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Redis for your boss
Redis for your bossRedis for your boss
Redis for your boss
 
Cassandra Summit 2015
Cassandra Summit 2015Cassandra Summit 2015
Cassandra Summit 2015
 
Redis for your boss 2.0
Redis for your boss 2.0Redis for your boss 2.0
Redis for your boss 2.0
 
Top Node.js Metrics to Watch
Top Node.js Metrics to WatchTop Node.js Metrics to Watch
Top Node.js Metrics to Watch
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
Cassandra 2.0 better, faster, stronger
Cassandra 2.0   better, faster, strongerCassandra 2.0   better, faster, stronger
Cassandra 2.0 better, faster, stronger
 
Database Wizardry for Legacy Applications
Database Wizardry for Legacy ApplicationsDatabase Wizardry for Legacy Applications
Database Wizardry for Legacy Applications
 
Cassandra summit keynote 2014
Cassandra summit keynote 2014Cassandra summit keynote 2014
Cassandra summit keynote 2014
 

Viewers also liked

Machine learning for developers
Machine learning for developersMachine learning for developers
Machine learning for developersSource Ministry
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
 
Holistic approach to machine learning
Holistic approach to machine learningHolistic approach to machine learning
Holistic approach to machine learningSource Ministry
 
Embrace Events and let CRUD die
Embrace Events and let CRUD dieEmbrace Events and let CRUD die
Embrace Events and let CRUD dieKacper Gunia
 
The top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doingThe top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doingKacper Gunia
 
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...Alexey Petrov
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeperSaurav Haloi
 

Viewers also liked (8)

Machine learning for developers
Machine learning for developersMachine learning for developers
Machine learning for developers
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Holistic approach to machine learning
Holistic approach to machine learningHolistic approach to machine learning
Holistic approach to machine learning
 
Embrace Events and let CRUD die
Embrace Events and let CRUD dieEmbrace Events and let CRUD die
Embrace Events and let CRUD die
 
The top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doingThe top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doing
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 

Similar to Service discovery and configuration provisioning

Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebookguoqing75
 
Drupal as a web framework
Drupal as a web frameworkDrupal as a web framework
Drupal as a web frameworkAdam Kalsey
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
A 2-2 php on windows azure
A 2-2 php on windows azureA 2-2 php on windows azure
A 2-2 php on windows azureGoAzure
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objectswebhostingguy
 
MySQL server security
MySQL server securityMySQL server security
MySQL server securityDamien Seguy
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploySimon Su
 
Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Serverhendrikvb
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slidesmkherlakian
 

Similar to Service discovery and configuration provisioning (20)

Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Drupal as a web framework
Drupal as a web frameworkDrupal as a web framework
Drupal as a web framework
 
Fatc
FatcFatc
Fatc
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
PHP on Windows Azure
PHP on Windows Azure PHP on Windows Azure
PHP on Windows Azure
 
A 2-2 php on windows azure
A 2-2 php on windows azureA 2-2 php on windows azure
A 2-2 php on windows azure
 
Php summary
Php summaryPhp summary
Php summary
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
 
MySQL server security
MySQL server securityMySQL server security
MySQL server security
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Server
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
 

Recently uploaded

Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingFrancesco Corti
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
Flow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameFlow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameKapil Thakar
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)IES VE
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024Brian Pichman
 
20140402 - Smart house demo kit
20140402 - Smart house demo kit20140402 - Smart house demo kit
20140402 - Smart house demo kitJamie (Taka) Wang
 
How to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxHow to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxKaustubhBhavsar6
 
Oracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxOracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxSatishbabu Gunukula
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024Brian Pichman
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Alkin Tezuysal
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNeo4j
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch TuesdayIvanti
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 

Recently uploaded (20)

Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is going
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
Flow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameFlow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First Frame
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024
 
20140402 - Smart house demo kit
20140402 - Smart house demo kit20140402 - Smart house demo kit
20140402 - Smart house demo kit
 
How to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxHow to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptx
 
Oracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxOracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptx
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4j
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch Tuesday
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 

Service discovery and configuration provisioning

  • 1. Service discovery and configuration provisioning mariuszgil srcministry Mariusz Gil
  • 5. What is an application? Source code?
  • 6. Is it a complete solution for client?
  • 9. How to manage the configuration?
  • 11. <?php
  
 define('DB_HOST', 'localhost'); 
 define('DB_NAME', 'northwind'); 
 define('DB_USER', 'root'); 
 define('DB_PASS', 'your_password'); 
  
 // This connection allows your application to be used for multi-lingual websites. 
 function _connect_to_mysql($is_utf8 = null)
 {
 $mysql_link = mysql_connect(DB_HOST, DB_USER, DB_PASS)
 or die("Could not connect to database server");
 mysql_select_db(DB_NAME, $mysql_link)
 or die("Could not select database");
  
 if (is_null($is_utf8))
 {
 /* This sets collation for the connection to utf8_general_ci 
 because it is the default collation for utf8. 
 This enables multi-lingual capability in database. 
 */
 mysql_query("SET NAMES 'utf8'");
 } 
 
 return $mysql_link; 
 }
  • 12. <?php
  
 // ...
  
 // ** MySQL settings - You can get this info from your web host ** //
 define('DB_NAME', 'database');
  
 /** MySQL database username */
 define('DB_USER', 'username');
  
 /** MySQL database password */
 define('DB_PASSWORD', 'password');
  
 /** MySQL hostname */
 define('DB_HOST', 'localhost');
  
 /** Database Charset to use in creating database tables. */
 define('DB_CHARSET', 'utf8');
  
 /** The Database Collate type. Don't change this if in doubt. */
 define('DB_COLLATE', '');
  • 13. <?php
 /**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 * @package WordPress
 */
  
 // ** MySQL settings - You can get this info from your web host ** //
 define('DB_NAME', 'database');
  
 /** MySQL database username */
 define('DB_USER', 'username');
  
 /** MySQL database password */
 define('DB_PASSWORD', 'password');
  
 /** MySQL hostname */
 define('DB_HOST', 'localhost');
  
 /** Database Charset to use in creating database tables. */
 define('DB_CHARSET', 'utf8');
  
 /** The Database Collate type. Don't change this if in doubt. */
 define('DB_COLLATE', '');
  • 14. bash-3.2$ ack DB_NAME   wp-includes/load.php 350: $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );   wp-content/plugins/xcloner-backup-and-restore/restore/XCloner.php 580: $config_data = str_replace("define('DB_NAME', '", "define('DB_NAME', ‚".$_REQUEST[mysql_db]."'); #", $config_data)   wp-content/plugins/w3-total-cache/lib/W3/Db.php 165: parent::__construct(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
  • 15. How we can improve it?
  • 16. <?php
 
 use PimpleContainer;
 
 $container = new Container();
 
 $container['db'] = function() {
 $host = 'localhost';
 $dbName = 'wordpress';
 $user = 'root';
 $pass = '';
 
 return new PDO("mysql:host={$host};dbname={$dbName}", $user, $pass);
 };
  • 17. <?php
 
 $dice = new DiceDice();
 
 $rule = [
 //Mark the class as shared so the same instance is returned each time
 'shared' => true,
 
 //The constructor arguments that will be supplied when the instance is created
 'constructParams' => [
 'mysql:host=127.0.0.1;dbname=mydb',
 'username',
 'password',
 ],
 ];
 
 //Apply the rule to the PDO class
 $dice->addRule('PDO', $rule);
 
 //Now any time PDO is requested from Dice, the same instance will be returned
 //And will have been constructed with the arguments supplied in 'constructParams'
 $pdo = $dice->create('PDO');
  • 18. <?php
 
 $builder = new DIContainerBuilder();
 
 $builder->addDefinitions([
 'foo' => 'hello ',
 'bar' => 'world',
 ]);
 $builder->addDefinitions([
 'foo' => DIdecorate(function ($previous, InteropContainerContainerInterface $container) {
 return $previous . $container->get('bar');
 }),
 ]);
 $builder->addDefinitions([
 'values' => [
 'value 1',
 'value 2',
 ],
 ]);
 $builder->addDefinitions([
 // with the same name
 'stdClass' => DIobject('stdClass'),
 // with name inferred
 __NAMESPACE__ . 'ObjectDefinitionClass1' => DIobject(),
 // with a different name
 'object' => DIobject(__NAMESPACE__ . 'ObjectDefinitionClass1'),
 ]);
 
 $container = $builder->build();
  • 19. # Swiftmailer Configuration swiftmailer: transport: "%mailer_transport%" host: "%mailer_host%" username: "%mailer_user%" password: "%mailer_password%" spool: { type: memory } # KNP Menu configuration knp_menu: twig: template: knp_menu.html.twig templating: false default_renderer: twig # KNP Paginator configuration knp_paginator: page_range: 5 default_options: page_name: page # LiipImagine configuration liip_imagine: filter_sets: square_200: quality: 100 filters: thumbnail: { size: [200, 200], mode: outbound } # Configuration parameters parameters: database_host: 127.0.0.1 database_port: null database_name: database database_user: root database_password: null mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: null mailer_password: null secret: 092402938a039b72278b9b05da3f4d4
  • 22. Is captcha feature enabled? Is remember-be feature enabled? Is remind-me feature enabled? Is 2-factor authentication enabled? Is brute-force protection enabled? How many attempts per login allowed? What is delay between failed logins? Is hide-errors protection enabled? … Is login feature enabled at all?
  • 23. What is database host? What is database port? What is database user? What is database password? What is database name? What is database encoding? Is database cache enabled? What is cache host? What is cache port? Where the sessions are stored?
  • 24. Standard feature Single form Many configuration problems
  • 25. How to update configs?
  • 26. mysql> DESC wp_options; +--------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+---------------------+------+-----+---------+----------------+ | option_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | option_name | varchar(64) | NO | UNI | | | | option_value | longtext | NO | | NULL | | | autoload | varchar(20) | NO | | yes | | +--------------+---------------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM wp_options WHERE option_name LIKE '%enabled%' LIMIT 1; +-----------+----------------------+--------------+----------+ | option_id | option_name | option_value | autoload | +-----------+----------------------+--------------+----------+ | 87 | link_manager_enabled | 0 | yes | +-----------+----------------------+--------------+----------+ 1 row in set (0.00 sec)
  • 27. You need to deploy application to release changes in configuration
  • 30. Another approach to maintain configs
  • 31. Decouple your application from hardcoded configuration details
  • 32. by
  • 36. host A host B host C host D 192.168.100.56 192.168.100.120
  • 37. host A host B host C host D 192.168.100.56 192.168.100.120
  • 38. host A host B host C host D mysql.service.consul. redis.service.consul. agentserver agent agent
  • 39. host A host B host C host D mysql.service.consul. redis.service.consul. server agent agent agent
  • 41. # curl -X PUT -d '{ "service": { "name": "memcached", "tags": ["cache"], "port": 11211, "check": { "name": "memcached status", "script": "echo stats | nc 127.0.0.1 11211", "interval": "5s" } } }' http://192.168.33.10:8500/v1/catalog/service/memcached # curl -X GET http://192.168.33.10:8500/v1/catalog/service/memcached [{„Node":"vagrant-ubuntu- trusty-64","Address":"192.168.33.10","ServiceID":"memcached","ServiceName":"memcached","ServiceTags ":["cache"],"ServiceAddress":"","ServicePort":11211,"ServiceEnableTagOverride":false,"CreateIndex": 19,"ModifyIndex":22}]
  • 42. <?php require '../vendor/autoload.php'; $sf = new SensioLabsConsulServiceFactory(array( 'base_url' => 'http://192.168.33.10:8500', )); $catalog = $sf->get('catalog'); $response = $catalog->service('memcached')->json(); # Result data array ( 0 => array ( 'Node' => 'vagrant-ubuntu-trusty-64', 'Address' => '192.168.33.10', 'ServiceID' => 'memcached', 'ServiceName' => 'memcached', 'ServiceTags' => array ( 0 => 'cache', ), 'ServiceAddress' => '', 'ServicePort' => 11211, 'ServiceEnableTagOverride' => false, 'CreateIndex' => 19, 'ModifyIndex' => 60, ), )
  • 43. DNS interface for services and tags
  • 46. # dig @192.168.33.10 -p 8600 memcached.service.consul ; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @192.168.33.10 -p 8600 memcached.service.consul ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58136 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; WARNING: recursion requested but not available ;; QUESTION SECTION: ;memcached.service.consul. IN A ;; ANSWER SECTION: memcached.service.consul. 0 IN A 192.168.33.10 ;; Query time: 4 msec ;; SERVER: 192.168.33.10#8600(192.168.33.10) ;; WHEN: Fri Jan 29 16:40:37 UTC 2016 ;; MSG SIZE rcvd: 82
  • 47. # dig @192.168.33.10 -p 8600 memcached.service.consul SRV ; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @192.168.33.10 -p 8600 memcached.service.consul SRV ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10299 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; WARNING: recursion requested but not available ;; QUESTION SECTION: ;memcached.service.consul. IN SRV ;; ANSWER SECTION: memcached.service.consul. 0 IN SRV 1 1 11211 vagrant-ubuntu-trusty-64.node.dc1.consul. ;; ADDITIONAL SECTION: vagrant-ubuntu-trusty-64.node.dc1.consul. 0 IN A 192.168.33.10 ;; Query time: 4 msec ;; SERVER: 192.168.33.10#8600(192.168.33.10) ;; WHEN: Fri Jan 29 16:41:06 UTC 2016 ;; MSG SIZE rcvd: 182
  • 48. PHP Benelux Fries Example
  • 50. # curl -X PUT -d '{ "Datacenter": "dc1", "Node": "vagrant-ubuntu-trusty-64", "Address": "192.168.33.10", "Service": { "ID": "fries-1", "Service": "fries", "Tags": [ "fries" ], "Address": "192.168.33.10", "Port": 1111 } }' http://192.168.33.10:8500/v1/catalog/register true # curl -X PUT -d '{ "Datacenter": "dc1", "Node": "vagrant-ubuntu-trusty-64", "Address": "192.168.33.10", "Service": { "ID": "fries-2", "Service": "fries", "Tags": [ "fries" ], "Address": "192.168.33.10", "Port": 2222 } }' http://192.168.33.10:8500/v1/catalog/register true
  • 51. # dig @192.168.33.10 -p 8600 fries.service.consul SRV ; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @192.168.33.10 -p 8600 fries.service.consul SRV ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30707 ;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2 ;; WARNING: recursion requested but not available ;; QUESTION SECTION: ;fries.service.consul. IN SRV ;; ANSWER SECTION: fries.service.consul. 0 IN SRV 1 1 1111 vagrant-ubuntu-trusty-64.node.dc1.consul. fries.service.consul. 0 IN SRV 1 1 2222 vagrant-ubuntu-trusty-64.node.dc1.consul. ;; ADDITIONAL SECTION: vagrant-ubuntu-trusty-64.node.dc1.consul. 0 IN A 192.168.33.10 vagrant-ubuntu-trusty-64.node.dc1.consul. 0 IN A 192.168.33.10 ;; Query time: 4 msec ;; SERVER: 192.168.33.10#8600(192.168.33.10) ;; WHEN: Fri Jan 29 23:21:22 UTC 2016 ;; MSG SIZE rcvd: 310
  • 54. # curl -X GET http://192.168.33.10:8500/v1/kv/foo [{"LockIndex":0,"Key":"foo","Flags":128,"Value":"YmFy","CreateIndex":123,"ModifyIndex":130}] # curl -X PUT -d 'bar' http://192.168.33.10:8500/v1/kv/foo true # curl -X GET http://192.168.33.10:8500/v1/kv/foo [{"LockIndex":0,"Key":"foo","Flags":0,"Value":"YmFy","CreateIndex":123,"ModifyIndex":123}] # curl -X PUT -d 'bar' http://192.168.33.10:8500/v1/kv/foo?flags=128 true
  • 55. <?php
 
 require '../vendor/autoload.php';
 
 $sf = new SensioLabsConsulServiceFactory(array('base_url' => 'http://192.168.33.10:8500'));
 
 $kv = $sf->get('kv');
 
 $kv->put('foo', 'bar' . time());
 
 $response = $kv->get('foo')->json();
 
 $kv->delete('foo');
 
 // Result data
 array (
 0 =>
 array (
 'LockIndex' => 0,
 'Key' => 'foo',
 'Flags' => 0,
 'Value' => 'YmFyMTQ1NDA4NTQ3MA==',
 'CreateIndex' => 123,
 'ModifyIndex' => 147,
 ),
 )
  • 57. <?php
 
 require '../vendor/autoload.php';
 
 $sf = new SensioLabsConsulServiceFactory(array('base_url' => 'http://192.168.33.10:8500'));
 
 $session = $sf->get('session');
 $kv = $sf->get('kv');
 
 // Start a session
 $sessionId = $session->create()->json()['ID'];
 
 // Lock a key / value with the current session
 $lockAcquired = $kv->put('session/a-lock', 'a value', ['acquire' => $sessionId])->json();
 
 if (false === $lockAcquired) {
 $session->destroy($sessionId);
 
 echo "The lock is already acquire by another node.n";
 exit(1);
 }
 
 # YOUR CRITICAL SECTION CODE HERE...
 
 $kv->delete('session/a-lock');
 $session->destroy($sessionId);
  • 58. Useful to avoid dogpile effect
  • 59. Even more useful with leader election
  • 63. Task #1 Replace one search engine to another Without downtime
  • 64. <?php
 
 $backend = $userId % 100 < $settings->get('search/elastic/access_threshold', 0)
 ? $container->get('search.elastic')
 : $container->get('search.sphinx');
 
 $suggestions = $backend->search($query); # curl -X PUT -d '5' http://192.168.33.10:8500/v1/kv/search/elastic/threshold # curl -X PUT -d '10' http://192.168.33.10:8500/v1/kv/search/elastic/threshold # curl -X PUT -d '15' http://192.168.33.10:8500/v1/kv/search/elastic/threshold # curl -X PUT -d '25' http://192.168.33.10:8500/v1/kv/search/elastic/threshold # curl -X PUT -d '50' http://192.168.33.10:8500/v1/kv/search/elastic/threshold # curl -X PUT -d '75' http://192.168.33.10:8500/v1/kv/search/elastic/threshold # curl -X PUT -d '50' http://192.168.33.10:8500/v1/kv/search/elastic/threshold
  • 65. <?php
 
 $engine = $userId % 100 < $settings->get('search/elastic/access_threshold')
 ? 'elastic'
 : 'sphinx';
 $backend = $container->get('search.' . $engine);
 
 $minimalQueryLength = $settings->get('search.' . $engine . '.minimal_length', 3);
 $maximalNumberOfSuggestion = $settings->get('search.' . $engine . '.suggestions_limits', 10);
 
 if (length($query) >= $minimalQueryLength) {
 $suggestions = $backend->search($query, $maximalNumberOfSuggestion);
 }
  • 66. Task #2 Add CPU/memory to the server In the middle of the night
  • 67. <?php
 
 if ($settings->get('recommendations/enabled')) {
 # Fetch recommendations for user based on request
 # ...
 } # curl -X PUT -d '0' http://192.168.33.10:8500/v1/kv/recommendations/enabled # halt # ADD MORE CPU/MEMORY # curl -X PUT -d '1' http://192.168.33.10:8500/v1/kv/recommendations/enabled
  • 68. # curl -X PUT -d '{ > "Datacenter": "dc1", > "Node": "vagrant-ubuntu-trusty-64", > "ServiceID": "memcached" > }' http://192.168.33.10:8500/v1/catalog/deregister true # curl -X PUT -d '{ > "Datacenter": "dc1", > "Node": "vagrant-ubuntu-trusty-64", > "Address": "192.168.33.10", > "Service": { > "ID": "memcached", > "Service": "memcached", > "Tags": [ > "cache" > ], > "Address": "192.168.33.10", > "Port": 11211 > } > }' http://192.168.33.10:8500/v1/catalog/register true
  • 69. <?php
 
 require '../vendor/autoload.php';
 
 $sf = new SensioLabsConsulServiceFactory(array(
 'base_url' => 'http://192.168.33.10:8500',
 ));
 
 $catalog = $sf->get('catalog');
 $serviceDefinitions = $catalog->service('memcached')->json();
 
 $memcached = new Memcache();
 
 foreach ($serviceDefinitions as $serviceDefinition) {
 $memcached->addserver($serviceDefinition['ServiceAddress'], $serviceDefinition['ServicePort']);
 }
  • 74. host A host B host C host D agentserver web app agent background worker agent background worker watch for event make changes & fire event
  • 91. Choose one or implement your own If you need it. Really need it
  • 92. Thanks! Enjoy config management! https://joind.in/talk/198e7 mariuszgil srcministry