SlideShare a Scribd company logo
1 of 43
Morpheus
  Ultimate configuration engine

http://github.com/druxa/morpheus
Evolution


my $xml = $ua->get(“http://api.example.com/get”);




          This is trivial. And bad if your program is large enough.
Evolution

our $API_HOST = “api.example.com”;
...
my $xml = $ua->get(“http://$API_HOST/get”);




              This is a little bit better, but still bad.
Evolution

my $conf = Config::General->new(“config_file”);
my $API_HOST = $conf->getall->{API_HOST};
...
my $xml = $ua->get(“http://$API_HOST/get”);




            This version is as far as most coders would go.
The end?


Who needs “ultimate configuration engine”, really...
Only just beginning


$conf = Config::General->new(“config_file”);




                 Where is this file located?
Which one to choose?

$config_file = “./config”;
$config_file = “/etc/my-app/config”;
$config_file = “$ENV{CONFIG_PATH}/config”;




    Who configurates the configurator? And is one config file really enough?
Real-world examples


Everyone reinvents configuration from scratch.
Example: git

•   ~/.gitconfig + .git/config
•   ini-style configs
•   git config --list
•   GIT_CONFIG env variable
Example: lighttpd

• /etc/lighttpd/conf-enabled/*
• include “config_file”
• include_shell “config_generator.sh”
Example: syslog-ng

• one monolythic file

Our system administrators had to write config generation scripts to deal
with this.
Enough!
We want to:
• separate config providers from consumers
  completely
• fill config values from any sources we like
• make this mechanism extensible
Layers
  Your code



Consumer APIs



  Morpheus



Provider APIs



    Users
Layers
Consumer APIs



  Morpheus



Provider APIs
Configuration tree
All configuration values for every program live in
one global and dynamic configuration tree.
You can think of this tree as:
• file system
• hashref with lots of nested hashrefs inside
• Windows registry (but not really)
Configuration tree

• dynamic - can return different results from
  different points of view
• assembled from various sources
• can contain any scalars as values: coderefs,
  objects, etc.
Layers
                   Consumer APIs



                       Morpheus



                     Provider APIs



“Consumer” is a code which needs some configuration values.
    It should never care where these values come from.
Consumers
                     Consumer APIs

/usr/bin/morph        use Morpheus                 defaults


                        Morpheus



                      Provider APIs




         There are many ways to obtain configuration.
use Morpheus

use Morpheus;
$API_HOST = morph(“/MyApp/api_host”);




  We’ll explain later how Morpheus can be configured to return the right value.
Imports

use Morpheus “/MyApp” => [
     ‘$api_host’
];
Imports

use Morpheus “/MyApp” => [
     api_host => ‘$API_HOST’,
];
Complex imports
use Morpheus "/foo/bar" => [
     qw($V1 $V2 $V3),
     "v5" => '$V5', "v6/a" => '$A',
     "v7" => [ '$C', '$D', "e" => '$E' ],
];
/usr/bin/morph
$ morph /MyApp
{
    "api_host" : "api.example.com",
    "rate_limit" : 1000
}



                  If you didn’t recognize, this is JSON.
/usr/bin/morph
$ morph --format=xml /MyApp
<opt>
 <api_host>api.example.com</api_host>
 <rate_limit>1000</rate_limit>
</opt>
/usr/bin/morph

$ morph --format=tt2 --template=my.tt /MyApp
< ... any config format you like ... >




     There is also --format=dumper, but I won’t waste another slide on it.
Setting defaults
use Morpheus -defaults => {
     ‘/MyApp’ => {
          api_host => ‘api.example.com’,
     },
};



                This is the first example of *providing* config values.
           Now you can use Morpheus instead of ‘use constant’ everywhere!
Layers
       Consumer APIs



          Morpheus



        Provider APIs




All values are provided by plugins.
Providers
 Consumer APIs


    Morpheus
  Provider APIs
 Bootstrap plugins

 Runtime plugins

    User APIs


    Don’t panic!
Providers
You’ll only need these 99% of the time


                              Provider APIs
                           Bootstrap plugins

                            Runtime plugins

                                User APIs


    At least this will be the case when Morpheus will be mature enough...
Plugins

• API: ‘list’ and ‘get’
• but not as trivial as you expect
• we need more plugins for more config formats
Bootstrap
Bootstrap is a technique for configuring Morpheus
using Morpheus itself.


Bootstrap plugins fill /morpheus/plugins
namespace with runtime plugins.


Bootstrap sets plugin priority order.
Our setup


These are plugins we currently use:
Env > DB > File > Defaults
Morpheus::Plugin::Env
$ MORPHEUS=‘foo => { bar => 5 }’ morph /foo
{
    "bar" : 5
}




                Yes, $ENV{MORPHEUS} contains perl code.
Morpheus::Plugin::DB

mysql> SELECT * FROM Morpheus;
+----------------------+-----------+
| Name          | Config |
+----------------------+-----------+
| /foo/bar       |5    |
+----------------------+-----------+




              Config column contains perl code too!
Morpheus::Plugin::File


$ cat /etc/foo.cfg
$bar = 5;




                  We load configs from [qw( ./etc /etc )].
       This path is configurable via /morpheus/plugin/file/options/path
Perl configs
$ cat /etc/MyApp.cfg
$API = {
   host => ‘api.example.com’,
};

$ cat /etc/MyApp/API.cfg
$host = ‘api.example.com’;

$ cat /etc/MyApp/API/host.cfg
‘api.example.com’

                  These are all the same.
Perl configs


$ cat /etc/foo.cfg
use Morpheus;
$bar = morph(‘/foo/bar’) + 1;




 Recursive morph calls work. Unless you’ll introduce dependency loop, of course.
Perl configs
$ cat /etc/MyApp.cfg
use Morpheus;
my $environment = morph(“/environment”);

if ($environment eq ‘development’) {
    $api_host = “api-dev.example.com”;
}
else {
    $api_host = “api.example.com”;
}


 Don’t be alarmed. Having this feature available doesn’t mean you have to use it.
Perl configs
$ cat /etc/MyApp.cfg
$API = {
   host => ‘api.example.com’,
   port => 1234,
   rate_limit => 100,
};

$ cat /etc/MyApp.99.cfg
use Morpheus;
$API = { rate_limit =>
   morph(“/MyApp/API/rate_limit”) * 10 };

             ‘99’ is a priority. Default priority is zero.
Perl configs

$ morph /MyApp
{
  "API" : {
    "rate_limit" : 1000,
    "port" : 1234,
    "host" : "api.example.com"
  }
}

                    Morphed!
Future directions

•   MooseX::Morpheus
•   customizible merging policies
•   customazible caching policies
•   meta-information layer
Future directions

But most important, we need community help.

Because we need tons of plugins for compatibility
with existing modules:
Config::General, Config::INI, Config::JSON, etc.
Contacts

http://search.cpan.org/dist/Morpheus
http://github.com/druxa/morpheus


morpheus-perl@googlegroups.com
irc://irc.perl.org#morpheus

More Related Content

What's hot

170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebookGeeks Anonymes
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Clinton Dreisbach
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Fwdays
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises Marc Morera
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013Puppet
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And MiddlewareBen Schwarz
 
Symfony internals [english]
Symfony internals [english]Symfony internals [english]
Symfony internals [english]Raul Fraile
 
Thor - RSLA - 13oct2009
Thor - RSLA - 13oct2009Thor - RSLA - 13oct2009
Thor - RSLA - 13oct2009Plataformatec
 
Customising py py
Customising py pyCustomising py py
Customising py pythepian
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern PerlDave Cross
 
Sympal - Symfony CMS Preview
Sympal - Symfony CMS PreviewSympal - Symfony CMS Preview
Sympal - Symfony CMS PreviewJonathan Wage
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSarah El-Atm
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netProgrammer Blog
 

What's hot (20)

170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebook
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And Middleware
 
Symfony internals [english]
Symfony internals [english]Symfony internals [english]
Symfony internals [english]
 
Thor - RSLA - 13oct2009
Thor - RSLA - 13oct2009Thor - RSLA - 13oct2009
Thor - RSLA - 13oct2009
 
Customising py py
Customising py pyCustomising py py
Customising py py
 
Rack
RackRack
Rack
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Sympal - Symfony CMS Preview
Sympal - Symfony CMS PreviewSympal - Symfony CMS Preview
Sympal - Symfony CMS Preview
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event Dispatcher
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 

Similar to Morpheus configuration engine (slides from Saint Perl-2 conference)

Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confooCombell NV
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkRyan Weaver
 
Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fwdays
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvarsSam Marley-Jarrett
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Yury Pliashkou
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門lestrrat
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard DevelopersHenri Bergius
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrbAntonio Peric-Mazar
 
PM : code faster
PM : code fasterPM : code faster
PM : code fasterPHPPRO
 

Similar to Morpheus configuration engine (slides from Saint Perl-2 conference) (20)

Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
 
PHP
PHPPHP
PHP
 
Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Composer
ComposerComposer
Composer
 
Beyond AEM Curl Commands
Beyond AEM Curl CommandsBeyond AEM Curl Commands
Beyond AEM Curl Commands
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard Developers
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrb
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Morpheus configuration engine (slides from Saint Perl-2 conference)

  • 1. Morpheus Ultimate configuration engine http://github.com/druxa/morpheus
  • 2. Evolution my $xml = $ua->get(“http://api.example.com/get”); This is trivial. And bad if your program is large enough.
  • 3. Evolution our $API_HOST = “api.example.com”; ... my $xml = $ua->get(“http://$API_HOST/get”); This is a little bit better, but still bad.
  • 4. Evolution my $conf = Config::General->new(“config_file”); my $API_HOST = $conf->getall->{API_HOST}; ... my $xml = $ua->get(“http://$API_HOST/get”); This version is as far as most coders would go.
  • 5. The end? Who needs “ultimate configuration engine”, really...
  • 6. Only just beginning $conf = Config::General->new(“config_file”); Where is this file located?
  • 7. Which one to choose? $config_file = “./config”; $config_file = “/etc/my-app/config”; $config_file = “$ENV{CONFIG_PATH}/config”; Who configurates the configurator? And is one config file really enough?
  • 8. Real-world examples Everyone reinvents configuration from scratch.
  • 9. Example: git • ~/.gitconfig + .git/config • ini-style configs • git config --list • GIT_CONFIG env variable
  • 10. Example: lighttpd • /etc/lighttpd/conf-enabled/* • include “config_file” • include_shell “config_generator.sh”
  • 11. Example: syslog-ng • one monolythic file Our system administrators had to write config generation scripts to deal with this.
  • 12. Enough! We want to: • separate config providers from consumers completely • fill config values from any sources we like • make this mechanism extensible
  • 13. Layers Your code Consumer APIs Morpheus Provider APIs Users
  • 14. Layers Consumer APIs Morpheus Provider APIs
  • 15. Configuration tree All configuration values for every program live in one global and dynamic configuration tree. You can think of this tree as: • file system • hashref with lots of nested hashrefs inside • Windows registry (but not really)
  • 16. Configuration tree • dynamic - can return different results from different points of view • assembled from various sources • can contain any scalars as values: coderefs, objects, etc.
  • 17. Layers Consumer APIs Morpheus Provider APIs “Consumer” is a code which needs some configuration values. It should never care where these values come from.
  • 18. Consumers Consumer APIs /usr/bin/morph use Morpheus defaults Morpheus Provider APIs There are many ways to obtain configuration.
  • 19. use Morpheus use Morpheus; $API_HOST = morph(“/MyApp/api_host”); We’ll explain later how Morpheus can be configured to return the right value.
  • 20. Imports use Morpheus “/MyApp” => [ ‘$api_host’ ];
  • 21. Imports use Morpheus “/MyApp” => [ api_host => ‘$API_HOST’, ];
  • 22. Complex imports use Morpheus "/foo/bar" => [ qw($V1 $V2 $V3), "v5" => '$V5', "v6/a" => '$A', "v7" => [ '$C', '$D', "e" => '$E' ], ];
  • 23. /usr/bin/morph $ morph /MyApp { "api_host" : "api.example.com", "rate_limit" : 1000 } If you didn’t recognize, this is JSON.
  • 24. /usr/bin/morph $ morph --format=xml /MyApp <opt> <api_host>api.example.com</api_host> <rate_limit>1000</rate_limit> </opt>
  • 25. /usr/bin/morph $ morph --format=tt2 --template=my.tt /MyApp < ... any config format you like ... > There is also --format=dumper, but I won’t waste another slide on it.
  • 26. Setting defaults use Morpheus -defaults => { ‘/MyApp’ => { api_host => ‘api.example.com’, }, }; This is the first example of *providing* config values. Now you can use Morpheus instead of ‘use constant’ everywhere!
  • 27. Layers Consumer APIs Morpheus Provider APIs All values are provided by plugins.
  • 28. Providers Consumer APIs Morpheus Provider APIs Bootstrap plugins Runtime plugins User APIs Don’t panic!
  • 29. Providers You’ll only need these 99% of the time Provider APIs Bootstrap plugins Runtime plugins User APIs At least this will be the case when Morpheus will be mature enough...
  • 30. Plugins • API: ‘list’ and ‘get’ • but not as trivial as you expect • we need more plugins for more config formats
  • 31. Bootstrap Bootstrap is a technique for configuring Morpheus using Morpheus itself. Bootstrap plugins fill /morpheus/plugins namespace with runtime plugins. Bootstrap sets plugin priority order.
  • 32. Our setup These are plugins we currently use: Env > DB > File > Defaults
  • 33. Morpheus::Plugin::Env $ MORPHEUS=‘foo => { bar => 5 }’ morph /foo { "bar" : 5 } Yes, $ENV{MORPHEUS} contains perl code.
  • 34. Morpheus::Plugin::DB mysql> SELECT * FROM Morpheus; +----------------------+-----------+ | Name | Config | +----------------------+-----------+ | /foo/bar |5 | +----------------------+-----------+ Config column contains perl code too!
  • 35. Morpheus::Plugin::File $ cat /etc/foo.cfg $bar = 5; We load configs from [qw( ./etc /etc )]. This path is configurable via /morpheus/plugin/file/options/path
  • 36. Perl configs $ cat /etc/MyApp.cfg $API = { host => ‘api.example.com’, }; $ cat /etc/MyApp/API.cfg $host = ‘api.example.com’; $ cat /etc/MyApp/API/host.cfg ‘api.example.com’ These are all the same.
  • 37. Perl configs $ cat /etc/foo.cfg use Morpheus; $bar = morph(‘/foo/bar’) + 1; Recursive morph calls work. Unless you’ll introduce dependency loop, of course.
  • 38. Perl configs $ cat /etc/MyApp.cfg use Morpheus; my $environment = morph(“/environment”); if ($environment eq ‘development’) { $api_host = “api-dev.example.com”; } else { $api_host = “api.example.com”; } Don’t be alarmed. Having this feature available doesn’t mean you have to use it.
  • 39. Perl configs $ cat /etc/MyApp.cfg $API = { host => ‘api.example.com’, port => 1234, rate_limit => 100, }; $ cat /etc/MyApp.99.cfg use Morpheus; $API = { rate_limit => morph(“/MyApp/API/rate_limit”) * 10 }; ‘99’ is a priority. Default priority is zero.
  • 40. Perl configs $ morph /MyApp { "API" : { "rate_limit" : 1000, "port" : 1234, "host" : "api.example.com" } } Morphed!
  • 41. Future directions • MooseX::Morpheus • customizible merging policies • customazible caching policies • meta-information layer
  • 42. Future directions But most important, we need community help. Because we need tons of plugins for compatibility with existing modules: Config::General, Config::INI, Config::JSON, etc.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n