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

[NET-7571] Ensure services function uses specified Consul namespace #1874

Merged
merged 6 commits into from
Feb 7, 2024

Conversation

kkavish
Copy link
Contributor

@kkavish kkavish commented Feb 6, 2024

  • bug fix: Services function in CT (consul-template) does not update the namespace for each services API call
  • opts should be defaulted to the opts at query creation.
  • then they should be merged with the opts present in Fetch.
  • currently the merge was the other way around.
  • ENT test support is not there, so no test cases added as of now.

How I've tested this PR

How I expect reviewers to test this PR

Checklist

  • Tests added
  • CHANGELOG entry added

- bug fix for SeatGeek: Services function in CT (consul-template) does not update the namespace for each services API call
- opts should be defaulted to the opts at query creation.
- then they should be merged with the opts present in Fetch.
- currently the merge was the other way around.
- ENT test support is not there, so no test cases added as of now.
@kkavish kkavish requested a review from a team as a code owner February 6, 2024 08:46
- bug fix for SeatGeek: Services function in CT (consul-template) does not update the namespace for each services API call
- opts should be defaulted to the opts at query creation.
- then they should be merged with the opts present in Fetch.
- currently the merge was the other way around.
- ENT test support is not there, so no test cases added as of now.
@kkavish kkavish added consul-india Consul India team gets notified about the PRs and removed consul-india Consul India team gets notified about the PRs labels Feb 6, 2024
Copy link
Collaborator

@tauhid621 tauhid621 left a comment

Choose a reason for hiding this comment

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

Looks good. I see that other functions are using the opts.Merge(&QueryOptions{ way. Would we need to update some of them as well?

Comment on lines 78 to 81
// see bug [https://github.com/hashicorp/consul-template/pull/1842#issuecomment-1915723565]
// it should be other way around.
// default to the query params present while creating NewCatalogServicesQuery
// and then merge with the query params present in the query
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have this comment here as the updated code will not have reference of what was used earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, some of the other functions have that problem too.
that's why I want to enable ENT and write proper tests for them before touching them.

- bug fix for SeatGeek: Services function in CT (consul-template) does not update the namespace for each services API call
- opts should be defaulted to the opts at query creation.
- then they should be merged with the opts present in Fetch.
- currently the merge was the other way around.
- ENT test support is not there, so no test cases added as of now.
- bug fix for SeatGeek: Services function in CT (consul-template) does not update the namespace for each services API call
- opts should be defaulted to the opts at query creation.
- then they should be merged with the opts present in Fetch.
- currently the merge was the other way around.
- ENT test support is not there, so no test cases added as of now.
- bug fix for SeatGeek: Services function in CT (consul-template) does not update the namespace for each services API call
- opts should be defaulted to the opts at query creation.
- then they should be merged with the opts present in Fetch.
- currently the merge was the other way around.
- ENT test support is not there, so no test cases added as of now.
- updating comments
@kkavish kkavish merged commit 5fbf750 into main Feb 7, 2024
54 checks passed
@kkavish kkavish deleted the NET-7571 branch February 7, 2024 13:27
@jkirschner-hashicorp jkirschner-hashicorp changed the title [NET-7571]SeatGeek [NET-7571] Ensure services function uses specified Consul namespace Feb 7, 2024
@komapa
Copy link

komapa commented Feb 13, 2024

Unfortunately this is also not complete implementation. I tested it locally and you need to change:

// String returns the human-friendly version of this dependency.
func (d *CatalogServicesQuery) String() string {
	if d.dc != "" {
		return fmt.Sprintf("catalog.services(@%s)", d.dc)
	}
	return "catalog.services"
}

to

// String returns the human-friendly version of this dependency.
func (d *CatalogServicesQuery) String() string {
	opts := &QueryOptions{
		Datacenter:      d.dc,
		ConsulPartition: d.partition,
		ConsulNamespace: d.namespace,
	}

	if opts.String() != "" {
		return fmt.Sprintf("catalog.services(@%s)", opts.String())
	}

	return "catalog.services"
}

This way you are actually watching different catalog.services for every dc, partition and namespace combination.

@kkavish
Copy link
Contributor Author

kkavish commented Feb 13, 2024

Unfortunately this is also not complete implementation. I tested it locally and you need to change:

// String returns the human-friendly version of this dependency.
func (d *CatalogServicesQuery) String() string {
	if d.dc != "" {
		return fmt.Sprintf("catalog.services(@%s)", d.dc)
	}
	return "catalog.services"
}

to

// String returns the human-friendly version of this dependency.
func (d *CatalogServicesQuery) String() string {
	opts := &QueryOptions{
		Datacenter:      d.dc,
		ConsulPartition: d.partition,
		ConsulNamespace: d.namespace,
	}

	if opts.String() != "" {
		return fmt.Sprintf("catalog.services(@%s)", opts.String())
	}

	return "catalog.services"
}

This way you are actually watching different catalog.services for every dc, partition and namespace combination.

@komapa thanks for pointing that out. please see - #1880

@@ -71,11 +71,17 @@ func (d *CatalogServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (in
default:
}

opts = opts.Merge(&QueryOptions{
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this was the problem, I think it was the String() function not being unique for different ns/partition queries. I think this function is only ever called here: https://github.com/hashicorp/consul-template/blob/main/watch/view.go#L218-L222 and so there's no issue with the merge order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consul-india Consul India team gets notified about the PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants