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

checks: populate interval and timeout when registering services #11138

Merged
merged 9 commits into from Feb 18, 2022

Conversation

eculver
Copy link
Contributor

@eculver eculver commented Sep 24, 2021

In #10707, we added Interval and Timeout to the response for health checks. This uncovered a few bugs whereby we weren't properly setting these values when services get registered and their checks created through other code paths. In particular, there are no fewer than 6 places where checks can get registered for a service. This addresses the path taken via the /v1/agent/service/register endpoint and the consul services register command.

Here's how I tested:

# start the agent
consul agent -dev

# register a service
curl -X PUT localhost:8500/v1/agent/service/register -H 'Content-type: application/json' -d '{
  "ID": "test-service-1",
  "Name": "test-service-1",
  "Meta": {
    "source": "consul-ecs",
    "task-arn": "arn:aws:ecs:us-east-1:123456789:task/test/1",
    "task-id": "1"
  },
  "Check": null,
  "Checks": [
    {
      "CheckID": "api-http",
      "Name": "HTTP on port 8080",
      "Interval": "5m",
      "Timeout": "10s",
      "HTTP": "http://localhost:8080",
      "Header": {
        "Content-type": [
          "application/json"
        ]
      },
      "Method": "GET",
      "Notes": "unittest http check"
    }
  ]
}'

Then validate that the Interval and Timeout fields get populated:

curl localhost:8500/v1/agent/checks
{
    "api-http": {
        "Node": "eculver-C02FQ1ENML85",
        "CheckID": "api-http",
        "Name": "HTTP on port 8080",
        "Status": "critical",
        "Notes": "unittest http check",
        "Output": "",
        "ServiceID": "test-service-1",
        "ServiceName": "test-service-1",
        "ServiceTags": [],
        "Type": "http",
        "Interval": "5m0s",
        "Timeout": "5m0s",
        "ExposedPort": 0,
        "Definition": {},
        "CreateIndex": 0,
        "ModifyIndex": 0
    }
}

I also tested via the CLI by writing a services.json:

{
  "Service": {
    "ID": "test-service-2",
    "Name": "test-service-2",
    "Meta": {
      "source": "consul-ecs",
      "task-arn": "arn:aws:ecs:us-east-1:123456789:task/test/2",
      "task-id": "2"
    },
    "Check": null,
    "Checks": [
      {
        "Name": "HTTP on port 8080",
        "Interval": "2m",
        "Timeout": "3s",
        "HTTP": "http://localhost:8080",
        "Header": {
          "Content-type": [
            "application/json"
          ]
        },
        "Method": "GET",
        "Notes": "unittest http check"
      }
    ]
  }
}

And registering via the CLI:

consul services register services.json

Then reading the output again via the API:

curl localhost:8500/v1/health/checks/test-service-2
[
    {
        "Node": "eculver-C02FQ1ENML85",
        "CheckID": "service:test-service-2",
        "Name": "HTTP on port 8080",
        "Status": "critical",
        "Notes": "unittest http check",
        "Output": "",
        "ServiceID": "test-service-2",
        "ServiceName": "test-service-2",
        "ServiceTags": [],
        "Type": "http",
        "Interval": "2m0s",
        "Timeout": "2m0s",
        "ExposedPort": 0,
        "Definition": {},
        "CreateIndex": 27,
        "ModifyIndex": 27
    }
]

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging September 24, 2021 01:59 Inactive
@vercel vercel bot temporarily deployed to Preview – consul September 24, 2021 01:59 Inactive
@eculver
Copy link
Contributor Author

eculver commented Sep 24, 2021

/cc @ishustava @lkysow @pglass - I think this should fix the issue based on the earlier thread.

@vercel vercel bot temporarily deployed to Preview – consul September 24, 2021 02:01 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging September 24, 2021 02:01 Inactive
@vercel vercel bot temporarily deployed to Preview – consul September 24, 2021 02:02 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging September 24, 2021 02:02 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging September 24, 2021 02:06 Inactive
@vercel vercel bot temporarily deployed to Preview – consul September 24, 2021 02:06 Inactive
Copy link

@pglass pglass left a comment

Choose a reason for hiding this comment

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

This looks good to me @eculver (Sorry for the months-late review!)

@github-actions
Copy link

This pull request has been automatically flagged for inactivity because it has not been acted upon in the last 60 days. It will be closed if no new activity occurs in the next 30 days. Please feel free to re-open to resurrect the change if you feel this has happened by mistake. Thank you for your contributions.

@github-actions github-actions bot added the meta/stale Automatically flagged for inactivity by stalebot label Feb 18, 2022
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 18, 2022 18:34 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 18, 2022 18:34 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 18, 2022 18:50 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 18, 2022 18:50 Inactive
@eculver eculver merged commit 602e08a into main Feb 18, 2022
@eculver eculver deleted the eculver/check-fields branch February 18, 2022 20:05
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/590068.

@hc-github-team-consul-core
Copy link
Collaborator

🍒✅ Cherry pick of commit 602e08a onto release/1.11.x succeeded!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta/stale Automatically flagged for inactivity by stalebot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants