mirror of
https://codeberg.org/JasterV/grpc-slides.git
synced 2026-04-26 18:40:03 +00:00
Update styles
This commit is contained in:
parent
1c525f179c
commit
a6d0cbafd6
3 changed files with 51 additions and 50 deletions
|
|
@ -240,22 +240,21 @@ section.has-light-background h6 {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: var(--r-block-margin) auto;
|
margin: var(--r-block-margin) auto;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
font-size: 0.55em;
|
|
||||||
font-family: var(--r-code-font);
|
font-family: var(--r-code-font);
|
||||||
line-height: 1.2em;
|
|
||||||
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.15);
|
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.15);
|
||||||
max-width: 90%;
|
max-width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.reveal .code-wrapper code {
|
.reveal .code-wrapper code {
|
||||||
max-height: 400px;
|
max-height: none;
|
||||||
font-family: var(--r-code-font);
|
font-family: var(--r-code-font);
|
||||||
tab-size: 2;
|
tab-size: 2;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
overflow-wrap: break-word;
|
overflow-wrap: break-word;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
font-size: 16px;
|
font-size: 1.3rem;
|
||||||
|
line-height: 1.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.reveal table {
|
.reveal table {
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ They auto-generated the client and server stubs:
|
||||||
`The user-stub and server-stub are automatically generated, by a program called Lupine.`
|
`The user-stub and server-stub are automatically generated, by a program called Lupine.`
|
||||||
|
|
||||||
---
|
---
|
||||||
### Interface Definition Language
|
## Interface Definition Language
|
||||||
|
|
||||||
```thrift
|
```thrift
|
||||||
struct Phone {
|
struct Phone {
|
||||||
|
|
@ -109,7 +109,7 @@ google Remote procedure calls
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Why a framework?
|
## Why a framework?
|
||||||
|
|
||||||
gRPC dictates how you will build your network interface.
|
gRPC dictates how you will build your network interface.
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ Some implementations wrap the original C library, some don't.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Built on top of HTTP2
|
## Built on top of HTTP2
|
||||||
|
|
||||||
So we get for free
|
So we get for free
|
||||||
- **Multiplexing**
|
- **Multiplexing**
|
||||||
|
|
@ -141,7 +141,7 @@ Explain multiplexing and server push
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 4 types of RPC supported
|
## 4 types of RPC supported
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ note:
|
||||||
Explain that each of these RPC types can be specified on the protobuffers IDL
|
Explain that each of these RPC types can be specified on the protobuffers IDL
|
||||||
|
|
||||||
---
|
---
|
||||||
### Metadata
|
## Metadata
|
||||||
|
|
||||||
Key-value pairs of data used to provide additional information about a call.
|
Key-value pairs of data used to provide additional information about a call.
|
||||||
|
|
||||||
|
|
@ -169,7 +169,7 @@ On the link I show, they document the supported values for metadata
|
||||||
Can be useful for: Authentication & tracing
|
Can be useful for: Authentication & tracing
|
||||||
|
|
||||||
---
|
---
|
||||||
### And many more features
|
## And many more features
|
||||||
|
|
||||||
- **Health checking** (Service-specific health checking)
|
- **Health checking** (Service-specific health checking)
|
||||||
- **Interceptors** (Middleware for RPCs)
|
- **Interceptors** (Middleware for RPCs)
|
||||||
|
|
@ -189,7 +189,7 @@ It is important to explain that these features might differ from language to lan
|
||||||
|
|
||||||
- **Health check**: gRPC specifies a standard service API ([health/v1](https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto)) for performing health check calls against gRPC servers. An implementation of this service is provided, but you are responsible for updating the health status of your services. It is pluggable, and some languages might not provide it.
|
- **Health check**: gRPC specifies a standard service API ([health/v1](https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto)) for performing health check calls against gRPC servers. An implementation of this service is provided, but you are responsible for updating the health status of your services. It is pluggable, and some languages might not provide it.
|
||||||
---
|
---
|
||||||
### Protocol buffers
|
## Protocol buffers
|
||||||
|
|
||||||
*Protocol Buffers are language-neutral, platform-neutral extensible mechanisms for serializing structured data.*
|
*Protocol Buffers are language-neutral, platform-neutral extensible mechanisms for serializing structured data.*
|
||||||
|
|
||||||
|
|
@ -203,7 +203,7 @@ It is also developed by google.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### They are a combination of
|
## They are a combination of
|
||||||
|
|
||||||
- The **Interface Definition Language**
|
- The **Interface Definition Language**
|
||||||
- The compiler that **generates code** from IDL files
|
- The compiler that **generates code** from IDL files
|
||||||
|
|
@ -215,10 +215,10 @@ note:
|
||||||
Here we will focus on the IDL and the tooling, we won't focus on the serialization format.
|
Here we will focus on the IDL and the tooling, we won't focus on the serialization format.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Protobufs as an Interface Definition Language
|
## Protobufs as an Interface Definition Language
|
||||||
---
|
---
|
||||||
|
|
||||||
### Defining messages
|
## Defining messages
|
||||||
|
|
||||||
```protobuf
|
```protobuf
|
||||||
// amend_termination/request/v1/request.proto
|
// amend_termination/request/v1/request.proto
|
||||||
|
|
@ -240,7 +240,7 @@ message AmendTerminationRequest {
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Defining a service
|
## Defining a service
|
||||||
|
|
||||||
```protobuf
|
```protobuf
|
||||||
// service/v1/service.proto
|
// service/v1/service.proto
|
||||||
|
|
@ -258,20 +258,20 @@ service PolicyManagementService {
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Remarkable features of Protocol buffers
|
## Remarkable features of Protocol buffers
|
||||||
|
|
||||||
- **Strongly typed** data
|
- **Strongly typed** data
|
||||||
- **Language** and **platform neutral**
|
- **Language** and **platform neutral**
|
||||||
- **Compact binary format**
|
- **Compact binary format**
|
||||||
- Support for **RPC service definition**
|
- Support for **RPC service definition**
|
||||||
- **Backward and Forward compatibility**
|
- **Backward** and **Forward compatibility**
|
||||||
|
|
||||||
note:
|
note:
|
||||||
|
|
||||||
Give a short example of why it is backward and forward compatible. Mention tags.
|
Give a short example of why it is backward and forward compatible. Mention tags.
|
||||||
|
|
||||||
---
|
---
|
||||||
### The protoc compiler
|
## The protoc compiler
|
||||||
|
|
||||||
Compiles `.proto` files into code.
|
Compiles `.proto` files into code.
|
||||||
Supports plugins for different languages.
|
Supports plugins for different languages.
|
||||||
|
|
@ -285,7 +285,7 @@ note:
|
||||||
`--proto_path` specifies the source directory, `--*_out` the destination directory, and the rest is the path to your `.proto`
|
`--proto_path` specifies the source directory, `--*_out` the destination directory, and the rest is the path to your `.proto`
|
||||||
|
|
||||||
---
|
---
|
||||||
### Buf CLI
|
## Buf CLI
|
||||||
|
|
||||||
- A **linter** for proto files
|
- A **linter** for proto files
|
||||||
- A **formatter** for proto files
|
- A **formatter** for proto files
|
||||||
|
|
@ -335,7 +335,7 @@ The main goal of tonic is to provide a generic gRPC implementation over HTTP/2
|
||||||
Codegen tools need to be used to generate the client and server stubs that will encode and decode the binary data and deal with other gRPC features such as streaming.
|
Codegen tools need to be used to generate the client and server stubs that will encode and decode the binary data and deal with other gRPC features such as streaming.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Features
|
## Features
|
||||||
|
|
||||||
- **Health check** of services
|
- **Health check** of services
|
||||||
- **Interceptors**
|
- **Interceptors**
|
||||||
|
|
@ -353,7 +353,7 @@ note:
|
||||||
These are only a few notable features, it provides more for sure
|
These are only a few notable features, it provides more for sure
|
||||||
|
|
||||||
---
|
---
|
||||||
### Generating code from Proto definitions :gear:
|
## Generating code from Proto definitions :gear:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// build.rs
|
// build.rs
|
||||||
|
|
@ -377,7 +377,7 @@ note:
|
||||||
First we need to talk about how do we generate code from our protobuf definitions.
|
First we need to talk about how do we generate code from our protobuf definitions.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Expose the generated code as a library
|
## Expose the generated code as a library
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// lib.rs
|
// lib.rs
|
||||||
|
|
@ -394,7 +394,7 @@ note:
|
||||||
We need to expose the generated code through our lib.rs
|
We need to expose the generated code through our lib.rs
|
||||||
|
|
||||||
---
|
---
|
||||||
### Auto generated services
|
## Auto generated services
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub trait PolicyManagementService {
|
pub trait PolicyManagementService {
|
||||||
|
|
@ -411,7 +411,7 @@ note:
|
||||||
We get a trait generated from the Protobuf Service definition
|
We get a trait generated from the Protobuf Service definition
|
||||||
|
|
||||||
---
|
---
|
||||||
### Building a server
|
## Building a server
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// main.rs
|
// main.rs
|
||||||
|
|
@ -439,7 +439,7 @@ Simple build of a Tonic Server. We will dive into how to add middleware later.
|
||||||
Highlight the fact that at the end of the day the gRPC server will be listening to a TCP port like any other HTTP2 server.
|
Highlight the fact that at the end of the day the gRPC server will be listening to a TCP port like any other HTTP2 server.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Building a client
|
## Building a client
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let mut client =
|
let mut client =
|
||||||
|
|
@ -462,7 +462,7 @@ note:
|
||||||
What if we wanted to add those headers for every request? Now we talk about interceptors
|
What if we wanted to add those headers for every request? Now we talk about interceptors
|
||||||
|
|
||||||
---
|
---
|
||||||
### Interceptors
|
## Interceptors
|
||||||
|
|
||||||
Interceptors are similar to middleware but with less flexibility.
|
Interceptors are similar to middleware but with less flexibility.
|
||||||
They allow you to:
|
They allow you to:
|
||||||
|
|
@ -470,7 +470,7 @@ They allow you to:
|
||||||
- Cancel a request with a `Status`.
|
- Cancel a request with a `Status`.
|
||||||
---
|
---
|
||||||
|
|
||||||
### Interceptors in practice
|
## Interceptors in practice
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn check_auth(req: Request<()>) -> Result<Request<()>, Status> {
|
fn check_auth(req: Request<()>) -> Result<Request<()>, Status> {
|
||||||
|
|
@ -487,7 +487,7 @@ let svc = PolicyManagementServiceServer::with_interceptor(
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
### Health checking gRPC services
|
## Health checking gRPC services
|
||||||
|
|
||||||
Tonic provides a health check service implementing a standard gRPC health checking protocol.
|
Tonic provides a health check service implementing a standard gRPC health checking protocol.
|
||||||
|
|
||||||
|
|
@ -506,7 +506,7 @@ It has rich semantics such as per-service health status.
|
||||||
The server has full control over the access of the health checking service.
|
The server has full control over the access of the health checking service.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Health service definition
|
## Health service definition
|
||||||
|
|
||||||
```protobuf
|
```protobuf
|
||||||
service Health {
|
service Health {
|
||||||
|
|
@ -524,7 +524,7 @@ This definition is provided by the official gRPC docs, each language runtime mig
|
||||||
https://github.com/grpc/grpc/blob/master/doc/health-checking.md
|
https://github.com/grpc/grpc/blob/master/doc/health-checking.md
|
||||||
</a>
|
</a>
|
||||||
---
|
---
|
||||||
### Enabling the health service
|
## Enabling the health service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let (health_reporter, health_service) = health_reporter();
|
let (health_reporter, health_service) = health_reporter();
|
||||||
|
|
@ -566,7 +566,7 @@ It's core abstraction is the Service, which we see in the next slide.
|
||||||
It exposes already a set of basic reusable services to solve common networking patterns such as timeouts and rate limiting.
|
It exposes already a set of basic reusable services to solve common networking patterns such as timeouts and rate limiting.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Tower service
|
## Tower service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub trait Service<Request> {
|
pub trait Service<Request> {
|
||||||
|
|
@ -596,7 +596,7 @@ It immediately returns a `Future` representing the eventual completion of proc
|
||||||
The processing may depend on calling other services. At some point in the future, the processing will complete, and the `Future` will resolve to a response or error.
|
The processing may depend on calling other services. At some point in the future, the processing will complete, and the `Future` will resolve to a response or error.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Layers
|
## Layers
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub trait Layer<S> {
|
pub trait Layer<S> {
|
||||||
|
|
@ -611,7 +611,7 @@ note:
|
||||||
Mechanism to layer services. It allows us to wrap a generic service with another one. It can be used to wrap a reusable service which is meant to act as a middleware around another service.
|
Mechanism to layer services. It allows us to wrap a generic service with another one. It can be used to wrap a reusable service which is meant to act as a middleware around another service.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Building a layered service
|
## Building a layered service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
ServiceBuilder::new()
|
ServiceBuilder::new()
|
||||||
|
|
@ -629,7 +629,7 @@ Timeout -> SSRHL -> Tracing -> SSRHL -> Auth -> Starsky service
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Building a layered service
|
## Building a layered service
|
||||||
|
|
||||||
<img alt="tower" src="assets/images/layers-diagram.svg" style="max-width: 45%;" />
|
<img alt="tower" src="assets/images/layers-diagram.svg" style="max-width: 45%;" />
|
||||||
---
|
---
|
||||||
|
|
@ -637,14 +637,14 @@ Timeout -> SSRHL -> Tracing -> SSRHL -> Auth -> Starsky service
|
||||||
Now let's dive into real middleware implementations
|
Now let's dive into real middleware implementations
|
||||||
|
|
||||||
---
|
---
|
||||||
### Authentication middleware
|
## Authentication middleware
|
||||||
|
|
||||||
Let's build one with Tower.
|
Let's build one with Tower.
|
||||||
|
|
||||||
We'll implement Auth0 M2M authentication.
|
We'll implement Auth0 M2M authentication.
|
||||||
|
|
||||||
---
|
---
|
||||||
#### Authentication service
|
## Authentication service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// Given a Json Web Key Set client and an audience,
|
// Given a Json Web Key Set client and an audience,
|
||||||
|
|
@ -666,7 +666,7 @@ The JwksClient contains the public keys to verify the signature of incoming toke
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Authentication service
|
## Authentication service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl<S> JwtAuth<S> {
|
impl<S> JwtAuth<S> {
|
||||||
|
|
@ -700,7 +700,7 @@ We assume that `make_unauthorized_response` will build a gRPC unauthorized respo
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Authentication service
|
## Authentication service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl<Req, Res, S> Service<http::Request<Req>> for JwtAuth<S>
|
impl<Req, Res, S> Service<http::Request<Req>> for JwtAuth<S>
|
||||||
|
|
@ -730,7 +730,7 @@ Finally implementing the service, pretty straight-forward
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Authentication layer
|
## Authentication layer
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// Reusable Tower Layer meant to wrap
|
// Reusable Tower Layer meant to wrap
|
||||||
|
|
@ -756,7 +756,7 @@ Although confusing, the purpose of the layer is to make the usage of the middlew
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Authentication layer
|
## Authentication layer
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl<S> Layer<S> for JwtAuthLayer {
|
impl<S> Layer<S> for JwtAuthLayer {
|
||||||
|
|
@ -777,7 +777,7 @@ note:
|
||||||
What is done inside of the `layer` function could just be done manually, but it is done here for better user experience later.
|
What is done inside of the `layer` function could just be done manually, but it is done here for better user experience later.
|
||||||
|
|
||||||
---
|
---
|
||||||
#### Attaching it to our gRPC server
|
## Attaching it to our gRPC server
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let authenticated_apis = ServiceBuilder::new()
|
let authenticated_apis = ServiceBuilder::new()
|
||||||
|
|
@ -794,7 +794,7 @@ note:
|
||||||
Simplified version of our real server implementation in `es-be`
|
Simplified version of our real server implementation in `es-be`
|
||||||
|
|
||||||
---
|
---
|
||||||
### Tracing Layer
|
## Tracing Layer
|
||||||
|
|
||||||
Let's build another Tower service.
|
Let's build another Tower service.
|
||||||
|
|
||||||
|
|
@ -802,7 +802,7 @@ Interceptors are not the best fit, we want to trace responses too.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Building a span from a request
|
## Building a span from a request
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn make_span<B>(request: &http::Request<B>) -> tracing::Span {
|
fn make_span<B>(request: &http::Request<B>) -> tracing::Span {
|
||||||
|
|
@ -841,7 +841,7 @@ Explain how this is a simplified version of the real implementation in `prima_to
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Updating the span from with the response
|
## Updating the span with the response
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn on_response<B>(response: &http::Response<B>, span: &tracing::Span) {
|
fn on_response<B>(response: &http::Response<B>, span: &tracing::Span) {
|
||||||
|
|
@ -867,7 +867,7 @@ We will see in a second how the span we receive by parameters is the same span w
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Tracing service
|
## Tracing service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub struct OpenTelemetryServerTracing<S> {
|
pub struct OpenTelemetryServerTracing<S> {
|
||||||
|
|
@ -881,7 +881,7 @@ We need to implement the service that will act as the tracing middleware
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Tracing service
|
## Tracing service
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl<Req, Res, S> Service<Request<Req>> for OpenTelemetryServerTracing<S>
|
impl<Req, Res, S> Service<Request<Req>> for OpenTelemetryServerTracing<S>
|
||||||
|
|
@ -919,7 +919,7 @@ Note how the same span is used to track the request and response.
|
||||||
Then that span is used as the parent span for the inner service call.
|
Then that span is used as the parent span for the inner service call.
|
||||||
|
|
||||||
---
|
---
|
||||||
#### Tracing layer
|
## Tracing layer
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub struct OpenTelemetryServerTracingLayer {}
|
pub struct OpenTelemetryServerTracingLayer {}
|
||||||
|
|
@ -938,7 +938,7 @@ As we've mentioned, layers exist for better development experience, services cou
|
||||||
In this case we don't need any data to be added to the layer.
|
In this case we don't need any data to be added to the layer.
|
||||||
|
|
||||||
---
|
---
|
||||||
#### Tracing layer
|
## Tracing layer
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl<S> Layer<S> for OpenTelemetryServerTracingLayer {
|
impl<S> Layer<S> for OpenTelemetryServerTracingLayer {
|
||||||
|
|
@ -951,7 +951,7 @@ impl<S> Layer<S> for OpenTelemetryServerTracingLayer {
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
#### Attaching it to our gRPC server
|
## Attaching it to our gRPC server
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
Server::builder()
|
Server::builder()
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,5 @@ revealjs:
|
||||||
history: true
|
history: true
|
||||||
slideNumber: c/t
|
slideNumber: c/t
|
||||||
jumpToSlide: true
|
jumpToSlide: true
|
||||||
|
height: 1080
|
||||||
|
width: 1920
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue