-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: integration test eureka with armeria
Signed-off-by: Adrian Cole <[email protected]>
- Loading branch information
Adrian Cole
committed
Jan 14, 2024
1 parent
fe58f3a
commit 2c166e8
Showing
9 changed files
with
240 additions
and
35 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2016-2024 The OpenZipkin Authors | ||
* | ||
* 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 brave.example; | ||
|
||
import com.linecorp.armeria.client.WebClient; | ||
import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
import com.linecorp.armeria.common.HttpData; | ||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
import com.linecorp.armeria.common.MediaType; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import zipkin2.reporter.BytesMessageEncoder; | ||
import zipkin2.reporter.BytesMessageSender; | ||
import zipkin2.reporter.ClosedSenderException; | ||
import zipkin2.reporter.Encoding; | ||
|
||
final class WebClientSender extends BytesMessageSender.Base { | ||
final WebClient client; | ||
final BytesMessageEncoder encoder = BytesMessageEncoder.JSON; | ||
final MediaType mediaType = MediaType.JSON; | ||
|
||
WebClientSender(WebClient client) { | ||
super(Encoding.JSON); | ||
this.client = client; | ||
} | ||
|
||
@Override public int messageMaxBytes() { | ||
return 500000; | ||
} | ||
|
||
/** close is typically called from a different thread */ | ||
volatile boolean closeCalled; | ||
|
||
/** Sends spans as a POST to the configured endpoint. */ | ||
@Override public void send(List<byte[]> encodedSpans) throws IOException { | ||
if (closeCalled) throw new ClosedSenderException(); | ||
byte[] body = encoder.encode(encodedSpans); | ||
HttpRequest request = | ||
HttpRequest.of(HttpMethod.POST, "", mediaType, HttpData.wrap(body)); | ||
AggregatedHttpResponse response = client.blocking().execute(request); | ||
try (HttpData content = response.content()) { | ||
if (!response.status().isSuccess()) { | ||
if (content.isEmpty()) { | ||
throw new IOException("response failed: " + response); | ||
} | ||
throw new IOException("response for failed: " + content.toStringAscii()); | ||
} | ||
} | ||
} | ||
|
||
/** Waits up to a second for in-flight requests to finish before cancelling them */ | ||
@Override public synchronized void close() { | ||
if (closeCalled) return; | ||
closeCalled = true; | ||
// webclient cannot be closed | ||
} | ||
|
||
@Override public String toString() { | ||
return "WebClientSender{" + client + "}"; | ||
} | ||
} |
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,59 @@ | ||
# | ||
# Copyright 2015-2024 The OpenZipkin Authors | ||
# | ||
# 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. | ||
# | ||
|
||
# This file uses the version 2 docker-compose file format, described here: | ||
# https://docs.docker.com/compose/compose-file/#version-2 | ||
# | ||
# It extends the default configuration from docker-compose.yml to register | ||
# zipkin into a test eureka server. | ||
|
||
version: '2.4' | ||
|
||
services: | ||
eureka: | ||
image: ghcr.io/openzipkin/zipkin-eureka | ||
container_name: eureka | ||
# Uncomment to expose the eureka port for testing | ||
# ports: | ||
# - 8761:8761 | ||
|
||
zipkin: | ||
extends: | ||
file: docker-compose.yml | ||
service: zipkin | ||
environment: | ||
- EUREKA_SERVICE_URL=http://eureka:8761/eureka/v2 | ||
depends_on: | ||
eureka: | ||
condition: service_healthy | ||
|
||
frontend: | ||
extends: | ||
file: docker-compose.yml | ||
service: frontend | ||
environment: | ||
- EUREKA_SERVICE_URL=http://eureka:8761/eureka/v2 | ||
depends_on: | ||
eureka: | ||
condition: service_healthy | ||
|
||
backend: | ||
extends: | ||
file: docker-compose.yml | ||
service: backend | ||
environment: | ||
- EUREKA_SERVICE_URL=http://eureka:8761/eureka/v2 | ||
depends_on: | ||
eureka: | ||
condition: service_healthy |
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