Skip to content

Commit

Permalink
Move common to to shared artifact, adjust packages
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Dec 19, 2024
1 parent 7d0ba46 commit bd8febb
Show file tree
Hide file tree
Showing 58 changed files with 1,223 additions and 373 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ This library is mostly based on

* SLF4J 2
* Logback + Logback logstash
* Lognet GRPC
* GRPC
* Lognet
* Ecosystem
* Logbook

Supported web technologies are:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.entur.logging.cloud.azure.spring.grpc.ecosystem.test;

import no.entur.logging.cloud.spring.grpc.ecosystem.AbstractRequestResponseGrpcEcosystemSinkAutoConfiguration;
import no.entur.logging.cloud.spring.rr.grpc.AbstractRequestResponseGrpcSinkAutoConfiguration;
import org.entur.jackson.jsh.AnsiSyntaxHighlight;
import org.entur.jackson.jsh.DefaultSyntaxHighlighter;
import no.entur.logging.cloud.rr.grpc.GrpcSink;
Expand All @@ -20,7 +20,7 @@
})

@Configuration
public class RequestResponseAzureGrpcEcosystemTestAutoConfiguration extends AbstractRequestResponseGrpcEcosystemSinkAutoConfiguration {
public class RequestResponseAzureGrpcEcosystemTestAutoConfiguration extends AbstractRequestResponseGrpcSinkAutoConfiguration {

@Bean
@ConditionalOnMissingBean(GrpcSink.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package no.entur.logging.cloud.azure.spring.grpc.ecosystem;

import no.entur.logging.cloud.spring.grpc.ecosystem.AbstractRequestResponseGrpcEcosystemSinkAutoConfiguration;
import no.entur.logging.cloud.spring.grpc.ecosystem.RequestResponseGrpcEcosystemAutoConfiguration;
import no.entur.logging.cloud.spring.rr.grpc.AbstractRequestResponseGrpcSinkAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(value = "classpath:request-response.azure.properties", ignoreResourceNotFound = false)
@AutoConfigureBefore(RequestResponseGrpcEcosystemAutoConfiguration.class)
public class RequestResponseAzureGrpcEcosystemAutoConfiguration extends AbstractRequestResponseGrpcEcosystemSinkAutoConfiguration {
public class RequestResponseAzureGrpcEcosystemAutoConfiguration extends AbstractRequestResponseGrpcSinkAutoConfiguration {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.entur.logging.cloud.azure.spring.azure.grpc.lognet.test;

import no.entur.logging.cloud.azure.spring.grpc.lognet.RequestResponseAzureGrpcLognetAutoConfiguration;
import no.entur.logging.cloud.spring.grpc.lognet.AbstractRequestResponseGrpcLognetSinkAutoConfiguration;
import no.entur.logging.cloud.spring.rr.grpc.AbstractRequestResponseGrpcSinkAutoConfiguration;
import org.entur.jackson.jsh.AnsiSyntaxHighlight;
import org.entur.jackson.jsh.DefaultSyntaxHighlighter;
import no.entur.logging.cloud.rr.grpc.GrpcSink;
Expand All @@ -21,7 +21,7 @@
})

@Configuration
public class RequestResponseAzureGrpcLognetTestAutoConfiguration extends AbstractRequestResponseGrpcLognetSinkAutoConfiguration {
public class RequestResponseAzureGrpcLognetTestAutoConfiguration extends AbstractRequestResponseGrpcSinkAutoConfiguration {

@Bean
@ConditionalOnMissingBean(GrpcSink.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package no.entur.logging.cloud.azure.spring.grpc.lognet;

import no.entur.logging.cloud.spring.grpc.lognet.AbstractRequestResponseGrpcLognetSinkAutoConfiguration;
import no.entur.logging.cloud.spring.grpc.lognet.RequestResponseGrpcLognetAutoConfiguration;
import no.entur.logging.cloud.spring.rr.grpc.AbstractRequestResponseGrpcSinkAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(value = "classpath:request-response.azure.properties", ignoreResourceNotFound = false)
@AutoConfigureBefore(RequestResponseGrpcLognetAutoConfiguration.class)
public class RequestResponseAzureGrpcLognetAutoConfiguration extends AbstractRequestResponseGrpcLognetSinkAutoConfiguration {

public class RequestResponseAzureGrpcLognetAutoConfiguration extends AbstractRequestResponseGrpcSinkAutoConfiguration {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import net.devh.boot.grpc.server.service.GrpcService;
import no.entur.logging.cloud.spring.grpc.ecosystem.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.grpc.ecosystem.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.trace.spring.grpc.interceptor.OrderedCorrelationIdGrpcMdcContextServerInterceptor;
import org.springframework.context.annotation.Profile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


import net.devh.boot.grpc.server.service.GrpcService;
import no.entur.logging.cloud.spring.grpc.ecosystem.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.grpc.ecosystem.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.spring.ondemand.grpc.scope.GrpcLoggingScopeContextInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.trace.spring.grpc.interceptor.OrderedCorrelationIdGrpcMdcContextServerInterceptor;
import org.springframework.context.annotation.Profile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import net.devh.boot.grpc.server.service.GrpcService;
import no.entur.logging.cloud.spring.grpc.ecosystem.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.grpc.ecosystem.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.trace.spring.grpc.interceptor.OrderedCorrelationIdGrpcMdcContextServerInterceptor;
import org.springframework.context.annotation.Profile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@


import net.devh.boot.grpc.server.service.GrpcService;
import no.entur.logging.cloud.spring.grpc.ecosystem.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.grpc.ecosystem.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.spring.ondemand.grpc.scope.GrpcLoggingScopeContextInterceptor;
import no.entur.logging.cloud.grpc.trace.CorrelationIdGrpcMdcContextServerInterceptor;
import no.entur.logging.cloud.rr.grpc.GrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.OrderedGrpcLoggingServerInterceptor;
import no.entur.logging.cloud.spring.rr.grpc.RequestResponseGrpcExceptionHandlerInterceptor;
import no.entur.logging.cloud.trace.spring.grpc.interceptor.OrderedCorrelationIdGrpcMdcContextServerInterceptor;
import org.springframework.context.annotation.Profile;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# gcp-grpc-ecosystem-without-test-artifacts-example
Simple GRPC service example without test dependencies from this project.

This emulates the deployed application (i.e. machine readable JSON).
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
plugins {
id 'org.springframework.boot' version '3.3.4'
id "com.google.protobuf" version "0.9.4"
}

test {
useJUnitPlatform {
includeEngines 'junit-jupiter', 'junit-vintage'
}
}

dependencies {
implementation project(':on-demand:on-demand-spring-boot-starter-grpc')
implementation project(':gcp:spring-boot-starter-gcp-grpc-ecosystem')
implementation project(':gcp:request-response-spring-boot-starter-gcp-grpc-ecosystem')
implementation project(':trace:server:correlation-id-trace-grpc-netty')
implementation project(':request-response:request-response-spring-boot-autoconfigure-grpc-ecosystem')

implementation project(':trace:mdc-context-grpc-netty')

implementation("io.grpc:grpc-api:$grpcVersion")
implementation("io.grpc:grpc-core:$grpcVersion")
implementation("io.grpc:grpc-context:$grpcVersion")
implementation("io.grpc:grpc-stub:$grpcVersion")
//implementation("io.grpc:grpc-inprocess:$grpcVersion")
implementation("io.grpc:grpc-services:$grpcVersion")
implementation("io.grpc:grpc-netty:$grpcVersion")
implementation("io.grpc:grpc-util:$grpcVersion")
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")

testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")

// JUnit Jupiter API and TestEngine implementation
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")

testImplementation ("com.google.truth:truth:${googleTruthVersion}")
testImplementation ("com.google.truth.extensions:truth-java8-extension:${googleTruthVersion}")
}

sourceSets {
test.java.srcDirs += "${protobuf.generatedFilesBaseDir}/test/java"
test.java.srcDirs += "${protobuf.generatedFilesBaseDir}/test/grpc"
}

tasks.compileTestJava { dependsOn("generateTestProto") }

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${grpcProtobufVersion}"
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion"
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package no.entur.grpc.example;


import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import org.entur.grpc.example.GreetingResponse;
import org.entur.grpc.example.GreetingServiceGrpc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

public class AbstractGreetingController extends GreetingServiceGrpc.GreetingServiceImplBase {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGreetingController.class);

private final AtomicLong counter = new AtomicLong();

public void greeting1(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

MDC.put("localKey", "value");
try {
LOGGER.trace("Hello greeting / trace");
LOGGER.debug("Hello greeting / debug");
LOGGER.info("Hello greeting / info");
LOGGER.warn("Hello greeting / warn");
LOGGER.error("Hello greeting / error");
} finally {
MDC.remove("localKey");
}

responseObserver.onNext(createResponse(request));
responseObserver.onCompleted();
}

public void exceptionLogging(org.entur.grpc.example.GreetingRequest request, io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {
MDC.put("localKey", "value");
try {

System.out.flush();
System.out.println("System out before endpoint logging");

LOGGER.trace("This message should be ignored / trace");
LOGGER.debug("This message should be ignored / debug");
LOGGER.info("This message should be delayed / info");
LOGGER.warn("This message should be logged / warn");
LOGGER.error("This message should be logged / error");

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("System out after endpoint logging + 1000ms");

} finally {
MDC.remove("localKey");
}

Status status = Status.INVALID_ARGUMENT.withDescription("Mock exception");
throw status.asRuntimeException();
}

/**
* Multiple responses
*/

public void greeting3(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

String traceId = UUID.randomUUID().toString();
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("x-correlation-id", Metadata.ASCII_STRING_MARSHALLER), traceId);

LOGGER.trace("Hello greeting 3 / trace");
LOGGER.debug("Hello greeting 3 / debug");
LOGGER.info("Hello greeting 3 / info");
LOGGER.warn("Hello greeting 3 / warn");
for (int i = 0; i < 100; i++) {
responseObserver.onNext(GreetingResponse.newBuilder().setMessage("Hello " + i).setStatus(counter.getAndIncrement()).build());
}
responseObserver.onCompleted();
}

public void noLogging(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

LOGGER.trace("Hello no logging / trace");
LOGGER.debug("Hello no logging / debug");
LOGGER.info("Hello no logging / info");
LOGGER.warn("Hello no logging / warn");

responseObserver.onNext(createResponse(request));
responseObserver.onCompleted();
}

public void fullLogging(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

LOGGER.trace("Hello full logging");
LOGGER.debug("Hello full logging");
LOGGER.info("Hello full logging");
LOGGER.warn("Hello full logging");

responseObserver.onNext(createResponse(request));
responseObserver.onCompleted();
}

public void summaryLogging(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

LOGGER.trace("Hello summary logging");
LOGGER.debug("Hello summary logging");
LOGGER.info("Hello summary logging");
LOGGER.warn("Hello summary logging");

responseObserver.onNext(createResponse(request));
responseObserver.onCompleted();
}

protected GreetingResponse createResponse(org.entur.grpc.example.GreetingRequest request) {
StringBuilder builder = new StringBuilder("Hello");

long size = request.getReturnMessageSize();
if (size > 0) {
builder.append(' ');
for (long i = 0; i < request.getReturnMessageSize(); i++) {
builder.append((char) ('a' + (int) (i % 27)));
}
}

return GreetingResponse.newBuilder().setMessage(builder.toString()).setStatus(counter.incrementAndGet()).build();
}

public void greetingWithResponseObserverOnErrorCall(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

MDC.put("localKey", "value");
try {
LOGGER.trace("Hello error / trace");
LOGGER.debug("Hello error / debug");
LOGGER.info("Hello error / info");
LOGGER.warn("Hello error / warn");
LOGGER.error("Hello error / error");
} finally {
MDC.remove("localKey");
}

responseObserver.onError(new StatusRuntimeException(Status.INTERNAL));
}

public void greeting5(org.entur.grpc.example.GreetingRequest request,
io.grpc.stub.StreamObserver<GreetingResponse> responseObserver) {

MDC.put("localKey", "value");
try {
LOGGER.trace("Hello greeting 5");
LOGGER.debug("Hello greeting 5");
LOGGER.info("Hello greeting 5");
LOGGER.warn("Hello greeting 5");
} finally {
MDC.remove("localKey");
}

GreetingResponse response = createResponse(request);

// return same timestamp

responseObserver.onNext(GreetingResponse.newBuilder(response).setTimestamp(request.getTimestamp()).build());
responseObserver.onCompleted();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package no.entur.grpc.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}


Loading

0 comments on commit bd8febb

Please sign in to comment.