Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tests API

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Tests API

Avatar for Yoshiki Nakagawa

Yoshiki Nakagawa

August 30, 2016
Tweet

More Decks by Yoshiki Nakagawa

Other Decks in Programming

Transcript

  1. Tests API Agora Tech Talk #5 Aug / 30 /

    2016 @yyoshiki41 Yoshiki Nakagawa
  2. Health Check API Runscope Blog Build a Health Check API

    for Services Underneath Your API TL;DR • Create separate health check API endpoints for all services! • Set up notifications!
  3. Health Check API How do we monitor them? • MySQL

    • Redis • BIND • etc ... They don't come with (HTTP) RESTful APIs ! Communicate over lower-level protocols like TCP and UDP.
  4. Good Example! ElasticSearch $ curl localhost:9200/_cluster/health { "cluster_name": "pairs-jp-es-cluster", "status":

    "green", "timed_out": false, "number_of_nodes": 6, "number_of_data_nodes": 5, "active_primary_shards": 8, "active_shards": 32, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100 }
  5. Create Health Check API Endpoints! Check MySQL connection <?php $config

    = [ "server" => "databaseserver:3306", "username" => "root", "password" => "password" ]; header('Content-type: application/json'); $link = new mysqli($config['server'],$config['username'],$config['password']); if ($link->connect_errno) { http_response_code(503); echo('{ "status": "Unable to connect" }'); } else { http_response_code(200); echo('{ "status": "Connection successful." }'); }
  6. Caution Do not open to the public ! Access control

    by ip address or authentication. nginx Advent Calendar 2015 Day21 nginx APIΤϯυϙΠϯτຖͷΞΫηε੍ޚ