The Bootiful Application (Josh Long, USA)

yeah okay good stuff alrighty everybody come on in have a seat please come on in come closer we want to make sure you can see the Fontan see the type on the screen come on in alrighty everybody welcome everybody how was the show great yeah right on I understand that you have many options right now you have many rooms you could be in right now so I appreciate you coming to spend the time with me today so welcome to my talk we’re gonna go through a lot of code I love code code to me is very very important if you’re among the 4 billion people on the planet that are connected to the internet only half of the human population then code is very very much what you can do to change the world it’s for those half for the half of the people on the population connected to the Internet code is the single most impactful thing you can do so I always start my presentations with code which is there online on github so github.com forward slash charge long forward slash bootiful micro-services please grab that URL for later and then once you’ve done that close your phone’s close your laptop’s give yourself time to really just follow along alright I’m on the Internet I’m on the Internet I’m happy to carry this discussion forward I love hearing from you I love answering questions I love talking to the community members so I’m on the Internet I’m on I’m on Twitter Twitter how many of you are on twitter twitter twitter – 2016 twitter Twitter anybody all right if you’re not on Twitter get on Twitter it’s awesome I love Twitter it’s like the new IRC it’s just really cool what about email e-mail e-mail email anybody does anybody have email well if you have one of those social networks as well as the kids call it please don’t hesitate to reach me there let’s carry this discussion forward beyond our beyond the constraints of our little bit of time together okay I am Josh long as I mentioned before I’m a spring developer advocate on the spring team at pivotal how many of you have heard of spring spring spring good stuff I’m an open source engineer and contributor number one leading top ranked number one over seven years number one contributor of bugs but still number one number one seven years running more bugs per lines of code contributed than anybody else it’s me thank you thank you thank you I’m a Java champion right means I get to spend a lot of time working with organizations so the customers are the community members talking about how to level up their spring how to be how to build next generation awesome applications I care very much about that process I care very much about working with the community and so on I’m also a book author and a training author I’ve done this is my fifth book I’m working on it right now it’s not done yet but it will be done soon this the book by the way for those of you who are wondering that’s a blue eared Kingfisher it’s a bird from the javanese and islands a bird it flies from from java java bird cloud bird fly cloud bird java no no no okay you’ll get it it’s gonna come to you it’s a good bird I had to fight for that bird so anyway lots of stuff right and I work at pivotal pivitol we have lots of great open source technologies and I love open source we all love open source but make no mistake it is not the reason we are here it is not the reason people go to pivotal to work the reason we care about open source is because it is a means to an end that helps our customers our community our organizations that we work with go quickly and safely to production and that is after all at the end of the day the most important thing how quickly in the modern world can you take an idea from product management all the way to production organizations they struggle with this they understand that speed is a differentiator speed is what helps you win in a marketplace have you ever read that amazing book the inmates are running the insane asylum anybody it’s a book that has a lot of good ideas and

