your_spotify icon indicating copy to clipboard operation
your_spotify copied to clipboard

feat: add health endpoint

Open tigattack opened this issue 1 year ago • 4 comments

Checks DB connection & lock status.

I'm largely unfamiliar with TS (and Mongo for that matter lol), but this change has achieved my goal and seems to function well. Hopefully it's suitable. Let me know what you think.

Responses

Connected and unlocked:

{
    "status": "ok",
    "db_health": {
        "status": "UP",
        "details": {
            "version": "6.0.19",
            "uptime": 6843,
            "writable": true
        }
    }
}

Connected and locked:

{
    "status": "warning",
    "db_health": {
        "status": "READONLY",
        "details": {
            "version": "6.0.19",
            "uptime": 7244,
            "writable": false
        },
        "message": "Database is read-only (fsyncLock enabled)"
    }
}

Disconnected:

{
    "status": "error",
    "db_health": {
        "status": "DOWN",
        "message": "Error querying database health"
    }
}

tigattack avatar Nov 25 '24 15:11 tigattack

On second thoughts, perhaps READONLY should be WARNING... Open to thoughts.

tigattack avatar Nov 25 '24 23:11 tigattack

Hello, nice idea!

I feel like this could benefit a little authentication. Can you tell me what's possible for you in your context for authentication? Maybe http basic auth could do the work

Yooooomi avatar Mar 22 '25 16:03 Yooooomi

I'm not convinced authentication should be necessary for this, but I'm by no means against it, and it wouldn't be breaking for my use case (Docker healthcheck, just runs an arbitrary command and looks at the return code to determine success/failure).

That said, it's probably not something I'd be prepared to implement personally given my current level of knowledge with both TypeScript and your_spotify...

Perhaps, as a middle-ground solution, the MongoDB version could be removed from the response? I feel this would alleviate any potential concerns with the endpoint being unauthenticated.

tigattack avatar Mar 22 '25 16:03 tigattack

@Yooooomi please let me know if you're interested in going ahead with this, or have any further thoughts. I'd love to see the feature added but will close the PR if not.

tigattack avatar Aug 10 '25 21:08 tigattack