use of com.google.cloud.servicedirectory.v1.Endpoint in project zipkin-gcp by openzipkin.
the class AttributesExtractorTest method testEndpointWithNullServiceName.
@Test
public void testEndpointWithNullServiceName() {
Endpoint.Builder serverEndpointBuilder = Endpoint.newBuilder().port(80);
Endpoint serverEndpoint = serverEndpointBuilder.build();
Span serverSpan = Span.newBuilder().kind(Kind.SERVER).traceId("4").name("test-span").id("5").localEndpoint(serverEndpoint).build();
AttributesExtractor extractor = new AttributesExtractor(Collections.emptyMap());
Map<String, AttributeValue> serverLabels = extractor.extract(serverSpan).getAttributeMapMap();
assertThat(serverLabels).doesNotContainKey("endpoint.serviceName");
}
use of com.google.cloud.servicedirectory.v1.Endpoint in project zipkin-gcp by openzipkin.
the class AttributesExtractorTest method testEndpointIsSetIpv4.
@Test
public void testEndpointIsSetIpv4() {
Endpoint.Builder serverEndpointBuilder = Endpoint.newBuilder().serviceName("service1").port(80);
serverEndpointBuilder.parseIp("10.0.0.1");
Endpoint serverEndpoint = serverEndpointBuilder.build();
Endpoint.Builder clientEndpointBuilder = Endpoint.newBuilder().serviceName("service2").port(80);
clientEndpointBuilder.parseIp("10.0.0.1");
Endpoint clientEndpoint = clientEndpointBuilder.build();
Span serverSpan = Span.newBuilder().kind(Kind.SERVER).traceId("4").name("test-span").id("5").localEndpoint(serverEndpoint).build();
Span clientSpan = Span.newBuilder().kind(Kind.CLIENT).traceId("4").name("test-span").id("6").parentId("5").localEndpoint(clientEndpoint).build();
AttributesExtractor extractor = new AttributesExtractor(Collections.emptyMap());
Map<String, AttributeValue> serverLabels = extractor.extract(serverSpan).getAttributeMapMap();
assertThat(serverLabels).containsEntry("endpoint.ipv4", toAttributeValue("10.0.0.1"));
assertThat(serverLabels).doesNotContainKey("endpoint.ipv6");
Map<String, AttributeValue> clientLabels = extractor.extract(clientSpan).getAttributeMapMap();
assertThat(clientLabels).doesNotContainKeys("endpoint.ipv4", "endpoint.ipv6");
}
use of com.google.cloud.servicedirectory.v1.Endpoint in project easeagent by megaease.
the class ConvertSpanReporter method convert.
static ReportSpan convert(MutableSpan span) {
ReportSpanBuilder result = ReportSpanBuilder.newBuilder().traceId(span.traceId()).parentId(span.parentId()).id(span.id()).name(span.name());
long start = span.startTimestamp();
long finish = span.finishTimestamp();
result.timestamp(start);
if (start != 0 && finish != 0L) {
result.duration(Math.max(finish - start, 1));
}
// use ordinal comparison to defend against version skew
Kind kind = span.kind();
if (kind != null) {
result.kind(BRAVE_TO_ZIPKIN_KIND.get(kind));
}
String localServiceName = span.localServiceName();
String localIp = span.localIp();
if (localServiceName != null || localIp != null) {
zipkin2.Endpoint e = Endpoint.newBuilder().serviceName(localServiceName).ip(localIp).port(span.localPort()).build();
result.localEndpoint(ReportSpanBuilder.endpoint(e));
}
String remoteServiceName = span.remoteServiceName();
String remoteIp = span.remoteIp();
if (remoteServiceName != null || remoteIp != null) {
zipkin2.Endpoint e = Endpoint.newBuilder().serviceName(remoteServiceName).ip(remoteIp).port(span.remotePort()).build();
result.remoteEndpoint(ReportSpanBuilder.endpoint(e));
}
span.forEachTag(Consumer.INSTANCE, result);
span.forEachAnnotation(Consumer.INSTANCE, result);
if (span.shared())
result.shared(true);
if (span.debug())
result.debug(true);
return result.build();
}
use of com.google.cloud.servicedirectory.v1.Endpoint in project java-servicedirectory by googleapis.
the class RegistrationServiceClientTest method listEndpointsTest.
@Test
public void listEndpointsTest() throws Exception {
Endpoint responsesElement = Endpoint.newBuilder().build();
ListEndpointsResponse expectedResponse = ListEndpointsResponse.newBuilder().setNextPageToken("").addAllEndpoints(Arrays.asList(responsesElement)).build();
mockRegistrationService.addResponse(expectedResponse);
ServiceName parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[NAMESPACE]", "[SERVICE]");
ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent);
List<Endpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getEndpointsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListEndpointsRequest actualRequest = ((ListEndpointsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.servicedirectory.v1.Endpoint in project java-servicedirectory by googleapis.
the class EndpointsCreate method createEndpoint.
// Create a new endpoint.
public static void createEndpoint(String projectId, String locationId, String namespaceId, String serviceId, String endpointId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
// The service to create the endpoint in.
ServiceName parent = ServiceName.of(projectId, locationId, namespaceId, serviceId);
// The endpoint to create, with fields filled in.
// Optionally set an IP address and port for the endpoint.
Endpoint endpoint = Endpoint.newBuilder().setAddress("10.0.0.1").setPort(443).build();
// Send the request to create the endpoint.
Endpoint createdEndpoint = client.createEndpoint(parent, endpoint, endpointId);
// Process the response.
System.out.println("Created Endpoint: " + createdEndpoint.getName());
System.out.println("IP Address: " + createdEndpoint.getAddress());
System.out.println("Port: " + createdEndpoint.getPort());
}
}
Aggregations