one interesting point that they make in that book is that if you take any business and you add software you get a software business it’s seriously what is the number one taxi company in the world today that’s a software business not a taxi business what is the number one hotel business in the world today Airbnb right that’s a software business not a hotel business if you what is the number one video rental service in the world today software business right these organizations run themselves as software businesses agile agile businesses and if you are running yourself as if every business today is a software business then the only way to compete is to deliver better software faster right so this becomes very important organizations understand that they need to go fast and so they look for ways to shorten the time from concept to production how quickly can we innovate how quickly can we if we’re going to make mistakes at least make them quickly and then figure them out and then fix them and so there’s a lot of things that stop people from doing this today there’s a lot of things that stop their ability to do that there’s a whole ecosystem of things that need to be addressed but at least when it comes to application development there’s concerns that get our ability to move quickly to production production is a wonderful place I love production you should love production if you can go to production you should the weather is amazing it’s great bring the family bring the kids go to production as awesome as you can production is amazing right but if you’re trying to get there you have to care for certain things things like you know observability how does your application exist in a production environment how does it work with operations things like this so you need to be able to develop code quickly and then move it to production quickly so that’s what we’re gonna look at today we’re gonna look at things that we’re gonna look at something called spring boot which helps us build applications quickly and then you know with that in mind we’re gonna understand that spring boot is an opinionated framework it’s an opinionated approach to the Java ecosystem the opinion by the way since you’re wondering is that production is awesome right so those are my slides what do you think good stuff maybe so what we’re gonna do is we’re gonna build a simple application today my I always start here this is my second favorite place on the Internet so again production is first I love production I keep that bookmark but if you’re not already in production and you want to begin your journey to production then you start here and start that spring that i/o if you find yourself lacking for inspiration in the early morning before your cup of tea or coffee start that spring that i/o if your children are restless and they cannot sleep start that spring die oh and if you suffer from indigestion or heartburn after a big meal and you want relief start that spring dot IO this is my second favorite place on the internet what we’re gonna do is we’re gonna build a very very simple service here we’re gonna choose reservation service actually I’ll start from zero there we go we’re gonna build a new service when it called the reservation service we’re gonna bring in web support we’re gonna bring in h2 which is the in-memory embedded sequel database we’re gonna use the Java persistence API because I make poor life decisions so JPA I’m gonna bring in the actuator for operational concerns I’m gonna bring in the time leaf template and Technology rest repository support the remote shell I’m gonna bring in the actuator itself don’t I already have that yep I’m gonna bring in the how browser I’m gonna bring in do I need anything else Vaadin right cuz why not why not I’m just gonna I’m gonna throw everything in here and we’re gonna do it very quickly the goal is not to show you how to do one thing it’s to show you how easy it is to do all of these things now I have choices I could make here there’s other choices I could elect to switch to the full version and here I’m given a list of of checkboxes see all these checkboxes checkboxes for every kind of use case that you could imagine lots of tech boxes Jo cube you know no sequel technologies cloud computing technologies all these different choices so many good choices so I could I could of course choose specifically each one of these different dependencies that’s fine right do you remember do you remember those stupid advertisements from Apple there’s an app for that anybody know there used to be a commercial they used to say oh you want to do this you want to do that no

problem on the iPhone there’s an app for that well screw that there’s a checkbox for that right much better now there are some other choices here that you can make you can choose for example which version of which you know which language you want to use any language on the JVM that supports annotations and objects will work just fine so again feel free to choose whatever you want or even Scala it’s not on this list but you could choose that as well doesn’t matter the rest of these however are non choices these are choices in the same way that stripping naked and running in Fiza is a choice you could youcould but but but but don’t don’t please please don’t so here for example you might choose an older version you might choose an older version of the JVM that’s a terrible idea just just terrible these are end of life why would you choose them that’s terrible don’t don’t choose these these are non choices right these are choices that you could make but that you shouldn’t and then finally here we have a very tough question a very tough choice that people struggle with too often the question of packaging the choice of packaging and so to help you I’m going to do my best to explain here now when to choose which and when ok if by some crazy freak accident of physics you find yourself stuck in the very very very very very very distant past far beyond modern help then then choose dot war but if you’re here with me in 2016 the future really then then choose dot jar this is a big part of my overarching guiding personal philosophy of make jar not war ok again you have options you have choices you should do what works for you ok thank you make jar noir and by the way I just came from this other conference that that likes this stuff and that that conference see this the make jar not water thing is getting a little out of hand and so people are can you see that it says make jar not war yes that’s a spring conference of course but still like yes anyway so now we’ve got a new application let’s go ahead and hit generate and we’re gonna open this up in our IDE hello computer there we go well open this up in our IDE and it doesn’t matter what you use how many of you use NetBeans NetBeans is cool hey I’m a fan you know I’ve I’ve I’ve I’ve gotta tell you it’s good stuff they have the spring boot tools for NetBeans that’s awesome if you like that how many of you using eclipse good stuff as well it’s fine right what about IntelliJ how many of you gee wait a minute seriously wait wait hold on that’s crazy everybody using IntelliJ put your hand up that is insane that’s so cool it used to be 5050 and now it’s Wow 80 90 % look at that okay so I’m gonna make this font the size a little larger I realize that this is not gonna be small enough for you all better okay so close all that and what I have here is a stock standard maven build it’s a maven build that has a dependency up here spring boots start apparent spring boots start a parent intern has other dependencies spring boot dependencies and here you can see all the different versions of all the different libraries have been managed for you all the different libraries have been made to align up so that if you’re using project a and project B and they both use project C then you get the correct version for both project gain project b1 version both of them right you don’t get problems with dependencies we have people on the spring boot team who are bald no hair gone all of it no hair zero they have solved this problem for you they have managed the dependencies for you okay this is a very very big feature so we have that already out of the box and now we have dependencies and these dependencies correspond to the check boxes that we selected on start that spring that I oh my second favorite place on the internet these dependencies are opinionated dependencies they bring in everything you need to get started building an application in 2016 using these dependencies so suppose that I want to build an application that uses JPA like this spring boot starter data JPA that dependency has everything I need in 2016 it has J dependency management has ORM support has transaction support JDBC port JDBC

