-
Notifications
You must be signed in to change notification settings - Fork 33
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 for generate_request_id and preserve_external_request_id listener config #233
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2dd71c2
generate_request_id and preserve_external_request_id config added
piorkowskiprzemyslaw fdec37d
new flags added to test configs
piorkowskiprzemyslaw 60f8c83
tests added
piorkowskiprzemyslaw 1e65a6c
fix ktlint issues
piorkowskiprzemyslaw a2c0362
Merge branch 'master' into requestIdConfig
slonka 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
119 changes: 119 additions & 0 deletions
119
...y-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/RequestIdTest.kt
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,119 @@ | ||
package pl.allegro.tech.servicemesh.envoycontrol | ||
|
||
import okhttp3.Headers | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.MethodSource | ||
import pl.allegro.tech.servicemesh.envoycontrol.assertions.isOk | ||
import pl.allegro.tech.servicemesh.envoycontrol.assertions.untilAsserted | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.envoycontrol.EnvoyControlExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.service.GenericServiceExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.service.HttpsEchoContainer | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.service.asHttpsEchoResponse | ||
|
||
class RequestIdTest { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun extraHeadersSource() = listOf( | ||
emptyMap(), | ||
mapOf("x-forwarded-for" to "123.321.231.111"), | ||
mapOf("x-forwarded-for" to "111.111.222.222,123.123.231.231") | ||
) | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val consul = ConsulExtension() | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val envoyControl = EnvoyControlExtension(consul) | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val localService = GenericServiceExtension(HttpsEchoContainer()) | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val envoy = EnvoyExtension(envoyControl, localService) | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val externalService = GenericServiceExtension(HttpsEchoContainer()) | ||
} | ||
|
||
@BeforeEach | ||
fun setup() { | ||
consul.server.operations.registerService(externalService, name = "service-1") | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("extraHeadersSource") | ||
fun `should propagate x-request-id on the egress port when it is available in request`(extraHeaders: Map<String, String>) { | ||
// given | ||
val requestIdHeader = mapOf("x-request-id" to "egress-fake-request-id") | ||
|
||
untilAsserted { | ||
// when | ||
val response = envoy.egressOperations | ||
.callService(service = "service-1", headers = requestIdHeader + extraHeaders) | ||
.asHttpsEchoResponse() | ||
|
||
// then | ||
assertThat(response).isOk() | ||
assertThat(response.requestHeaders).containsEntry("x-request-id", "egress-fake-request-id") | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("extraHeadersSource") | ||
fun `should generate x-request-id on the egress port when it is missing in request`(extraHeaders: Map<String, String>) { | ||
untilAsserted { | ||
// when | ||
val response = envoy.egressOperations | ||
.callService(service = "service-1", headers = extraHeaders) | ||
.asHttpsEchoResponse() | ||
|
||
// then | ||
assertThat(response).isOk() | ||
assertThat(response.requestHeaders).hasEntrySatisfying("x-request-id") { assertThat(it).isNotBlank() } | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("extraHeadersSource") | ||
fun `should propagate x-request-id on the ingress port when it is available in request`(extraHeaders: Map<String, String>) { | ||
// given | ||
val requestIdHeader = mapOf("x-request-id" to "ingress-fake-request-id") | ||
|
||
untilAsserted { | ||
// when | ||
val response = envoy.ingressOperations | ||
.callLocalService(endpoint = "/", headers = Headers.of(requestIdHeader + extraHeaders)) | ||
.asHttpsEchoResponse() | ||
|
||
// then | ||
assertThat(response).isOk() | ||
assertThat(response.requestHeaders).containsEntry("x-request-id", "ingress-fake-request-id") | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("extraHeadersSource") | ||
fun `should generate x-request-id on the ingress port when it is missing in request`(extraHeaders: Map<String, String>) { | ||
untilAsserted { | ||
// when | ||
val response = envoy.ingressOperations | ||
.callLocalService(endpoint = "/", headers = Headers.of(extraHeaders)) | ||
.asHttpsEchoResponse() | ||
|
||
// then | ||
assertThat(response).isOk() | ||
assertThat(response.requestHeaders).hasEntrySatisfying("x-request-id") { assertThat(it).isNotBlank() } | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...kotlin/pl/allegro/tech/servicemesh/envoycontrol/assertions/HttpsEchoResponseAssertions.kt
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,20 @@ | ||
package pl.allegro.tech.servicemesh.envoycontrol.assertions | ||
|
||
import org.assertj.core.api.Assertions | ||
import org.assertj.core.api.ObjectAssert | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.service.HttpsEchoContainer | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.service.HttpsEchoResponse | ||
|
||
fun ObjectAssert<HttpsEchoResponse>.isOk(): ObjectAssert<HttpsEchoResponse> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have this for the |
||
matches { it.response.isSuccessful } | ||
return this | ||
} | ||
|
||
fun ObjectAssert<HttpsEchoResponse>.hasSNI(serverName: String): ObjectAssert<HttpsEchoResponse> = satisfies { | ||
val actualServerName = HttpsEchoResponse.objectMapper.readTree(it.body).at("/connection/servername").textValue() | ||
Assertions.assertThat(actualServerName).isEqualTo(serverName) | ||
} | ||
|
||
fun ObjectAssert<HttpsEchoResponse>.isFrom(container: HttpsEchoContainer) = satisfies { | ||
Assertions.assertThat(container.containerName()).isEqualTo(it.hostname) | ||
} |
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
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
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
Oops, something went wrong.
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.
I think we should decide on a "standard method" for this type of tests. I think that everything except reliability tests should use
waitForReadyServices
. WDYT?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.
I agree. However, I'd change it in a separate PR. I want to merge it ASAP and I don't want to make changes to someone else's PR.
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.
#240