Skip to content

Commit c05b07d

Browse files
committed
Merge branch 'feat/caching' into feat/grpc-sync-addition
Signed-off-by: Simon Schrottner <[email protected]>
2 parents f91dd5c + 3c0e9cc commit c05b07d

File tree

24 files changed

+618
-247
lines changed

24 files changed

+618
-247
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
name: "Build, lint, and test"
77

88
on:
9+
push:
10+
branches:
11+
- main
912
pull_request:
1013
types:
1114
- opened
@@ -26,6 +29,7 @@ jobs:
2629
package:
2730
- "hooks/openfeature-hooks-opentelemetry"
2831
- "providers/openfeature-provider-flagd"
32+
- "providers/openfeature-provider-ofrep"
2933

3034
steps:
3135
- uses: actions/checkout@v4
@@ -45,6 +49,11 @@ jobs:
4549
run: hatch build
4650
working-directory: ${{ matrix.package }}
4751

52+
- name: Type checking
53+
if: matrix.python-version == '3.11'
54+
working-directory: ${{ matrix.package }}
55+
run: hatch run mypy:run
56+
4857
- name: Test with pytest
4958
run: hatch test -c
5059
working-directory: ${{ matrix.package }}

.pre-commit-config.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,3 @@ repos:
1414
- id: check-yaml
1515
- id: trailing-whitespace
1616
- id: check-merge-conflict
17-
18-
- repo: https://github.com/pre-commit/mirrors-mypy
19-
rev: v1.11.2
20-
hooks:
21-
- id: mypy
22-
args: [--python-version=3.8]
23-
additional_dependencies:
24-
- openfeature-sdk>=0.4.0
25-
- opentelemetry-api
26-
- types-protobuf
27-
- types-PyYAML
28-
- types-requests
29-
- mmh3
30-
- semver
31-
- panzi-json-logic
32-
exclude: proto|tests

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ To run the integration tests you need to have a container runtime, like docker,
3838
hatch run test
3939
```
4040

41+
### Type checking
42+
43+
Run `mypy` by entering the package directory and running `hatch run mypy:run`.
44+
4145
## Pull Request
4246

4347
All contributions to the OpenFeature project are welcome via GitHub pull requests.

hooks/openfeature-hooks-opentelemetry/pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,31 @@ cov = [
5050
"cov-report",
5151
]
5252

53+
[tool.hatch.envs.mypy]
54+
dependencies = [
55+
"mypy[faster-cache]>=1.13.0",
56+
]
57+
58+
[tool.hatch.envs.mypy.scripts]
59+
run = "mypy"
60+
5361
[tool.hatch.build.targets.sdist]
5462
exclude = [
5563
".gitignore",
5664
]
5765

5866
[tool.hatch.build.targets.wheel]
5967
packages = ["src/openfeature"]
68+
69+
[tool.mypy]
70+
mypy_path = "src"
71+
files = "src"
72+
73+
python_version = "3.8" # should be identical to the minimum supported version
74+
namespace_packages = true
75+
explicit_package_bases = true
76+
local_partial_types = true
77+
pretty = true
78+
79+
strict = true
80+
disallow_any_generics = false

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
files = hooks,providers
2+
files = hooks,providers/openfeature-provider-ofrep
33
exclude = proto|tests
44
untyped_calls_exclude = flagd.proto
55

providers/openfeature-provider-flagd/README.md

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ The default options can be defined in the FlagdProvider constructor.
105105
> [!NOTE]
106106
> Some configurations are only applicable for RPC resolver.
107107
108-
109108
<!--
110109
### Unix socket support
111-
112110
Unix socket communication with flagd is facilitated by usaging of the linux-native `epoll` library on `linux-x86_64`
113111
only (ARM support is pending the release of `netty-transport-native-epoll` v5).
114112
Unix sockets are not supported on other platforms or architectures.
@@ -118,8 +116,7 @@ Unix sockets are not supported on other platforms or architectures.
118116

119117
Reconnection is supported by the underlying gRPC connections.
120118
If the connection to flagd is lost, it will reconnect automatically.
121-
A failure to connect will result in an [error event](https://openfeature.dev/docs/reference/concepts/events#provider_error) from the provider, though it will attempt to reconnect
122-
indefinitely.
119+
A failure to connect will result in an [error event](https://openfeature.dev/docs/reference/concepts/events#provider_error) from the provider, though it will attempt to reconnect indefinitely.
123120

124121
### Deadlines
125122

@@ -131,24 +128,12 @@ They behave differently based on the resolver type.
131128
If the remote evaluation call is not completed within this deadline, the gRPC call is terminated with the error `DEADLINE_EXCEEDED`
132129
and the evaluation will default.
133130

134-
#### Deadlines with In-process resolver
135-
136-
In-process resolver with remote evaluation uses the `deadline` for synchronous gRPC calls to fetch metadata from flagd as part of its initialization process.
137-
If fetching metadata fails within this deadline, the provider will try to reconnect.
138-
The `streamDeadlineMs` defines a deadline for the streaming connection that listens to flag configuration updates from
139-
flagd. After the deadline is exceeded, the provider closes the gRPC stream and will attempt to reconnect.
140-
141-
In-process resolver with offline evaluation uses the `deadline` for file reads to fetch flag definitions.
142-
If the provider cannot open and read the file within this deadline, the provider will default the evaluation.
143-
144-
145131
### TLS
146132

147133
TLS is available in situations where flagd is running on another host.
148134

149135
<!--
150136
You may optionally supply an X.509 certificate in PEM format. Otherwise, the default certificate store will be used.
151-
152137
```java
153138
FlagdProvider flagdProvider = new FlagdProvider(
154139
FlagdOptions.builder()
@@ -159,22 +144,6 @@ FlagdProvider flagdProvider = new FlagdProvider(
159144
```
160145
-->
161146

162-
### Caching (RPC only)
163-
164-
> [!NOTE]
165-
> The in-process resolver does not benefit from caching since all evaluations are done locally and do not involve I/O.
166-
167-
The provider attempts to establish a connection to flagd's event stream (up to 5 times by default).
168-
If the connection is successful and caching is enabled, each flag returned with the reason `STATIC` is cached until an event is received
169-
concerning the cached flag (at which point it is removed from the cache).
170-
171-
On invocation of a flag evaluation (if caching is available), an attempt is made to retrieve the entry from the cache, if
172-
found the flag is returned with the reason `CACHED`.
173-
174-
By default, the provider is configured to
175-
use [least recently used (lru)](https://pypi.org/project/cachebox/)
176-
caching with up to 1000 entries.
177-
178147
## License
179148

180149
Apache 2.0 - See [LICENSE](./LICENSE) for more information.

providers/openfeature-provider-flagd/pyproject.toml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818
keywords = []
1919
dependencies = [
20-
"openfeature-sdk>=0.4.0",
20+
"openfeature-sdk>=0.6.0",
2121
"grpcio>=1.68.0",
2222
"protobuf>=4.25.2",
2323
"mmh3>=4.1.0",
@@ -60,6 +60,20 @@ cov = [
6060
"cov-report",
6161
]
6262

63+
64+
[tool.hatch.envs.mypy]
65+
dependencies = [
66+
"mypy[faster-cache]>=1.13.0",
67+
"types-protobuf",
68+
"types-pyyaml",
69+
]
70+
pre-install-commands = [
71+
"hatch build",
72+
]
73+
74+
[tool.hatch.envs.mypy.scripts]
75+
run = "mypy"
76+
6377
[tool.hatch.build.hooks.protobuf]
6478
generate_pyi = false
6579
dependencies = [
@@ -83,8 +97,6 @@ outputs = ["{proto_path}/{proto_name}_pb2_grpc.pyi"]
8397
exclude = [
8498
".gitignore",
8599
"/openfeature",
86-
"test-harness",
87-
"spec"
88100
]
89101

90102
[tool.hatch.build.targets.wheel]
@@ -93,6 +105,32 @@ packages = ["src/openfeature"]
93105
[tool.coverage.run]
94106
omit = [
95107
# exclude generated files
96-
"src/schemas/*",
108+
"src/openfeature/schemas/*",
97109
"tests/**",
98110
]
111+
112+
[tool.mypy]
113+
mypy_path = "src"
114+
files = "src"
115+
116+
python_version = "3.8" # should be identical to the minimum supported version
117+
namespace_packages = true
118+
explicit_package_bases = true
119+
local_partial_types = true
120+
pretty = true
121+
122+
strict = true
123+
disallow_any_generics = false
124+
125+
[[tool.mypy.overrides]]
126+
module = [
127+
"grpc.*",
128+
"json_logic.*",
129+
]
130+
ignore_missing_imports = true
131+
132+
[[tool.mypy.overrides]]
133+
module = [
134+
"openfeature.schemas.*"
135+
]
136+
warn_unused_ignores = false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[pytest]
2+
markers =
3+
rpc: tests for rpc mode.
4+
in-process: tests for rpc mode.
5+
customCert: Supports custom certs.
6+
unixsocket: Supports unixsockets.
7+
events: Supports events.
8+
sync: Supports sync.
9+
caching: Supports caching.
10+
offline: Supports offline.

0 commit comments

Comments
 (0)