support spring that @j PA all of hibernate 5xj PA – directs everything right it has everything I need to be productive out-of-the-box and here I can now build a very very simple domain model we’re going to say class reservation and we’re gonna give it an ID and a private field reservation name and this field is going to be an auto incrementing auto incrementing unique primary key value I’ll use JP to signal that and I’m going to make this a JP entity okay so there’s JP a and that my friends that right there is the purest cleanest most concise expression of this entity it’s so beautiful but this is Java so we have to add a lot more we have to add a lot more a lot more there’s this we’re gonna add another constructor this one for JP a right why why is this here we need to have a two string we need another Gator for the reservation name there we go that’s that’s better better anyway now I’ve got an entity I can save it in the database this will be mapped to a column called ID this one will be mapped to a column called reservation underscore name and this will be mapped to a table called reservations like that okay what I want to do now is Express a repository now and repository is a very simple thing if you’ve ever read dr. Eric Evans is amazing book domain-driven design then you know that a repository is an object that handles the underlying persistence logic the creating the reading the updating in the deleting this is interesting in that it helps your code be more concise but it takes time it doesn’t help your business at all it is not why you are here it is what aging Cockroft the lead devops and web engineer for Netflix used to say as or used to call as undifferentiated heavy thing it’s work that doesn’t profit you it doesn’t benefit you at all and so you should not waste more than a minute on this ever right we’re gonna let the Machine do it that the Machine do the dumb work and the reason we’re gonna let the Machine do that dumb work is because it’s not going to help you if you do the dumb work right nobody’s going to ever come to you late on a Friday night and put their hands on your shoulders and say good job good job well done you wrote the best to select all from foo where ID equals question mark nobody cares nobody so don’t waste more than a minute on that dumb dumb logic we’re gonna create an interface a declarative interface using spring data modules spring data is an umbrella project there are many modules inside of it including spring data Cassandra Couchbase react MongoDB Redis geode neo4j I mean all sorts of modules so we provide these interfaces these are declarative and they provide base functionality but make no mistake this is not the lowest common denominator we’re not trying to provide one API across all of them we provide the best of breed support where appropriate but we don’t try and pretend that these database technologies can do things that they can’t for example Cassandra for all of its many many many benefits and features doesn’t have the best ad hoc paging and sorting support so you’re not gonna find equivalent support there right but you will for example here you can even define custom finder methods you can say I wanted to express a finder based on the reservation name type so find my reservation name and the reservation name is the field and the object and at runtime this gets turned into a query something like select all from reservations where reservation underscore name equals R in and that’s by convention right that’s based on the name of the method of course you can override this provide your own Act query like this and you could use the underlying persistence technology and you should okay again if you’re using something like neo4j use the technology use the best features of that absolutely in our case however it doesn’t really add anything so we don’t need to but you could and you should if you want to now finally we need to tell spring that we want to create some sample data some records that we can put in the database and then use now remember this is a spring application how many of you have used a spring for good stuff Wow what about spring boot few of you good stuff so what about how many of you are in spring to that five it’s okay you’re among friends you’re you’re among friends I give hugs open sores hugs well anyway if you’re on one of those versions of spring then you know that this annotation is a stereotyped annotation it actually is equal to three other annotations like this okay so there it is components can that tells spring to look in the current package

and find all the beans that I have stereotyped annotations this tells spring that this class is a dependency is it is a configuration class that provides beans and then this one is the one that turns on spring boots basic functionality I I just want to tell you that while I like spring boot and I’m a big fan I feel like the spring team you know I feel like they could have done a better job on the name okay I’m just gonna say it I fought with the spring team on this I we had arguments okay I thought this could have been named something a little bit better like I want to go home early right and again whatever it’s fine they didn’t choose it whatever so I’m not bitter we’ll just leave it like that so now once that’s done I can create a regular component class dummy CLR implements command line runner and command line runner is an object it’s a callback interface when spring boot starts up it’s going to call the command line runner interface passing in public static void main string args to the void run method and we’re going to tell spring that we want a collaborating object right we want a collaborating object like this this is the correct way to do this is to create a constructor and then define the dependency as part of the constructor the wrong way to do it of course is to use field injection like this never ever do this not even when you’re all by yourself all alone at home and no one is looking never do this every time you do this a unit test don’t do it so what we’re gonna do we’re gonna say here’s a constructor good at Auto wired and finally we’re gonna create some sample data say stream dot of and let’s see my name is Josh under Nikola with some names what’s your name boss how do you spell a buddy gee oh gee ha ha damn it ok dr z is that is that it what is it then what okay when he ah thank you who cool name nice to meet you what else do we got what’s your name boss and there’s sunglasses how do you spell that buddy LAN nice to meet you too what one more I need one more so it too even what about you boss yep yeah yeah like that lovely to meet you all thank you that’s six that’s an even number I can sleep well tonight and so what we’re gonna do is we’re gonna go through each element in the stream and we’re gonna have the Java 8 API call back this method passing in the name and then we’re gonna save each record into the database we’re gonna say a new reservation name okay and there we go and that you know that’s that’s probably enough but again how many of using Java 8 oh so you know so Java 8 is awesome I love job eight you should love to have eight as well right in Java eight to have a nice feature called lambdas lambdas are feature that only other modern languages only other very very modern languages like Java 8 and Scala and groovy and Kotlin and JavaScript and COBOL and C and C++ danforth and PHP and JavaScript and typescript and basic and Visual Basic and Objective C and visual basicnet and typescript an equi script and closure and Lisp and small talk and Perl Python Ruby Lua or Lang go Haskell only these other modern languages from the last 50 or 60 years have this feature right and so as a Java champion as a Java champion I’m very happy to talk about a feature that we introduced into Java two-and-a-half years ago so so there’s that there’s that now I can say for every reservation in the repository find all and then visit each it and I can also use a lambda here as well I can say call the print line method but this is pretty wasteful again what I’m trying to do is just to tell Jabba to call to print line method and pass in the are so there we go now if I run this if I run this recall that I have configured the h2 in memory embedded sequel database it’s on the class path and we haven’t

