Skip to content

Commit

Permalink
Ecosystem grpc support (#64)
Browse files Browse the repository at this point in the history
* Add first ecosystem modules, change package

* Initial support for GCP

* Improve azure, various adjustments

* Add

* Move common to to shared artifact, adjust packages

* Remove properties

* Adjust interceptor

* More logging adjustments

* Update documentation

* Run exampe on newest spring boot

* Bump version

* Fix version

* Adjust readme

* Adjust example / docs

* Adjust examples / docs
  • Loading branch information
skjolber authored Jan 20, 2025
1 parent f90a5dc commit ebe1d08
Show file tree
Hide file tree
Showing 147 changed files with 4,621 additions and 223 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Features:
* Selective 'on-demand' logging for unexpected web server behaviour
* capture full logs for problematic requests (i.e. not only WARN or ERROR, but also all sibling INFO log statements)
* reduce cost of logging considerably
* only supported for sync calls for now
* Unit testing
* Always assert against machine-readable JSON 'under the hood', regardless what is printed to console during local development
* Supported frameworks
Expand All @@ -33,18 +34,19 @@ This library is mostly based on

* SLF4J 2
* Logback + Logback logstash
* Lognet GRPC
* Logbook
* GRPC
* [Ecosystem](https://github.com/grpc-ecosystem/grpc-spring)
* [Lognet](https://github.com/LogNet/grpc-spring-boot-starter) (deprecated due to lack of maintenance)
* [Logbook](https://github.com/zalando/logbook)

Supported web technologies are:

* Spring web
* Spring + gRPC via Lognet
* Micrometer
* Spring + gRPC

Supported clouds:

* GCP (stackdriver)
* GCP (Stackdriver)
* Azure

# License
Expand All @@ -64,7 +66,7 @@ Each Spring Boot starter has a corresponding Spring Boot test starter. The Sprin
The above starters are implemented in two flavours:

* Servlet-based web
* Lognet gRPC
* Netty-based gRPC

## Getting started
See [Getting started with gRPC](guides/gRPC.md) or [Getting started with servlet-based web](guides/web.md). Alternatively, go directly to the [examples](examples).
Expand All @@ -75,7 +77,9 @@ See [Getting started with gRPC](guides/gRPC.md) or [Getting started with servlet
* Better define and tune request-response logging JSON format
* Add support for other text formats


# See also

* [logback-logstash-syntax-highlighting-decorators](https://github.com/entur/logback-logstash-syntax-highlighting-decorators)



48 changes: 22 additions & 26 deletions azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Import the below artifacts:
Add

```xml
<cloud-logging.version>2.0.x</cloud-logging>
<cloud-logging.version>4.0.x</cloud-logging>
```

and
Expand All @@ -82,7 +82,7 @@ and
<version>${cloud-logging.version}</version>
<scope>test</scope>
</dependency>
<!-- request-respons support -->
<!-- request-response support -->
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>request-response-spring-boot-starter-azure-web</artifactId>
Expand All @@ -97,7 +97,7 @@ and
<!-- on-demand logging support -->
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>on-demand-spring-boot-starter-azure-web</artifactId>
<artifactId>on-demand-spring-boot-starter-web</artifactId>
<version>${cloud-logging.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -126,7 +126,7 @@ For

```groovy
ext {
cloudLoggingVersion = '2.0.x'
cloudLoggingVersion = '4.0.x'
}
```

Expand All @@ -139,7 +139,7 @@ testImplementation("no.entur.logging.cloud:spring-boot-starter-azure-web-test:${
implementation("no.entur.logging.cloud:request-response-spring-boot-starter-azure-web:${cloudLoggingVersion}")
testImplementation("no.entur.logging.cloud:request-response-spring-boot-starter-azure-web-test:${cloudLoggingVersion}")
// on-demand logging support
implementation("no.entur.logging.cloud:on-demand-spring-boot-starter-azure-web:${cloudLoggingVersion}")
implementation("no.entur.logging.cloud:on-demand-spring-boot-starter-web:${cloudLoggingVersion}")
// metrics
implementation("no.entur.logging.cloud:micrometer-azure:${cloudLoggingVersion}")
// logger with additional log levels
Expand Down Expand Up @@ -185,7 +185,8 @@ gRPC request-response-logging for local development, for additional coloring and
## on-demand-spring-boot-starter-azure-grpc
Selective (on-demand) logging for logging only interesting requests.

Try the [configuration](on-demand-spring-boot-starter-azure-grpc/src/main/java/no/entur/logging/cloud/azure/spring/grpc/lognet/properties/OndemandProperties.java)
See the [configuration properties](../on-demand/on-demand-spring-boot-starter-grpc/src/main/java/no/entur/logging/cloud/spring/ondemand/grpc/properties/OndemandProperties.java)

```
entur.logging.grpc.ondemand.enabled=true
```
Expand All @@ -199,39 +200,39 @@ Import the below artifacts:
Add

```xml
<cloud-logging.version>2.0.x</cloud-logging>
<cloud-logging.version>4.0.x</cloud-logging>
```

and

```xml
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>spring-boot-starter-azure-grpc</artifactId>
<artifactId>spring-boot-starter-azure-grpc-ecosystem</artifactId>
<version>${cloud-logging.version}</version>
</dependency>
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>spring-boot-starter-azure-grpc-test</artifactId>
<artifactId>spring-boot-starter-azure-grpc-ecosystem-test</artifactId>
<version>${cloud-logging.version}</version>
<scope>test</scope>
</dependency>
<!-- request-response logging -->
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>request-response-spring-boot-starter-azure-grpc</artifactId>
<artifactId>request-response-spring-boot-starter-azure-grpc-ecosystem</artifactId>
<version>${cloud-logging.version}</version>
</dependency>
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>request-response-spring-boot-starter-azure-grpc-test</artifactId>
<artifactId>request-response-spring-boot-starter-azure-grpc-ecosystem-test</artifactId>
<version>${cloud-logging.version}</version>
<scope>test</scope>
</dependency>
<!-- on-demand logging -->
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>on-demand-spring-boot-starter-azure-grpc</artifactId>
<artifactId>on-demand-spring-boot-starter-grpc</artifactId>
<version>${cloud-logging.version}</version>
<scope>test</scope>
</dependency>
Expand All @@ -247,13 +248,13 @@ and
<artifactId>api</artifactId>
<version>${cloud-logging.version}</version>
</dependency>
// MDC support
<!-- MDC support -->
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>mdc-context-grpc-netty</artifactId>
<version>${cloud-logging.version}</version>
</dependency>
// Correlation id + various interceptors
<!-- Correlation id + various interceptors -->
<dependency>
<groupId>no.entur.logging.cloud</groupId>
<artifactId>correlation-id-trace-grpc-netty</artifactId>
Expand All @@ -277,20 +278,20 @@ For

```groovy
ext {
cloudLoggingVersion = '2.0.x'
cloudLoggingVersion = '4.0.x'
}
```

add

```groovy
implementation("no.entur.logging.cloud:spring-boot-starter-azure-grpc:${cloudLoggingVersion}")
testImplementation("no.entur.logging.cloud:spring-boot-starter-azure-grpc-test:${cloudLoggingVersion}")
implementation("no.entur.logging.cloud:spring-boot-starter-azure-grpc-ecosystem:${cloudLoggingVersion}")
testImplementation("no.entur.logging.cloud:spring-boot-starter-azure-grpc-ecosystem-test:${cloudLoggingVersion}")
// requst-response logging
implementation("no.entur.logging.cloud:request-response-spring-boot-starter-azure-grpc:${cloudLoggingVersion}")
testImplementation("no.entur.logging.cloud:request-response-spring-boot-starter-azure-grpc-test:${cloudLoggingVersion}")
implementation("no.entur.logging.cloud:request-response-spring-boot-starter-azure-grpc-ecosystem:${cloudLoggingVersion}")
testImplementation("no.entur.logging.cloud:request-response-spring-boot-starter-azure-grpc-ecosystem-test:${cloudLoggingVersion}")
// on-demand logging support
implementation("no.entur.logging.cloud:on-demand-spring-boot-starter-azure-grpc:${cloudLoggingVersion}")
implementation("no.entur.logging.cloud:on-demand-spring-boot-starter-grpc:${cloudLoggingVersion}")
// metrics
implementation("no.entur.logging.cloud:micrometer-azure:${cloudLoggingVersion}")
// logger with additional log levels
Expand Down Expand Up @@ -334,9 +335,4 @@ Avoid [OWASP dependency supressions](dependencycheck-root-suppression.xml) flagg
See [test-logback-junit](../test/test-logback-junit) for basic JUnit test support.

## Examples:

* [azure-grpc-example](../examples/azure-grpc-example) Lognet gRPC example
* [azure-web-example](../examples/azure-web-example) Spring-flavoured REST example
* [azure-web-grpc-example](../examples/azure-web-example) Spring-flavoured REST example with gRPC context (read: for further gRPC calls).
* [azure-grpc-without-test-artifacts-example](../examples/azure-grpc-without-test-artifacts-example) Lognet gRPC example without test artifacts
* [azure-web-without-test-artifacts-example](../examples/azure-web-without-test-artifacts-example) Spring-flavoured REST example without test artifacts
See [examples](../examples) for various examples.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.entur.logging.cloud.spring.logbook.azure;
package no.entur.logging.cloud.azure.logbook.spring;

import no.entur.logging.cloud.spring.logbook.LogbookLoggingAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
no.entur.logging.cloud.spring.logbook.azure.LogbookAzureAutoConfiguration
no.entur.logging.cloud.azure.logbook.spring.LogbookAzureAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

dependencies {
api project(":azure:spring-boot-autoconfigure-azure-test")
api project(':azure:request-response-spring-boot-starter-azure-grpc-ecosystem')
api project(':request-response:request-response-spring-boot-autoconfigure-grpc-ecosystem')

api ("org.entur.jackson:jackson-syntax-highlight:${jacksonSyntaxHighlightVersion}")
api ("org.entur.logback-logstash-syntax-highlighting-decorators:logback-logstash-syntax-highlighting-decorators:${logbackLogstashSyntaxHighlightingDecoratorsVersion}")

api ("net.logstash.logback:logstash-logback-encoder:${logbackLogstashVersion}")
api ("com.fasterxml.jackson.core:jackson-core:${jacksonVersion}")

api("org.slf4j:slf4j-api:${slf4jVersion}")
api("org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}")
implementation project(path: ':request-response:netty-grpc-test')

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

}




Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package no.entur.logging.cloud.azure.spring.grpc.ecosystem.test;

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;
import no.entur.logging.cloud.rr.grpc.test.CompositeSink;
import no.entur.logging.cloud.rr.grpc.test.PrettyPrintingLogLevelLogstashLogbackGrpcSink;
import no.entur.logging.cloud.rr.grpc.test.PrettyPrintingGrpcSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@AutoConfigureBefore(value = {
no.entur.logging.cloud.azure.spring.grpc.ecosystem.RequestResponseAzureGrpcEcosystemAutoConfiguration.class,
})

@Configuration
public class RequestResponseAzureGrpcEcosystemTestAutoConfiguration extends AbstractRequestResponseGrpcSinkAutoConfiguration {

@Bean
@ConditionalOnMissingBean(GrpcSink.class)
public GrpcSink grpcSink() {
Logger logger = LoggerFactory.getLogger(loggerName);
Level level = parseLevel(loggerLevel);

GrpcSink machineReadableSink = createMachineReadbleSink(logger, level);

// emulate default intellij color scheme
DefaultSyntaxHighlighter highlighter = DefaultSyntaxHighlighter.newBuilder()
.withField(AnsiSyntaxHighlight.MAGENTA)
.withBoolean(AnsiSyntaxHighlight.BLUE)
.withNumber(AnsiSyntaxHighlight.BLUE)
.withString(AnsiSyntaxHighlight.GREEN)
.build();

GrpcSink humanReadablePlainSink = new PrettyPrintingGrpcSink.Builder()
.withLogger(logger)
.withLogLevel(level)
.withSyntaxHighlighter(highlighter)
.build();

GrpcSink humanReadableJsonSink = PrettyPrintingLogLevelLogstashLogbackGrpcSink.newBuilder()
.withLogger(logger)
.withLogLevel(level)
.build();

return CompositeSink.newBuilder()
.withMachineReadableJsonSink(machineReadableSink)
.withHumanReadablePlainSink(humanReadablePlainSink)
.withHumanReadableJsonSink(humanReadableJsonSink)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no.entur.logging.cloud.azure.spring.grpc.ecosystem.test.RequestResponseAzureGrpcEcosystemTestAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package no.entur.logging.cloud.spring.logbook.web.test;

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 ebe1d08

Please sign in to comment.