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

[Enhancement] Consul ESM to support Admin Partitions #281

Merged
merged 10 commits into from
Sep 20, 2024

Conversation

srahul3
Copy link
Contributor

@srahul3 srahul3 commented Sep 13, 2024

Background

Many customers are looking forward for ESM to support Admin partition.

Changes proposed

There is need for additional configuration in order to support Admin partition.

partition = "<admin partition name>"

Note: ESM configured with a particular partition needs to connect to its respective Consul Client Agent with same partition configured.

@srahul3 srahul3 marked this pull request as draft September 13, 2024 04:32
@srahul3 srahul3 self-assigned this Sep 13, 2024
@Esity
Copy link

Esity commented Sep 15, 2024

Just tested this against

  • default partition and specific non default partitions
  • RHEL and Ubuntu
  • In our VMWare environment and Azure

With 100% success
@blake When can we get this magic PR merged?

@srahul3 srahul3 marked this pull request as ready for review September 16, 2024 07:40
@srahul3
Copy link
Contributor Author

srahul3 commented Sep 16, 2024

@Esity Thanks for testing the draft, I have made few cleanups after you have tested it. These cleanups were required to make the test passing. Do you mind testing this version as-well?

@srahul3 srahul3 marked this pull request as draft September 16, 2024 07:52
@srahul3 srahul3 marked this pull request as ready for review September 16, 2024 16:32
Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Thanks so much for making these changes! This is looking great, just a couple of comments on whether we got all the cases and some tests we could add.

For each .go file that changed, would it make sense to add a test with non-default partitions? For example in leader.go, you added partitions to commitOps(). I think it could make sense to then update the test for that function or add a new test that just tests that function with non-default partitions in the inputs. Similarly, for example in agent.go, you added partitions to the getHealthChecks function, so you could add to the test func TestAgent_getHealthChecks some cases with non-default partitions.

The way I reviewed was I was looking for every instance of api. or client. and checked if partition was added.

.vscode/launch.json Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
agent.go Show resolved Hide resolved
agent.go Show resolved Hide resolved
config_test.go Outdated Show resolved Hide resolved
coordinate.go Show resolved Hide resolved
@srahul3
Copy link
Contributor Author

srahul3 commented Sep 17, 2024

For each .go file that changed, would it make sense to add a test with non-default partitions?

@ndhanushkodi Since this is OSS project hence, we may not be able to add API related test with partition since it is enterprise only feature.

@ndhanushkodi
Copy link
Contributor

ndhanushkodi commented Sep 18, 2024

Since this is OSS project hence, we may not be able to add API related test with partition since it is enterprise only feature.

So for a similar example, consul-k8s is also an open source repo, but for example here it tests the behavior with non-default namespaces.

It doesn't have to be a separate build but similar to how you're passing a non-default partition to this unit test here, you can also do something similar for tests for functions that you updated. I would say for the scope of this PR it would make sense to add non-default partitions to tests that already exist, such as func TestAgent_getHealthChecks. But if a function you updated doesn't already have an existing test you can add the non-default partition to, then it would be ok to skip. What do you think?

@srahul3
Copy link
Contributor Author

srahul3 commented Sep 19, 2024

@ndhanushkodi Added more admin partition tests with mock server.

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for making those changes, this looks great

@srahul3 srahul3 merged commit 7c3ef2a into main Sep 20, 2024
53 checks passed
@srahul3 srahul3 deleted the srahul3/esm-admin-partition-poc branch September 20, 2024 03:18
}

// HasPartition checks if the partition is valid and calls the callback with the partition if it has any.
func (a *Agent) HasPartition(callback func(partition string)) {
Copy link
Member

Choose a reason for hiding this comment

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

this reads a little strange to me, is this checking if a partition is valid then it should be returning a bool to indicate if it's valid (and should probably be named ValidPartition) though this isn't checking if the partition is valid, it's just checking if the partition on the agent is non-emtpy and non-default, I'd probably get rid of this function entirely and re-write where it's used to just assign the output of PartitionOrEmtpy

agent.go Show resolved Hide resolved
agent.go Show resolved Hide resolved
cases := []struct {
name, partition, expected string
}{
{"No partition", "", ""},
Copy link
Member

Choose a reason for hiding this comment

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

can we use the struct keys here so it's a bit clearer what each value means?

Comment on lines +523 to 534
if tc.partition == "" {
agent = testAgent(t, func(c *Config) {
c.HTTPAddr = ts.URL
c.InstanceID = "test-agent"
})
} else {
agent = testAgent(t, func(c *Config) {
c.HTTPAddr = ts.URL
c.InstanceID = "test-agent"
c.Partition = tc.partition
})
}
Copy link
Member

Choose a reason for hiding this comment

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

so the zero value for a string here is "" so we can just always assign the partition value because in the first case tc.partition == "" the Partition field on the config struct will just be "" so we don't need the conditional check here

Suggested change
if tc.partition == "" {
agent = testAgent(t, func(c *Config) {
c.HTTPAddr = ts.URL
c.InstanceID = "test-agent"
})
} else {
agent = testAgent(t, func(c *Config) {
c.HTTPAddr = ts.URL
c.InstanceID = "test-agent"
c.Partition = tc.partition
})
}
agent = testAgent(t, func(c *Config) {
c.HTTPAddr = ts.URL
c.InstanceID = "test-agent"
c.Partition = tc.partition
})

case strings.Contains(uri, "health/service"):
assert.Equal(t, tc.partition, r.URL.Query().Get(partitionQueryParamKey))
fmt.Fprint(w, healthserviceJSON)
}
Copy link
Member

Choose a reason for hiding this comment

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

minor, but could we add a default case here that errors if an unexpected endpoint is called so we can be sure that we're catching all the cases?

@srahul3
Copy link
Contributor Author

srahul3 commented Sep 24, 2024

@jm96441n Even the empty partition fails with OSS/CE version of consul.

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

Successfully merging this pull request may close these issues.

4 participants