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

Tests API

Tests API

94500f2d1984cd5da6e445d89819052b?s=128

Yoshiki Nakagawa

August 30, 2016
Tweet

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ΤϯυϙΠϯτຖͷΞΫηε੍ޚ
  7. Tests API Unit test $ go test -run TestHogehoge How

    do we test API endpoints??
  8. Runscope

  9. Runscope • Monitor API perfomance • CI

  10. Monitor API performance Set schedules for this test Demo

  11. Ghost Inspector

  12. Ghost Inspector Ghost InspectorΛࢼͯ͠Έ·ͨ͠ FYI (૿੮)·ͩ໨ࢹͰফ໣ͯ͠Δͷʁϒϥ΢βνΣοΫࣗಈԽͷ͢͢ Ί

  13. Demo

  14. Automate everything Commit => Unit Test => Deploy => API

    Tests => !