Skip to content

Commit

Permalink
Use /_health instead of /_ping
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Dec 6, 2024
1 parent 55a4f5d commit c2dbcd6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub fn run(allocator: std.mem.Allocator, indexes: *MultiIndex, address: []const

// Monitoring API
router.get("/_metrics", handleMetrics);
router.get("/_ping", handlePing);
router.get("/:index/_ping", handlePingIndex);
router.get("/_health", handleHealth);
router.get("/:index/_health", handleIndexHealth);

// Search API
router.post("/:index/_search", handleSearch);
Expand Down Expand Up @@ -458,18 +458,18 @@ fn handleHeadIndex(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !vo
defer releaseIndex(ctx, index);
}

fn handlePingIndex(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !void {
fn handleIndexHealth(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !void {
const index = try getIndex(ctx, req, res, false) orelse return;
defer releaseIndex(ctx, index);

try handlePing(ctx, req, res);
try res.writer().writeAll("OK\n");
}

fn handlePing(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !void {
fn handleHealth(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !void {
_ = ctx;
_ = req;

try res.writer().writeAll("pong\n");
try res.writer().writeAll("OK\n");
}

fn handleMetrics(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !void {
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def wait_for_ready(self, index_name=None, timeout=10.0):
deadline = time.time() + timeout
while True:
if index_name:
url = f'http://localhost:{self.port}/{index_name}/_ping'
url = f'http://localhost:{self.port}/{index_name}/_health'
else:
url = f'http://localhost:{self.port}/_ping'
url = f'http://localhost:{self.port}/_health'
try:
with requests.get(url) as res:
res.raise_for_status()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_index_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def test_get_index(client, index_name, create_index, fmt):
req = client.get(f'/{index_name}', headers=headers(fmt))
assert req.status_code == 200, req.content
if fmt == 'json':
expected = {'version': 1, 'attributes': {'foo': 1234}}
expected = {'version': 1, 'attributes': {'foo': 1234}}
else:
expected = {'v': 1, 'a': {'foo': 1234}}
expected = {'v': 1, 'a': {'foo': 1234}}
assert decode(fmt, req.content) == expected


Expand Down
13 changes: 5 additions & 8 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
def test_ping(client):
req = client.get(f'/_ping')
def test_health(client):
req = client.get('/_health')
assert req.status_code == 200, req.content
assert 'pong' in req.text


def test_index_ping(client, index_name, create_index):
req = client.get(f'{index_name}/_ping')
def test_index_health(client, create_index, index_name):
req = client.get(f'/{index_name}/_health')
assert req.status_code == 200, req.content
assert 'pong' in req.text


def test_metrics(client):
req = client.get(f'/_metrics')
req = client.get('/_metrics')
assert req.status_code == 200, req.content
assert 'aindex_searches_total' in req.text

0 comments on commit c2dbcd6

Please sign in to comment.