otherwise specifically configured an Oracle or Postgres or my sequel or whatever so it’s going to create an auto initialized embedded database oh that’s good stuff stay so we will see that hello computer will see that if everything has worked everything has worked there we go look at that it worked of course that worked this is a demonstration it was always going to work there’s always going to be the data on the command line that’s not really what I wanted to talk to you about although it’s good instead let’s talk about this now this is the ASCII artwork in spring boot this ASCII art work took a long time to get right we have people on the spring bootie who are doctors PhDs in their previous lives they worked in nuclear physics and they decided one day that they wanted to change the world so instead of working on nuclear physics and physics and science they joined the spring team so it makes me very happy to imagine that someday somewhere somehow someplace they got a github e issue and the github issue said we need good ASCII art work damn it and look at that it’s beautiful absolutely beautiful now I’m a big fan I think they did a good job but I want to take this moment while we have some time together maybe as a group maybe we could change the world a little bit I want to talk about what I consider to be a very serious deficiency or bug in the IntelliJ JetBrains product because I’m a fan but what the hell what the hell why is that there that’s a dumb feature now now I’m a big fan and they did good work so I did what I did what all modern adults do when they’re confronted with challenges in the real world I went on the internet and I cried and there I was given a message of hope by my friend Jana Braun who’s a software developer by passion at JetBrains and he responded with this message that I want to share with you now as a message of hope don’t worry my friends we’re gonna make IntelliJ great again it’s gonna be okay now some people ask me can I change the ASCII artwork can I change it or can I override it and that’s a stupid question because why would you want to change that you couldn’t possibly do a better job or at least that’s what I used to think but then I went to Canada and I’ve never I don’t know if you’ve ever been to Canada but it snows all year 365 days a year snow even when it’s blue in the sky and the Sun is out somehow snow even when it’s raining there’s raindrops and snow drops next to each other we don’t know how it rains and snows at the same time but as a result people in Canada spend a lot of time indoors working on stuff like art and poetry and whatever so there’s some very talented people they dream of nice sunny days which will never happen so I don’t know how that works you know and it’s kind of weird because all of Canada is right above the United States if they were to go just across the border no snow just it’s just right there at the border snow and then ten feet below no snow we don’t know how but anyway because they spend all their time inside there are some very talented people in Canada who are very good artists so if you’re from Canada this is for you I’m gonna show you how to override the ass get work okay now what I’ve done is I’ve copied this artwork here source main resources banner txt okay and what I’m going to do is I’m going to restart this application with my new banner artwork in place and there we go so there’s a few things I want to show you a few things I want to I want to share with you first of all first of all now and then and then also this is basically why we’re here this is my favorite part so now we’ve got an application we’ve written data to the database we can read and write from the underlaying database

are we ready to go to production not yet we’ve got an existential philosophical question before us if we write to the database but we can’t read from the database using a REST API did we actually write to the database and the answer’s no you didn’t so what we need to do is we need to build a REST API to read that data there’s a couple of ways to do this we could go back to our build here spring boot starter web like this okay add that no problem and we could just build a very simple rest controller like this at rest controller come on class reservation rest controller and we create a repository and inject that in there as well okay and we can add a constructor will say collection of reservation reservation collection reservations okay and we can map this to an endpoint like this mapping method equals get value equals reservations and we create a constructor of course add this as well and then just return the data then start reservation repository not find all and then there we go and that would work right that would be that would be enough but that’s a very low-level API so instead of writing all that code and doing the busy work that the repository already knows how to do we’re gonna bring in spring boot starter data rest like this okay spring boots started data rest gives us the ability to turn my repository which already knows about how to map the business state entities to the you know to the appropriate corresponding business state transitions creation reading updating and deleting and then map those to the appropriate HTTP verbs so I can say at repository rest resource I’ll map this at as so and I’ll say rest resource path equals by name and I’ll say at per am okay and then if we start that we’ll get an auto created Auto you know generated rest api for us so here’s this reservations and there’s our data you can see the payload is there great we have hypermedia these links these links are an implementation of the design pattern huh tos hypermedia as the engine of application state it’s the idea that every rest resource should have enough information in the resource for the client to be able to use that resource without any off priori knowledge it’s a very good idea in a distributed systems world it helps decouple the client from the services this hyper media is contextual so these links get created dynamically you can register your own links very much like in the real world when you go to amazon.com for example and you add a product to the shopping cart there is no link offering you a refund or your money back for products for which you have not paid all right that makes sense similarly you would not see a link here for certain things that are not appropriate based on the state of the resource so now we have a REST API we can also do things like deep linking right we can see you you know there we go we can do search as well so I can say search and I’m gonna do a search by name and of course Who am I gonna look for well I’ll search for my friend this guy here search by name are N equals and then that and then voila see the database can spell his name even if I cannot so it found it it’s fine right we got the data back very quickly and we can even do paging and sorting remember so reservations page equals one and size equals three so there one two three and then links about the resources so now we’ve got a REST API it’s pretty smart we should build a web application this is after all 2016 so it’s very common to have something that you may load on the simplest case you might have a static page that you want to load like this high dot HTML maybe you have your angular or your JavaScript or whatever oh okay right that’s a static but JavaScript or CSS that would be fine a very common thing is of course to have a a MVC controller something that has very very minimal server-side processing and then loads a template and you can use any kind of template you want so I’m going to say reservation NBC controller and we’ll come back to this in a second but let’s go see if that worked so if I go to here now hi dot HTML there’s that now let’s go ahead and build a very simple spring MVC controller I’ll do the same thing private reservation repository okay and I’ll say here’s a constructor on a wired and I’m gonna create an endpoint that was returned a page based on some model data okay and the model data is a glorified map basically it’s a map containing context data that we’re gonna serve to a template to be rendered and I can name

it I can name the page whatever I want so you know anything it could be it could be anything it doesn’t have to be anything at all related to the name of the method so I’m gonna just name it something crazy like reservations dot PHP right so there’s that and I’ll say add attribute reservations and I’ll just add the data from the repository like so and then I’m gonna return a string that’s going to be used by the spring MVC framework to look up a template which it’s going to find by convention in the source main templates directory you know dot X dot HTML and the reason it’s going to know to do that is because we’re gonna give it a view resolver that is going to look for something called time leaf thyme leaf is a templating technology that you can use to render service cited pages it’s very nice it’s html5 friendly you can open it up in your modern designer tools and it’ll still work correctly right this is not the same as JSP JSP does not have that benefit have you ever gone to the office and spoken with your colleagues and then you walk into the office and then at the office you you find a bag of of big red flaming poop do you know did I’m talking about the bag of feces on your desk that’s because you gave the designers JSP pages and they can’t open that they can’t even look at it right so if you want to make friends don’t don’t don’t use JSP that’s it’s simple so I’m gonna use server-side template this is very very simple it’s like server-side angular for each reservation are in the reservations model attribute it’s gonna print out the ID in the reservation name and I’m gonna go ahead and restart now remember you can use anything I’m using timely if you could use velocity you could use free marker you could use moustache or Jason V server pages or or whatever right you can even use JSP but but don’t don’t don’t right so what did I name this I said reservations dot PHP reservations dot PHP there’s my data very very simple I am a designer of course now we could also build a you know sometimes we have data driven kind of user interfaces with lots of forms and components and I don’t want to worry too much about the layout and all the JavaScript and all that for this there’s something called Vaadin Vaadin is very very cool because it’s built on top of Google web toolkit so all the user interfaces are compiled into JavaScript and the business logic lives on the server so I’m going to go ahead and bring in the third-party Vaadin remote shell here like this and I’m gonna build a very very simple user interface using Vaadin which is a component centric kind of thing I’m gonna make my reservation type public for this okay I’m gonna say class reservation UI extends UI okay and I’ll create the anit method and then the anit i’ll create a grid like this new grid and in the grid I’m expected to pass in a new bean item container which contains data of type reservation class whose data I’m gonna get from this injected repository right ok there’s this and I’ll say this dot reservation repository at find all and I’ll set content equals to grid grid set size full there we go now if I restart we should see oops I forgot to give it a name that’s not gonna work I need to register this bean obviously so spring can find it it’ll be reservation GUI and I’m gonna give it a theme right I’ll say that the theme is valo this is a stylesheet and style you know kind of definition from Baden and all I’ve done is I’ve created a grid with data inside of it I’ve passed it a data source basically this is what that is right good so now if I rerun the code here very simple but you can see it gives us a very simple data grid that you can sort and click and it has components and all that stuff right now if I even use source you can see there’s no html5 no HTML is just all JavaScript so it’s very very fast in the browser in the client ok so now I’ve got a web application did you say 10 minutes I’m out of time so we’ve got an application in the date we’ve got an application that’s reading for and writing from the day basis we’ve got a web application we’ve got a few different endpoints can I go to production probably not right not yet there’s a few things I need to care about first of all I need to support observability observability is the idea that my build my application can be monitored it can be made visible in production I want to expose a few different things so what I’m gonna do is

