-
Notifications
You must be signed in to change notification settings - Fork 16
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
Support behaviour changes based on URIs with a 'mesh-' prefix #1048
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5eaee66
prefixing uris with 'mesh-' auto-disables retries
iamdanfox e91ca42
include debug logging
iamdanfox f2f6db0
Move to dedicated class
iamdanfox 35c9dfb
Mention (mesh) in tracing spans
iamdanfox f0dfd92
update test
iamdanfox 0f5023c
improve readability
iamdanfox 75c380e
Also turn off all concurrency limiting in mesh-land
iamdanfox 96065cd
Add generated changelog entries
iamdanfox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
dialogue-core/src/main/java/com/palantir/dialogue/core/MeshMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.dialogue.core; | ||
|
||
import com.palantir.logsafe.Preconditions; | ||
import com.palantir.logsafe.SafeArg; | ||
import java.util.List; | ||
|
||
enum MeshMode { | ||
DEFAULT_NO_MESH, | ||
USE_EXTERNAL_MESH; | ||
|
||
/** | ||
* This prefix may reconfigure several aspects of the client to work better in a world where requests are routed | ||
* through a service mesh like istio/envoy. | ||
*/ | ||
private static final String MESH_PREFIX = "mesh-"; | ||
|
||
static MeshMode fromUris(List<String> uris, SafeArg<String> channelName) { | ||
long meshUris = uris.stream().filter(s -> s.startsWith(MESH_PREFIX)).count(); | ||
long normalUris = uris.stream().filter(s -> !s.startsWith(MESH_PREFIX)).count(); | ||
|
||
if (meshUris == 0) { | ||
return MeshMode.DEFAULT_NO_MESH; | ||
} else { | ||
Preconditions.checkState( | ||
meshUris == 1, | ||
"Not expecting multiple 'mesh-' prefixed uris - please double-check the uris", | ||
SafeArg.of("meshUris", meshUris), | ||
SafeArg.of("normalUris", normalUris), | ||
channelName); | ||
Preconditions.checkState( | ||
normalUris == 0, | ||
"When a 'mesh-' prefixed uri is present, there should not be any normal uris - please double " | ||
+ "check the uris", | ||
SafeArg.of("meshUris", meshUris), | ||
SafeArg.of("normalUris", normalUris), | ||
channelName); | ||
|
||
return MeshMode.USE_EXTERNAL_MESH; | ||
} | ||
} | ||
|
||
public static String stripMeshPrefix(String input) { | ||
return input.startsWith(MESH_PREFIX) ? input.substring(MESH_PREFIX.length()) : input; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
dialogue-core/src/test/java/com/palantir/dialogue/core/MeshModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.dialogue.core; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import com.palantir.logsafe.SafeArg; | ||
import com.palantir.logsafe.exceptions.SafeIllegalStateException; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MeshModeTest { | ||
|
||
@Test | ||
void normal_uris_are_not_mesh() { | ||
MeshMode mode = fromUris("https://server.whatever", "http://server.another"); | ||
assertThat(mode).isEqualTo(MeshMode.DEFAULT_NO_MESH); | ||
} | ||
|
||
@Test | ||
void single_prefix_triggers_mesh_mode() { | ||
MeshMode mode = fromUris("mesh-https://server.whatever"); | ||
assertThat(mode).isEqualTo(MeshMode.USE_EXTERNAL_MESH); | ||
} | ||
|
||
@Test | ||
void empty_uris_doesnt_break() { | ||
MeshMode mode = fromUris(); | ||
assertThat(mode).isEqualTo(MeshMode.DEFAULT_NO_MESH); | ||
} | ||
|
||
@Test | ||
void mixed_uris_breaks() { | ||
assertThatThrownBy(() -> fromUris("https://server.whatever", "mesh-http://server.another")) | ||
.isInstanceOf(SafeIllegalStateException.class) | ||
.hasMessage( | ||
"When a 'mesh-' prefixed uri is present, there should not be any normal uris - please double " | ||
+ "check the uris: " | ||
+ "{meshUris=1, normalUris=1, channelName=channelName}"); | ||
} | ||
|
||
@Test | ||
void multiple_prefixes_breaks() { | ||
assertThatThrownBy(() -> fromUris("mesh-https://server.whatever", "mesh-http://server.another")) | ||
.isInstanceOf(SafeIllegalStateException.class) | ||
.hasMessage("Not expecting multiple 'mesh-' prefixed uris - please double-check the uris: " | ||
+ "{meshUris=2, normalUris=0, channelName=channelName}"); | ||
} | ||
|
||
private MeshMode fromUris(String... uris) { | ||
return MeshMode.fromUris( | ||
Arrays.stream(uris).collect(Collectors.toList()), SafeArg.of("channelName", "channelName")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep all of the meshmode stuff internal to DialogueChannel? i.e. perform the computation internally instead of having a derived field on the config object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we could, but then there's a possibility of constructing a Config object which is in a non-sensical state - i.e. has
mesh-
prefixed uris, but doesn't haveMeshMode.USE_EXTERNAL_MESH
set. The reason I think it's appropriate & desirable here is to emphasise to people that this isn't an extra degree of freedom in how you build a Config object, instead it's just purely derived from the URIs that you already put in. This is an example of the "make illegal states unrepresentable" pattern.Otherwise, to keep this safety, we'd just have to put in a Value.Check that computes the mesh mode.
Third option is to not even have the mesh() param on this object, which would then require plumbing it in everywhere that we currently pass
Config cf
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least within the scope of this PR it seems like there are only 2 places that actually care about the mesh mode stuff, and in both cases they didn't previous require the entire
Config
object to be initialized. So it doesn't seem like we're saving much by pushing the mesh-mode stuff into the config object and it just exposes additional API on theConfig
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config is package private, so the only people who will be affected by this decision will be us / future maintainers of dialogue.
Back in april I found dialogue channel had grown to become really hard to read, so condensed all of the 'inputs' into this one Config object. That enables the pattern where Channels are created with this convention:
In each of these cases,
Config cf
is only plumbed to the static factory method, so the actual Channel's constructor has only the bits it really needs (e.g. a clock or a channelname string etc), which makes it convenient to supply only exactly what you need for unit-testing.It might seem minor, but i do feel kinda strongly about this... I think this convention helps us minimize plumbing, keeping the top level DialogueChannel as concise as possible so that you can follow which channels are wired into which other channels without getting distracted.