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

feat(naming): adds a ShardingNamingConvention that can inspect the detail component of a Name #28

Merged
merged 5 commits into from
Feb 29, 2020

Conversation

cfieber
Copy link
Contributor

@cfieber cfieber commented Feb 27, 2020

A NamingConvention describes a way of extracting extra attributes from a name without
requiring that all consumers adopt that convention.

@cfieber
Copy link
Contributor Author

cfieber commented Feb 28, 2020

@haleyw @vigneshm FYI

"foo" || "foo" || null || []
"x1foo-bar-baz" || "-bar-baz" || [1: s(1, "foo")] || []
"x1foo-x2bar-x1baz-bazinga" || "-bazinga" || [1: s(1, "baz"), 2: s(2, "bar")] || [dupe(1, "foo", "baz")]
"x2bar-x1foo-blah-x3baz" || "-blah-x3baz" || [1: s(1, "foo"), 2: s(2, "bar")] || [remains("-blah-x3baz", 3, "baz")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we could precisely reproduce the overall resource name if we know the component parts. The support for arbitrary ordering and de-duping means that it isn't possible to do that reliably.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as we discussed on chat - I think the fact that a NamingConvention is used to inspects a name after it has been processed into an app/stack/detail may put us in a stronger spot that we previously were (we always only use those three components (and push sequence for a deploy) to compose the final name)

@brharrington
Copy link
Contributor

How is the NamingConvention expected to get used with Names? Would Names be used to extract the detail and then the user would use the naming convention class directly?

What do you think about moving the old labelled vars stuff into a naming convention? The main change to the current behavior is that now these labelled vars would be considered as part of the detail string. This came up recently because we found an example in use where Frigga can generate names using AutoScalingGroupNameBuilder that it cannot parse back out reliably. Example:

    def 'should be able to parse generated name'() {
        when:
        AutoScalingGroupNameBuilder cluster = new AutoScalingGroupNameBuilder()
        cluster.withAppName("app")
            .withStack("stack")
            .withDetail("c0usa")
        Names name = Names.parseName(cluster.buildGroupName())

        then:
        "app-stack-c0usa" == cluster.buildGroupName()
        "app" == name.app
        "stack" == name.stack
        "detail" == name.detail // fails because detail matches a labelled var
    }

The labelled var pattern does not appear to be in use at Netflix. We could make it a naming convention and have it only get applied and used in Names if one of the labelled var accessors is called. Thoughts?

@cfieber
Copy link
Contributor Author

cfieber commented Feb 28, 2020

yeah I do like the idea of extracting all the existing labelledVars into a NamingConvention (or potentially just deleting them all..)

@brharrington
Copy link
Contributor

Deleting them all is fine with me, but I haven't done any due diligence to see if it would break something.

prevent capturing anything that is -[alpha]0 as a labeled variable and explicitly scopes to the
already implemented variables
…etail string

An optional naming convention that can be applied against a
freeFormDetails string so as not to inflict the opinion on all frigga users
…ention

Breaking

Accessor methods still exist on Names and calling one will parse labeled variables out of the cluster name, preserving
the existing values as they would be returned.

Labeled variables are not dropped prior to considering the app/stack/detail components of a name, so where previously a
cluster called foo-c0banana would have a stack of null and a country of banana, now will have a stack of c0banana and
a country of banana.
sequence = Integer.parseInt(sequenceString);
} catch (NumberFormatException e) {
// This is fine.
protected Names(String name) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reworked the constructor here to make the fields final

} else if (!zone.equals(other.zone))
return false;
return true;
public boolean equals(Object o) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can safely just consider group for equals and hashCode, since that is the original value passed in the constructor, everything else is determined off that value at construction, and group is only non-null if the supplied name was legitimately parseable

@@ -341,7 +341,7 @@ class NamesSpec extends Specification {
'cass-nccpintegration-random-junk-c0northamerica-d0prod-h0gamesystems-p0vizio-r027-u0nccp-w0A-z0useast1a' == names.cluster
'cass' == names.app
'nccpintegration' == names.stack
'random-junk' == names.detail
'random-junk-c0northamerica-d0prod-h0gamesystems-p0vizio-r027-u0nccp-w0A-z0useast1a' == names.detail
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes in this test highlight the breaking change behavior from refactoring out the labeled variables into a NamingConvention

Copy link
Contributor

@brharrington brharrington left a comment

Choose a reason for hiding this comment

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

The labelled variable changes LGTM.

@cfieber cfieber merged commit 128a499 into Netflix:master Feb 29, 2020
@cfieber cfieber deleted the sharding_support branch February 29, 2020 00:11
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.

2 participants