I’m going to bring in spring boots starter remote shell spring boot oh sorry spring data rest how browser and then spring boot starter actuator and then having done all that hard work I’m going to restart and what these are gonna do is it’s going to expose endpoints that support visibility into the application into what it’s doing into its internal state I also want to be able to support deploying this in production so I’m gonna make my jar executable like this so configuration Executive Bowl true and then when I’ve done that first of all I can go here refresh reservations no problem PHP there’s that right reservations 1 2 etc now I can go to metrics and metrics is a set of keys and values that enumerate information about the host and the node on which the application is running these are automatically provided for you things like the RAM the uptime the processors the memory that keep the non heap and even things like this request counter that shows me that I made three requests to reservations at PHP with status code 200 there are two types of keys and values here gauges and counters a gauge is a value that you can collect and understand in one you know one at all at the same time how much how many users are there connected to the server there’s 500 users that’s a gauge how much RAM do I have right now I have 2 gigs of ram oh yeah there’s 2 gigs of ram a counter under the hand is a value that increments or decrements naturally one by one or you know minus one plus one I have one new HTTP request that’s a counter I have one less job on the task queue that’s a counter these things you can collect as well very easily right you can inject a counter service or a gauge service in in your code and collect custom counters as well things that you can use to quantify the state of the application and to correlate that with product management driven you know use cases right these metrics are very very powerful but they lack a critical dimension they lack the dimension of time without time we don’t know if these values are an improvement or a deterioration we don’t know what they were a minute ago an hour ago a week ago we don’t know if this is the average value roughly or if it’s the worst-ever right so to support that you can use the drop wizard metrics library the drop wizard metrics library was built by a guy named Cody Hale this is my friend Cody Hale this is also Kota Heil I just want you to appreciate how awesome he is and to think that he’s in your code all up in your metrics making things awesome look at the dog even the dog knows how amazing this moment is pink pink I just love it so Kota he’ll wrote this library called the drop Wizard metrics library the drop Wizard metrics library provides a histogram a histogram is a statistical structure that you can use to calculate things like the mean the median the average the max the 95th percentile the 99th percentile etc it also has a nice facility to publish metrics using something called a reporter so now you can publish these metrics to something like an open source time series database something like open TSD be in flux DB graphite ganglia Prometheus etc these databases are easy to support if you have the stats D protocol stats D is a protocol for shipping and publishing metrics it’s open source there’s actually it was written by a group called Etsy and Etsy built a daemon as well a thing that actually collects the metrics but nobody uses it because it’s based on note that Jas and note that Jess doesn’t scale so instead they just use the protocol now this is one set of endpoint here local host metrics there’s also env write environment variables there’s trace which gives you a trace which gives you the last HTTP requests that were made into the application the headers and so on there’s mappings which shows you all of the endpoints that are exposed from spring and the components that handle them so here’s reservation MVC controller reservations are PHP the method is get here’s beans right here’s all the objects in the object graph and of course you can customize all of this stuff as well you can go to your code and go to application up properties application of properties has many different properties that spring boot knows about for example suppose I have health you know health is an endpoint that tells me the state of my application what if I want to first of all what if I want to move all of my endpoints to b4 – admin I can go to our application of properties management dock context path

