Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce service definition for GRPC sync contract #78

Merged
merged 18 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions protobuf/buf.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# Flagd build spec

## This repository is managed by OpenFeature
### Managed by [OpenFeature](https://github.com/open-feature).

This module contains the core types that developers can use for interacting with [flagd](https://github.com/open-feature/flagd).
This repository contains grpc service definitions that developers can use for interacting with [flagd](https://github.com/open-feature/flagd).

Internally flagd uses the connect protocol, meaning it is compatible with grpc interfaces. If your desired language has a supported plugin for generating connect stubs then it is recommended to use these over grpc.
Given below are the modules exposed through this repository,

The package contains a single `Service`, describing the 5 core `rpcs` for feature flag evaluation (`ResolveBoolean`, `ResolveString`, `ResolveFloat`, `ResolveInt` and `ResolveObject`) each with their type specific request and response objects(`ResolveXXXRequest` and `ResolveXXXResponse`).
The final `rpc` on the `Service` is a streamed response named `EventStream`, this is used to pass internal events to the client, such as `configuration_change` and `provider_ready`.
- [Flag evaluation](#Flag-evaluation)
- [Flag sync](#Flag-sync)

## Build options
## Flag evaluation

The core definitions are in the `schema.v1` package, and contains package name options for the following languages, as such these options may be excluded from build instructions:
The module `schema.v1` contains a single `Service`, describing the 5 core `rpcs` for feature flag evaluation (`ResolveBoolean`,
`ResolveString`, `ResolveFloat`, `ResolveInt` and `ResolveObject`), each with their type specific request and
response objects (`ResolveXXXRequest` and `ResolveXXXResponse`). The final `rpc` on the `Service` is a streamed response
named `EventStream`, this is used to pass internal events to the client, such as `configuration_change` and `provider_ready`.

Internally, flagd uses the connect protocol, meaning it is compatible with grpc interfaces. If your desired language has
a supported plugin for generating connect stubs then it is recommended to use these over grpc.

## Flag sync

The module `sync.v1` is a grpc server streaming service definition to provide flagd with feature flag configurations.
This service exposes a single method `SyncFlags`. Flagd acts as the client and initiates the streaming with `SyncFlagsRequest`.

The server implementation will then stream feature flag configurations through `SyncFlagsResponse`. The response contains
`SyncState` which can be utilized to provide flagd with flexible configuration updates.

## Code generation

Easiest way to generate grpc code for your language of choice is using provided [buf](https://buf.build/) templates.
For example, with required binaries in your path, java code generation can be done using
`buf generate --template buf.gen.java.yaml` command.

- Go: schema/service/v1.0.0
- Java: dev.openfeature.flagd.grpc
- C#: OpenFeature.Flagd.Grpc
- PHP: OpenFeature\\Providers\\Flagd\\Schema\\Grpc
- Ruby: "OpenFeature::FlagD::Provider::Grpc"
52 changes: 52 additions & 0 deletions protobuf/sync/v1/sync_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
syntax = "proto3";

package sync.v1;

option go_package = "flagd/grpcsync";

// SyncFlagsRequest is the request initiating the sever-streaming rpc. Flagd sends this request, acting as the client
message SyncFlagsRequest {
// Optional: A unique identifier for flagd provider (grpc client) initiating the request. The server implementations
// can utilize this identifier to aggregate flag configurations and stream them to a specific client. This identifier
// is intended to be optional. However server implementation may enforce it.
string provider_id = 1;
}

// SyncState conveys the state of the payload. These states are related to flagd isync.go type definitions but
// contains extras to optimize grpc use case. Refer - https://github.com/open-feature/flagd/blob/main/pkg/sync/isync.go
enum SyncState {
// Value is ignored by the listening flagd
Kavindu-Dodan marked this conversation as resolved.
Show resolved Hide resolved
SYNC_STATE_UNSPECIFIED = 0;

// All the flags matching the request. This is the default response and other states can be ignored
// by the implementation. Flagd internally replaces all existing flags for this response state.
SYNC_STATE_ALL = 1;

// Convey an addition of a flag. Flagd internally handles this by combining new flags with existing ones
SYNC_STATE_ADD = 2;

// Convey an update of a flag. Flagd internally attempts to update if the updated flag already exist OR if it does not,
// it will get added
SYNC_STATE_UPDATE = 3;

// Convey a deletion of a flag. Flagd internally removes the flag
SYNC_STATE_DELETE = 4;

// Optional server ping to check client connectivity. Handling is ignored by flagd and is to merely support live check
SYNC_STATE_PING = 5;
}

// SyncFlagsResponse is the server response containing feature flag configurations and the state
message SyncFlagsResponse {
james-milligan marked this conversation as resolved.
Show resolved Hide resolved
// flagd feature flag configuration. Must be validated to schema - https://raw.githubusercontent.com/open-feature/schemas/main/json/flagd-definitions.json
string flag_configuration = 1;

// State conveying the operation to be performed by flagd. See the descriptions of SyncState for an explanation of
// supported values
SyncState state = 2;
}

// FlagService implements a server streaming to provide realtime flag configurations
service FlagSyncService {
rpc SyncFlags(SyncFlagsRequest) returns (stream SyncFlagsResponse) {}
}