OpenLiberty / docs

See Open Liberty documentation on https://openliberty.io/docs/
https://openliberty.io/docs/
Other
13 stars 47 forks source link

Microservice configuration (MP26) #335

Closed lauracowen closed 4 years ago

lauracowen commented 5 years ago

Introduce MP Config, and why it is important to be able to configure microservices without having to update the app code (can move them between environments eg test, production). Give examples of what kinds of things you can do with config in MP (eg change connections to databases depending on environment, inc Kubernetes (see guide); ....see other MP features for other examples).

Include that you can put your microservice config in various places (though some of this info might be more appropriate in the server config docs and linked to instead?).

Relevant guides (for background research and to link to):

A blog post Emily wrote:

Contact:

ManasiGandhi commented 5 years ago

// Copyright (c) 2018 IBM Corporation and others. // Licensed under Creative Commons Attribution-NoDerivatives // 4.0 International (CC BY-ND 4.0) // https://creativecommons.org/licenses/by-nd/4.0/ // // Contributors: // IBM Corporation // :page-description: MicroProfile Config is an API that externalizes configuration from microservices, thus keeping it separate from the source code. Microprofile Config can be used by applications as a single API that can retrieve configuration information from different sources. :seo-description: MicroProfile Config is an API that externalizes configuration from microservices, thus keeping it separate from the source code. Microprofile Config can be used by applications as a single API that can retrieve configuration information from different sources. :page-layout: general-reference :page-type: general

= Microservice configuration

MicroProfile Config is an API that externalizes configuration from microservices, thus keeping it separate from the source code. Microprofile Config can be used by applications as a single API that can retrieve configuration information from different sources. When your applications are deployed as microservices, having a single place to update the configuration data of multiple microservices is useful for several reasons. • Building systems as collections of independent microservices increases the number of services that need to be managed. • Different stages in the pipeline often use different configuration sources for a single piece of configuration data and a given component needs updating as it moves through the pipeline. • Containerisation of services means that even while a component is ‘live’ in production, the environment it is running in might be more dynamic and the components need configuration updates without being restarted. The Microprofile Config API allows for a consistent means to access configuration data from pluggable configuration sources. Configuration properties can be injected using Java CDI in a form that is easy to consume. Data values and sources can vary across the devOps pipeline without code change or repackaging, and dynamic and fully typed data is catered for.

== Why it is important to configure microservices without having to update the app code?

A Micro Service can be deployed hundreds of times, using multiple different versions and across multiple different environments. The micro service needs to continue to work in all those environments without the need to modify the code. It is important to avoid embedding configuration in code, particularly if that config contains sensitive information such as passwords.

Configuration data can come from different locations and in different formats – system properties, system environment variables, properties files or resources, XML files or resources, and even data sources. MicroProfile Config calls these sources of data ConfigSources. Since the same configuration property could be defined in multiple ConfigSources, a prioritization can be used to determine which ConfigSource is used for the property value. Sometimes configuration values can change dynamically. Applications need to be able to access the latest values without restarting. This is particularly important for microservices running in a cloud environment. MicroProfile Config supports dynamically updating configuration values.

== What you can do with MP Config?

Here are some things you can do with a Microprofile Config API:

• Amalgamate multiple configuration sources into a single configuration and access with one API. • Override configuration property values with values from configuration sources that are designated as having a higher precedence. • Store values in named properties files, system environment variables, or Java™ System properties. • Load ConfigSource resources by using a Java ClassLoader, either the application’s current context ClassLoader or a user supplied ClassLoader. • Provide values by registering a user implementation of a ConfigSource interface. • Retrieve values as Strings or as typed objects of a particular Java class by using built in or custom type Converters. • Discover ConfigSource and Converter implementations by using the Java ServiceLoader pattern. • Directly inject configuration property values, whether for primitives, standard types, or user supplied types, by using Java CDI (Context and Dependency Injection).

==== See also:

lauracowen commented 5 years ago

Sorry, I meant can you create it as a .adoc file like this one https://github.com/OpenLiberty/docs/blob/draft/ref/general/contexts_dependency_injection.adoc (not in this issue)?

lauracowen commented 5 years ago

Some points I'm coming across that maybe should be included in this:

Charlotte-Holt commented 5 years ago

https://github.com/OpenLiberty/docs/blob/draft/ref/general/Microservice%20configuration

lauracowen commented 5 years ago

I think the first draft of this topic is a reasonable start but I think it needs more work. It needs to be clearer and more concise (it currently repeats some of the points several times, or sometimes only makes half a point so it's not clear what it's saying).

Structure:

Link to (as they come up in the text, or at the end if not):

For background research:

Minor thoughts:

lauracowen commented 5 years ago

Questions from Slack conversation: 1) If we mention Kubernetes (with respect to port binding) should we also provide a context for it? 2) Can you please provide more details or links for MP JWT, MP Reactive Messaging, and MP FT?

1) Kubernetes - yes...you're right, it's a little bit  of a surprise mention at the moment. How about change the earlier sentences slightly: "In the cloud, microservices deployed to Kubernetes clusters need to communicate..." and "As Kubernetes creates and destroys instances of microservices to scale the app up an down, port numbers change." Or something like that? Then your existing Kubernetes sentence makes more sense. Do you think that gives enough context to it? Should also link from this topic to https://openliberty.io/guides/kubernetes-microprofile-config.html (maybe from this section is best, rather than just sticking a list of links out of context at the end of the topic).

2) I think just give some examples of how they're used for each.

MP JWT - You could maybe just say that public key location and verification can be set in properties files so that if, say, the location of the key repository changes, it can easily be updated?? (not sure of the exact wording but check that with the reviewer). I would say to link to this guide: https://openliberty.io/guides/microprofile-jwt.html but I think this was written before MP Config came about and I don't think it's demonstrating the use of MP Config :( And we don't currently have anything else to link to, so maybe not. 

MP Reactive Messaging - eg can set the connection details of messaging channels and connectors, and the topic names that are used by the app to consume and produce messages. (see the descriptions in here https://github.com/OpenLiberty/docs/issues/505 )

MP FT - eg can set the value of an annotation like the maximum number of retries for the @Retry annotation - - you can easily change the value if (I guess!) the tolerance is found to be too low or too high (get that explanation checked as I'm speculating!) (again, see the description here https://github.com/OpenLiberty/docs/issues/505 )

At some point, when we have done the #505 issue, we can link to that topic from here but we've not got that far yet.

chirp1 commented 4 years ago

Hi Manasi,

chirp1 commented 4 years ago

Hi Manasi, Here are my latest comments. "Microservices move among different environments and resource connection details can change." are two different thoughts. What is the relationship that you are trying to draw between the two? Also, how does this sentence relate to the second sentence in the short description? Would you you rewrite this short description so that the information is cohesive, following the 2 sentence short description guidelines that we studied in our ID workshops?

In various places a definite or indefinite article is missing in front of "configuration". For example "Externalizing configuration" is missing the. Throughout the article, add in the correct article in front of "configuration". Change " multiple environments- development, test, or production." to "development, test, and production environments." As with parentheses, don't use hyphens. They are both shorthand. Instead, write out what you have to say.

Would you rewrite this sentence as I find it a bit confusing: "Each backing service must be attached and detached as a resource to your application, as required, without a code change, or a distinction between a local and external service." It's the ", or a distinction between a local and external service." that is confusing. You can write it as multiple sentences if necessary. I think that you have too many commas, "or's" and "and's" in one sentence.

Use "application" instead of "app". Do so whenever you write.

Change "Applications can use MicroProfile Config as a single API to retrieve configuration information from different sources. Configuration data can come from different locations and in different formats – system properties, system environment variables, properties files, XML files, or data sources." to "Applications can use MicroProfile Config as a single API to retrieve configuration information from different sources such as system properties, system environment variables, properties files, XML files, or data sources." <= scrubs out unnecessary words.

Speak to the customer by using "you" and active voice instead of using passive voice. So, for example, change "A prioritization can be used to determine which ConfigSource is used for the property value. " to "You can prioritize which ConfigSource to use for the property value.". Chanage the wording in other places, too.

Generally for titles, don't have titles that are sentences. For "MicroProfile Config has three default configsources", change it to something like "Default configsources".

For "MicroProfile Config helps in overriding values in fault tolerance.", scrub out non-essential words. So, you could change the wording to "MicroProfile Config helps override values in fault tolerance.".

ManasiGandhi commented 4 years ago

Hi @lauracowen, I moved the MP Config issue into ready to publish after talking with Karen. Here is a link for your reference. https://draft-openlibertyio.mybluemix.net/docs/ref/general/#mp-config.html

Can you please review?

lauracowen commented 4 years ago

Some last review comments:

Thanks

ManasiGandhi commented 4 years ago

Published link of the topic on the live OL site https://openliberty.io/docs/ref/general/#mp-config.html