equals admin and then I can also override different health indicators I can contribute custom health indicators here as well using dependency injection so I can say at component class custom custom health indicator implements health indicator and there I have a very simple job when asked I say what is my status I could sit down or up or out of service or whatever but of course this conference here in keV we are never down right so we will just say status I huh Kampf okay that build and then I will restart so I’ve used two different ways to change the default behavior without having to rewrite everything I’ve used properties that spring boot knows about and notice I got auto completion this auto completion is driven by an SPI inside of spring boot itself any IDE spring boot tool suite sorry the spring tool suite or the spring boot tools for NetBeans or the intelligent Ultimate Edition has this auto completion if you’re using Emacs sorry but if you are then you can go to config props and it gives you all of these well-known properties for example management dot management context path management context path management that’s security management that port etc so now let’s check out our health you can see it worked it’s under admin now and there’s my custom status I can also access this information here via first of all can use J jmx like this so click on that insecure connection mbeans org spring free mcboot and auto configure here’s my custom health endpoint operations get the data there is my custom status right so I can do that I can also use the remote shell which is activated for us by default here when I had that on the classpath because I have that in the classpath so you can see here that come on come on yeah their comeback password there so by default it gives you a username and password that prints on the console it’s called user and then there’s a password you can view that password by using the remote Shell SSH – p2000 user at 127.0.0.1 enter paste and there’s a good quality ASCII art work you can ask for help you can say show me the metrics you can show endpoint invoke health endpoint right I don’t know if you can see that but it says I love je Kampf of course and of course my favorite perspective is dashboard dashboard gives you a running thread enumeration of all the threads the memory of the anon heap the heap the code cache all that stuff in the JVM for this node so you get a lot of support out of the box now when we want to customize this I want to move this to production it’s nice that this is a statically linked self-contained so-called fat jar or an American genre okay now you go to the Downloads directory here downloads reservation service you do maven – maven – d skip tests equals true because Yolo clean install and CD target and you can see that I have a so called fat jar this jar has everything I need it has a remote SSH server jmx support embedded Tomcat it has my hibernate support it has Vaadin it has everything I need to be able to deploy this application I can easily deploy this to production because it’s just Java – jar right of course I can also override parts of it by saying Java – D server dot port equals 80 10 – jar right that my server that port is another property that I could specify here instead but now I don’t have to recompile but the best part is actually that I don’t need to do any of that I can just do reservation service that jar and this bring begs us a brags a very simple question which direction does the JVM read bytecode or jar the operating system reads from the top down the JVM reads from the top from the bottom up so that means you can do some very interesting things like this where’s the Java – char and the way that’s working is this this script script script script scrip scrip scrip scrip scrip scrip scrip scrip scrip scrip my code right what we have here is a script a jar that supports init.d and system D so you take this jar put it

in the knit D directory and then the operating system will start it up it’ll manage the page for you manage the logs do all that stuff out of the box okay well we’re running a little long my friends so we’ve looked ever so briefly at how to build an application that supports observability how to create very good quality highly refined ask you at work and then how to manage this application in production the Java – jar thing is very simple it’s so simple that I could add it to an email and send it to my grandmother and because grandmother has JVM she has applets she can run this so if your operations teams have trouble running this maybe reconsider your career choices I don’t know I’m just saying now thank you so much my friends thank you so much for coming I hope you had something you could see I’m on Twitter if you need me please don’t hesitate to find me there thank you