Slide 1

Slide 1 text

Tests API Agora Tech Talk #5 Aug / 30 / 2016 @yyoshiki41 Yoshiki Nakagawa

Slide 2

Slide 2 text

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!

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

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 }

Slide 5

Slide 5 text

Create Health Check API Endpoints! Check MySQL connection "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." }'); }

Slide 6

Slide 6 text

Caution Do not open to the public ! Access control by ip address or authentication. nginx Advent Calendar 2015 Day21 nginx APIΤϯυϙΠϯτຖͷΞΫηε੍ޚ

Slide 7

Slide 7 text

Tests API Unit test $ go test -run TestHogehoge How do we test API endpoints??

Slide 8

Slide 8 text

Runscope

Slide 9

Slide 9 text

Runscope • Monitor API perfomance • CI

Slide 10

Slide 10 text

Monitor API performance Set schedules for this test Demo

Slide 11

Slide 11 text

Ghost Inspector

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Demo

Slide 14

Slide 14 text

Automate everything Commit => Unit Test => Deploy => API Tests => !