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

Add HTTP health server (closes #115) #227

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open

Conversation

keeganwitt
Copy link
Contributor

@keeganwitt keeganwitt commented Dec 7, 2024

fixes #115

Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
@keeganwitt keeganwitt marked this pull request as ready for review December 7, 2024 22:18
@keeganwitt
Copy link
Contributor Author

I'm not sure if I did this the right way. We also might want more checks than I've implemented.

@faisal-memon faisal-memon added this to the 0.10.0 milestone Dec 9, 2024
@faisal-memon
Copy link
Collaborator

Thanks @keeganwitt for submitting this.

cmd/spiffe-helper/config/config.go Outdated Show resolved Hide resolved
cmd/spiffe-helper/main.go Outdated Show resolved Hide resolved
cmd/spiffe-helper/main.go Outdated Show resolved Hide resolved
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
…k configs

Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
pkg/health/health.go Outdated Show resolved Hide resolved
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Error: can't load config: the Go language version (go1.22) used to build golangci-lint is lower than the targeted Go version (1.23.3)

Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Makefile Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
keeganwitt and others added 4 commits December 16, 2024 16:45
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
keeganwitt and others added 4 commits January 15, 2025 13:16
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
pkg/health/health.go Outdated Show resolved Hide resolved
Co-authored-by: Faisal Memon <fymemon@yahoo.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
@keeganwitt
Copy link
Contributor Author

Do you think we should wrap the FileWriteStatus in a Health struct so that the top level JSON is an object/map that can contain future health check info?

@faisal-memon
Copy link
Collaborator

Do you think we should wrap the FileWriteStatus in a Health struct so that the top level JSON is an object/map that can contain future health check info?

Not mandatory but I think that would make the output look a little nicer.

@keeganwitt
Copy link
Contributor Author

keeganwitt commented Jan 15, 2025

Do you think we should wrap the FileWriteStatus in a Health struct so that the top level JSON is an object/map that can contain future health check info?

I guess it already is an object, just doesn't have a top level key. So currently looks like

{
    "x509_write_success": true,
    "jwt_write_successes": {
        "a.jwt": true,
        "b.jwt": false
    }
}

But we might want something like this, so then we could add future keys, like a hypothetical socket_connection_failed

{
    "write_successes": {
        "x509_write_success": true,
        "jwt_write_successes": {
            "a.jwt": true,
            "b.jwt": false
        }
    },
    "socket_connection_failed": false
}

@keeganwitt
Copy link
Contributor Author

Do you think we should wrap the FileWriteStatus in a Health struct so that the top level JSON is an object/map that can contain future health check info?

I guess it already is an object, just doesn't have a top level key. So currently looks like

{
    "x509_write_success": true,
    "jwt_write_successes": {
        "a.jwt": true,
        "b.jwt": false
    }
}

But we might want something like this, so then we could add future keys, like a hypothetical socket_connection_failed

{
    "write_successes": {
        "x509_write_success": true,
        "jwt_write_successes": {
            "a.jwt": true,
            "b.jwt": false
        }
    },
    "socket_connection_failed": false
}

Optionally, we can also wrap it at the top level:

{
    "health": {
        "write_successes": {
            "x509_write_success": true,
            "jwt_write_successes": {
                "a.jwt": true,
                "b.jwt": false
            }
        },
        "socket_connection_failed": false
    }
}

@keeganwitt
Copy link
Contributor Author

I'm wondering now if the health check should distinguish between "failed to write" and "not yet written". That distinction would be important for a readiness probe.

Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
Signed-off-by: Keegan Witt <keeganwitt@gmail.com>
@keeganwitt
Copy link
Contributor Author

keeganwitt commented Jan 18, 2025

Here's what the output results look like when it first starts

// live
{
  "status": "OK",
  "health": {
    "file_write_statuses": {
      "x509_write_status": "unwritten",
      "jwt_write_status": {
        "certs": "unwritten"
      }
    }
  }
}
// ready
{
  "status": "Service Unavailable",
  "health": {
    "file_write_statuses": {
      "x509_write_status": "unwritten",
      "jwt_write_status": {
        "certs": "unwritten"
      }
    }
  }
}

@keeganwitt
Copy link
Contributor Author

Here's what the output results look like when it first starts

// live
{
  "status": "OK",
  "health": {
    "file_write_statuses": {
      "x509_write_status": "unwritten",
      "jwt_write_status": {
        "certs": "unwritten"
      }
    }
  }
}
// ready
{
  "status": "Service Unavailable",
  "health": {
    "file_write_statuses": {
      "x509_write_status": "unwritten",
      "jwt_write_status": {
        "certs": "unwritten"
      }
    }
  }
}

Maybe the status should be "ready/not ready" and "live/not live" instead of an HTTP status. Does that read easier?

@kfox1111
Copy link
Contributor

kfox1111 commented Jan 19, 2025

Hmm....

We may be crossing purposes too much?

Most of the time the check I've seen is pretty simple. http return code and not much more.

For details, they need to be readable as metrics so they can be collected over time, graphed, and alerted on. The formatting here looks more useful to humans then for machine processing.

Not saying that is a bad thing, but maybe we're too focused on it where others skip it?

Comment on lines +38 to +39
sidecarConfig := config.NewSidecarConfig(hclConfig, log)
spiffeSidecar := sidecar.New(sidecarConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines can go into startSidecar()

Comment on lines +40 to +41
err = startSidecar(hclConfig, log, spiffeSidecar)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = startSidecar(hclConfig, log, spiffeSidecar)
if err != nil {
if err = startSidecar(hclConfig, log, spiffeSidecar); err != nil {

@faisal-memon
Copy link
Collaborator

@keeganwitt Just two minor comments and then we're good to go. @kfox1111 Valid point. Lets merge this and see how it goes. Can always change the output to be more machine friendly.

@keeganwitt
Copy link
Contributor Author

Hmm....

We may be crossing purposes too much?

Most of the time the check I've seen is pretty simple. http return code and not much more.

For details, they need to be readable as metrics so they can be collected over time, graphed, and alerted on. The formatting here looks more useful to humans then for machine processing.

Not saying that is a bad thing, but maybe we're too focused on it where others skip it?

I was actually thinking of a human looking at this endpoint. Like if one of the probes fails, you can hit it with your browser and see why. I agree this doesn't replace the need for metrics.

@kfox1111
Copy link
Contributor

I mean, the current output is not directly machine understandable as, while its in a common format, the machine has no way of understanding what keys mean what. So, as is, its only directly understandable by a human.

Someone could code something to make a monitoring system fully parse it and report on it, but that could be done also by just having proper metrics.

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

Successfully merging this pull request may close these issues.

Kubernetes Sidecar Usecase
3 participants