Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export the StatusRep and related struct and make them consumable by third-party applications #146

Open
asaha123 opened this issue Jun 17, 2021 · 2 comments

Comments

@asaha123
Copy link

Is your feature request related to a problem? Please describe.

Currently LaunchDarkly Relay exports a /status endpoint which returns a JSON body as follows:

{
  "environments": {
    "environment1": {
      "sdkKey": "sdk-********-****-****-****-*******99999",
      "envId": "999999999999999999999999",
      "mobileKey": "mob-********-****-****-****-*******99999",
      "status": "connected",
      "connectionStatus": {
        "state": "VALID",
        "stateSince": 10000000
      },
      "dataStoreStatus": {
        "state": "VALID",
        "stateSince": 10000000,
        "database": "redis",
        "dbServer": "redis://my-redis-host",
        "dbPrefix": "env1"
      }
    },    
  },
  "status": "healthy",
  "version": "5.11.1",
  "clientVersion": "4.17.2"
}

The HTTP response status code is always 200 irrespective of the the overall health status. Hence, this means that applications who wish to include ld-relay’s status in their healthcheck or deploy it as a service will need to reimplement the custom logic themselves to report a non-200 response if one of the following scenarios occur:

  • If an environment status is not connected, or is currently disconnected for more than X seconds, etc.
  • If a datastore is being used, report a health status that the user may want to customize based on whether the previous condition is true or not.

One solution I am thinking that users can do is package the ld-relay (as explained here) and implement a /healthcheck (or similarly named) endpoint which returns a non-200 status as per the logic described above.

However, currently the structs for parsing the status response is an internal package and hence we cannot Unmarshal the data without copying the struct types.

Describe the solution you'd like

Export the status related type definitions to be usable by third party applications.

@eli-darkly
Copy link
Contributor

This would of course only be useful to applications that are written in Go, but I don't see any reason we couldn't do it. We do already export other code (the top-level Relay component and the configuration structs) so that the Relay Proxy services can be hosted inside other code, so this is not that different.

However, I disagree that "we cannot unmarshal the data without copying the struct types". Go can unmarshal arbitrary JSON into a map[string]interface{} type; there is also the LaunchDarkly SDK JSON type ldvalue.Value for a more type-safe approach. I agree that that's not as convenient as a struct type, but I thought it was worth mentioning, since one of the main reasons to use JSON for status information like this is that applications don't need any special schema to decode and traverse it.

LaunchDarklyCI pushed a commit that referenced this issue Jun 17, 2021
(v6 - #14) move some things into core subpackages, expose fewer impl details
@asaha123
Copy link
Author

However, I disagree that "we cannot unmarshal the data without copying the struct types". Go can unmarshal arbitrary JSON into a map[string]interface{} type; there is also the LaunchDarkly SDK JSON type ldvalue.Value for a more type-safe approach. I agree that that's not as convenient as a struct type, but I thought it was worth mentioning, since one of the main reasons to use JSON for status information like this is that applications don't need any special schema to decode and traverse it.

Yes you are right, of course there are other ways.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants