{"id":1233,"date":"2020-04-03T01:01:00","date_gmt":"2020-04-02T23:01:00","guid":{"rendered":"http:\/\/blog.zhaw.ch\/splab\/?p=1233"},"modified":"2020-04-03T10:17:59","modified_gmt":"2020-04-03T08:17:59","slug":"investigation-of-self-management-for-flask-based-services","status":"publish","type":"post","link":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/","title":{"rendered":"Investigation of Self-Management for Flask-based Services"},"content":{"rendered":"\n<p>Self-management is an important property of software services to increase the degree of exploiting benefitial characteristics of underlying runtime systems. Whether such services run in a managed cloud environment, on a device or somewhere else in the computing continuum, there may always be limitations in the managing runtime platform that a complementary or overarching application-level management can help to overcome. Using a Python <a href=\"https:\/\/flask.palletsprojects.com\/en\/1.1.x\/\">Flask<\/a>-based web service as example, this research blog post informs about our ongoing investigations into two specific self-management aspects: runtime resilience and feistiness.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>We have previously &#8211; five years ago &#8211; <a href=\"https:\/\/doi.org\/10.1016\/j.future.2016.09.002\">reported on self-management<\/a> in cloud-native applications concerning resilience and elastic scalability, and moreover &#8211; two years ago &#8211; on the need for <a href=\"https:\/\/digitalcollection.zhaw.ch\/handle\/11475\/2667\">adaptive self-management<\/a> in clouds. Since then, the proliferation of computing paradigms has evolved significantly. Multi- and cross-cloud setups have become common practice, serverless computing is now an indispensable ingredient of modern economic application design, and <a href=\"https:\/\/blog.zhaw.ch\/splab\/2020\/02\/11\/research-slam-on-fog-cloud-continuum-framework-and-other-swiss-latin-american-cooperation-projects\/\">cloud-fog continuums<\/a> are becoming more widespread while advanced concepts such as <a href=\"https:\/\/ieeexplore.ieee.org\/document\/8969621\">osmotic computing<\/a> are emerging as well. These evolving paradigms have the potential to make application and service engineering easier across all domains, but to exploit this potential, the self-management aspects need to be considered by design. This can be discussed on an abstract level, although for better and more intuitive understanding, this text exemplifies these aspects with a very ordinary Flask-based application. Flask is a typical Python web service framework that uses declarative routes (specified with Python decorators) to map local functions to HTTP endpoints. Flask comes with its own minimal HTTP server, but can also be proxied by more capable servers such as Apache httpd. For rapid prototyping, a complex setup is however prohibitively expensive in terms of effort. Either a managed (PaaS-based) solution or a somewhat capable zero-configuration self-hosting are therefore alternatives. Given the limited capabilities of PaaS even now &#8211; after ten years of being on the market &#8211; this presents interesting opportunities for self-management. To keep the expenses in check, we define the requirement of achieving the self-management aspects without any modification to the original Flask code.<\/p>\n\n\n\n<p><strong>Application and Service Model<\/strong><\/p>\n\n\n\n<p>The structure of a Flask application is shown below. It consists of a number of functions (or methods) that are exposed to the outside through an HTTP interface. RESTful service endpoints are defined by the port the service is running on in conjunction with declarative route decorators that may contain light-weight validation information such as type specifications. When the application runs with the <a href=\"https:\/\/flask.palletsprojects.com\/en\/1.1.x\/server\/\">built-in web server<\/a> (others are possible following <a href=\"https:\/\/www.python.org\/dev\/peps\/pep-3333\/\">WSGI<\/a>), it logs HTTP responses, but also exceptions associated with HTTP status code 500, to standard output. While this text is specific to Flask, many application service frameworks for many programming languages have a quite similar model.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\nfrom flask import Flask\napp = Flask(__name__)\n\n@app.route('\/')\ndef overview():\n    return json.dumps({\"status\": \"ok\"})\n\n@app.route('\/user\/&lt;username&gt;')\ndef getuser(user):\n    raise Exception(\"user unknown\")\n\n@app.route('\/&lt;int:year&gt;')\ndef getyear(year):\n    return str(year)\n\nif __name__ == '__main__':\n    app.run(host=\"0.0.0.0\", port=8080)\n<\/code><\/pre>\n\n\n\n<p><strong>Resilience<\/strong><\/p>\n\n\n\n<p>A resilient application continues to run, or degrades gracefully and in a controlled manner, when the runtime environment is affected by failures. Most cloud platforms handle certain failure types well, especially crashes that are mitigated by restarts. One of the trickier failure classes is slowness, including its extreme variant, a hanging process. Following the cattle-instead-of-pets design of microservices, resilience of an existing Flask application can be achieved by wrapping it into a slowness\/crash detection supervisor script. For Flask applications, this is implemented in the &#8220;<strong><a href=\"https:\/\/raw.githubusercontent.com\/serviceprototypinglab\/selfmanaged-flask\/master\/flasksupervisor\">flasksupervisor<\/a><\/strong>&#8221; script that is prepared to run both as root and as unprivileged users, depending on the ability to incorporate its invocation into a system startup process (e.g. through a systemd unit file that is accompanying the script as template).<\/p>\n\n\n\n<p><strong>Feistiness<\/strong><\/p>\n\n\n\n<p>Feistiness refers to the ability of an application to fend off malicious invocations. For a web service, specifically, it means that an application is able to impose connection limits by itself, in terms of blocking IP addresses and host names, throttling connections or prioritising peers. Again, the detection of adversaries and their blocking can be implemented without any modification to the application by wrapping it into a script that parses the Flask code, extracts knowledge about permissible HTTP endpoints, spawns the code and registers unexpected URLs by tracking the HTTP log of the spawned code after proxying all requests. This is implemented in the &#8220;<strong><a href=\"https:\/\/raw.githubusercontent.com\/serviceprototypinglab\/selfmanaged-flask\/master\/flask2ban\">flask2ban<\/a><\/strong>&#8221; script.<\/p>\n\n\n\n<p>This is preliminary, code-driven research that comes without a quantitative evaluation at this point in time. We have however identified a number of use cases especially for business applications, and will work with industry partners to outline with empirical techniques the value in application self-management. In the meantime, we hope that these code examples also inspire thinking about application management choices and the resulting self-management aspects.<\/p>\n<div class=\"pt-sm\">Schlagw\u00f6rter: <a href=\"http:\/\/blog.zhaw.ch\/splab\/tag\/api\/\">api<\/a>, <a href=\"http:\/\/blog.zhaw.ch\/splab\/tag\/cloud-native\/\">cloud-native<\/a>, <a href=\"http:\/\/blog.zhaw.ch\/splab\/tag\/logging\/\">logging<\/a>, <a href=\"http:\/\/blog.zhaw.ch\/splab\/tag\/paas\/\">paas<\/a>, <a href=\"http:\/\/blog.zhaw.ch\/splab\/tag\/self-management\/\">self-management<\/a><br><\/div>","protected":false},"excerpt":{"rendered":"<p>Self-management is an important property of software services to increase the degree of exploiting benefitial characteristics of underlying runtime systems. Whether such services run in a managed cloud environment, on a device or somewhere else in the computing continuum, there may always be limitations in the managing runtime platform that a complementary or overarching application-level [&hellip;]<\/p>\n","protected":false},"author":203,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[4],"tags":[130,20,145,87,144],"features":[],"class_list":["post-1233","post","type-post","status-publish","format-standard","hentry","category-research","tag-api","tag-cloud-native","tag-logging","tag-paas","tag-self-management"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Investigation of Self-Management for Flask-based Services - Service Prototyping Lab<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Investigation of Self-Management for Flask-based Services\" \/>\n<meta property=\"og:description\" content=\"Self-management is an important property of software services to increase the degree of exploiting benefitial characteristics of underlying runtime systems. Whether such services run in a managed cloud environment, on a device or somewhere else in the computing continuum, there may always be limitations in the managing runtime platform that a complementary or overarching application-level [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\" \/>\n<meta property=\"og:site_name\" content=\"Service Prototyping Lab\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-02T23:01:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-03T08:17:59+00:00\" \/>\n<meta name=\"author\" content=\"Josef Spillner\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Josef Spillner\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\"},\"author\":{\"name\":\"Josef Spillner\",\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/#\/schema\/person\/33a5227c6cc1fa3329279d33c3cc440e\"},\"headline\":\"Investigation of Self-Management for Flask-based Services\",\"datePublished\":\"2020-04-02T23:01:00+00:00\",\"dateModified\":\"2020-04-03T08:17:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\"},\"wordCount\":760,\"commentCount\":0,\"keywords\":[\"api\",\"cloud-native\",\"logging\",\"paas\",\"self-management\"],\"articleSection\":[\"Research\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\",\"url\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\",\"name\":\"Investigation of Self-Management for Flask-based Services - Service Prototyping Lab\",\"isPartOf\":{\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/#website\"},\"datePublished\":\"2020-04-02T23:01:00+00:00\",\"dateModified\":\"2020-04-03T08:17:59+00:00\",\"author\":{\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/#\/schema\/person\/33a5227c6cc1fa3329279d33c3cc440e\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\/\/blog.zhaw.ch\/splab\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Investigation of Self-Management for Flask-based Services\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/#website\",\"url\":\"https:\/\/blog.zhaw.ch\/splab\/\",\"name\":\"Service Prototyping Lab\",\"description\":\"A Blog of the ZHAW Zurich University of Applied Sciences\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.zhaw.ch\/splab\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.zhaw.ch\/splab\/#\/schema\/person\/33a5227c6cc1fa3329279d33c3cc440e\",\"name\":\"Josef Spillner\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/c57d7019e91373902c08eac230e003cb4f8498ecf68c9d119e9ecb82fdf6c400?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c57d7019e91373902c08eac230e003cb4f8498ecf68c9d119e9ecb82fdf6c400?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c57d7019e91373902c08eac230e003cb4f8498ecf68c9d119e9ecb82fdf6c400?s=96&d=mm&r=g\",\"caption\":\"Josef Spillner\"},\"description\":\"Head of the Service Prototyping Lab. Research on distributed systems and application computing paradigms. Senior lecturer at Zurich University of Applied Sciences.\",\"url\":\"https:\/\/blog.zhaw.ch\/splab\/author\/spio\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Investigation of Self-Management for Flask-based Services - Service Prototyping Lab","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/","og_locale":"en_GB","og_type":"article","og_title":"Investigation of Self-Management for Flask-based Services","og_description":"Self-management is an important property of software services to increase the degree of exploiting benefitial characteristics of underlying runtime systems. Whether such services run in a managed cloud environment, on a device or somewhere else in the computing continuum, there may always be limitations in the managing runtime platform that a complementary or overarching application-level [&hellip;]","og_url":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/","og_site_name":"Service Prototyping Lab","article_published_time":"2020-04-02T23:01:00+00:00","article_modified_time":"2020-04-03T08:17:59+00:00","author":"Josef Spillner","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Josef Spillner","Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#article","isPartOf":{"@id":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/"},"author":{"name":"Josef Spillner","@id":"https:\/\/blog.zhaw.ch\/splab\/#\/schema\/person\/33a5227c6cc1fa3329279d33c3cc440e"},"headline":"Investigation of Self-Management for Flask-based Services","datePublished":"2020-04-02T23:01:00+00:00","dateModified":"2020-04-03T08:17:59+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/"},"wordCount":760,"commentCount":0,"keywords":["api","cloud-native","logging","paas","self-management"],"articleSection":["Research"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/","url":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/","name":"Investigation of Self-Management for Flask-based Services - Service Prototyping Lab","isPartOf":{"@id":"https:\/\/blog.zhaw.ch\/splab\/#website"},"datePublished":"2020-04-02T23:01:00+00:00","dateModified":"2020-04-03T08:17:59+00:00","author":{"@id":"https:\/\/blog.zhaw.ch\/splab\/#\/schema\/person\/33a5227c6cc1fa3329279d33c3cc440e"},"breadcrumb":{"@id":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.zhaw.ch\/splab\/2020\/04\/03\/investigation-of-self-management-for-flask-based-services\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/blog.zhaw.ch\/splab\/"},{"@type":"ListItem","position":2,"name":"Investigation of Self-Management for Flask-based Services"}]},{"@type":"WebSite","@id":"https:\/\/blog.zhaw.ch\/splab\/#website","url":"https:\/\/blog.zhaw.ch\/splab\/","name":"Service Prototyping Lab","description":"A Blog of the ZHAW Zurich University of Applied Sciences","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.zhaw.ch\/splab\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/blog.zhaw.ch\/splab\/#\/schema\/person\/33a5227c6cc1fa3329279d33c3cc440e","name":"Josef Spillner","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/c57d7019e91373902c08eac230e003cb4f8498ecf68c9d119e9ecb82fdf6c400?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c57d7019e91373902c08eac230e003cb4f8498ecf68c9d119e9ecb82fdf6c400?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c57d7019e91373902c08eac230e003cb4f8498ecf68c9d119e9ecb82fdf6c400?s=96&d=mm&r=g","caption":"Josef Spillner"},"description":"Head of the Service Prototyping Lab. Research on distributed systems and application computing paradigms. Senior lecturer at Zurich University of Applied Sciences.","url":"https:\/\/blog.zhaw.ch\/splab\/author\/spio\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/posts\/1233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/users\/203"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/comments?post=1233"}],"version-history":[{"count":8,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/posts\/1233\/revisions"}],"predecessor-version":[{"id":1244,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/posts\/1233\/revisions\/1244"}],"wp:attachment":[{"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/media?parent=1233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/categories?post=1233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/tags?post=1233"},{"taxonomy":"features","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/splab\/wp-json\/wp\/v2\/features?post=1233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}