-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(flags): more flags production-readiness #26998
Changes from all commits
446fc72
e51fde4
1a78aee
f45d6f6
22c3d49
e41f4fe
14c29bf
107c97f
8b0d057
8e0c426
48a762c
055aae8
b280fa3
9c5de0d
07297d4
86d2b1b
eb4c1a9
1afa5a8
77c8112
cfcddbf
16c1f18
920479d
3af7da0
ecd72e1
fb8f4e1
28851a5
dc690eb
4fca396
e9b1fc1
1448733
27386ed
d677c5d
f3da199
44c94d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,11 @@ services: | |
path /capture* | ||
} | ||
|
||
@flags { | ||
path /flags | ||
path /flags* | ||
} | ||
|
||
handle @capture { | ||
reverse_proxy capture:3000 | ||
} | ||
|
@@ -37,6 +42,10 @@ services: | |
reverse_proxy replay-capture:3000 | ||
} | ||
|
||
handle @flags { | ||
reverse_proxy feature-flags:3001 | ||
} | ||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we run on port 3001, and then route it to port 8000 |
||
|
||
handle { | ||
reverse_proxy web:8000 | ||
} | ||
|
@@ -197,6 +206,24 @@ services: | |
SKIP_READS: 'false' | ||
FILTER_MODE: 'opt-out' | ||
|
||
feature-flags: | ||
image: ghcr.io/posthog/posthog/feature-flags:master | ||
build: | ||
context: rust/ | ||
args: | ||
BIN: feature-flags | ||
restart: on-failure | ||
volumes: | ||
- ./share:/share | ||
environment: | ||
WRITE_DATABASE_URL: 'postgres://posthog:posthog@db:5432/posthog' | ||
READ_DATABASE_URL: 'postgres://posthog:posthog@db:5432/posthog' | ||
MAXMIND_DB_PATH: '/share/GeoLite2-City.mmdb' | ||
REDIS_URL: 'redis://redis:6379/' | ||
ADDRESS: '0.0.0.0:3001' | ||
SKIP_WRITES: 'false' | ||
SKIP_READS: 'false' | ||
|
||
plugins: | ||
command: ./bin/plugin-server --no-restart-loop | ||
restart: on-failure | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ use std::net::IpAddr; | |
|
||
use crate::{ | ||
api::errors::FlagError, | ||
api::handler::{process_request, FlagsQueryParams, RequestContext}, | ||
api::types::FlagsResponse, | ||
api::request_handler::{process_request, FlagsQueryParams, RequestContext}, | ||
api::types::{FlagsOptionsResponse, FlagsResponse, FlagsResponseCode}, | ||
router, | ||
}; | ||
// TODO: stream this instead | ||
|
@@ -53,6 +53,12 @@ pub async fn flags( | |
Ok(Json(process_request(context).await?)) | ||
} | ||
|
||
pub async fn options() -> Result<Json<FlagsOptionsResponse>, FlagError> { | ||
Ok(Json(FlagsOptionsResponse { | ||
status: FlagsResponseCode::Ok, | ||
})) | ||
} | ||
Comment on lines
+56
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handle options requests like we do in |
||
|
||
fn record_request_metadata( | ||
headers: &HeaderMap, | ||
method: &Method, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ pub enum ClientFacingError { | |
Unauthorized(String), | ||
#[error("Rate limited")] | ||
RateLimited, | ||
#[error("billing limit reached")] | ||
BillingLimit, | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will implement the quota limiting in another PR; I started on it and then it got kinda beefy. Leaving this in for now though since it's harmless to add the error type, the PR will land shortly anyway. |
||
#[error("Service unavailable")] | ||
ServiceUnavailable, | ||
} | ||
|
@@ -67,6 +69,7 @@ impl IntoResponse for FlagError { | |
FlagError::ClientFacing(err) => match err { | ||
ClientFacingError::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg), | ||
ClientFacingError::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg), | ||
ClientFacingError::BillingLimit => (StatusCode::PAYMENT_REQUIRED, "Billing limit reached. Please upgrade your plan.".to_string()), | ||
ClientFacingError::RateLimited => (StatusCode::TOO_MANY_REQUESTS, "Rate limit exceeded. Please reduce your request frequency and try again later.".to_string()), | ||
ClientFacingError::ServiceUnavailable => (StatusCode::SERVICE_UNAVAILABLE, "Service is currently unavailable. Please try again later.".to_string()), | ||
}, | ||
|
@@ -176,7 +179,7 @@ impl From<CustomRedisError> for FlagError { | |
match e { | ||
CustomRedisError::NotFound => FlagError::TokenValidationError, | ||
CustomRedisError::PickleError(e) => { | ||
tracing::error!("failed to fetch data: {}", e); | ||
tracing::error!("failed to fetch data from redis: {}", e); | ||
FlagError::RedisDataParsingError | ||
} | ||
CustomRedisError::Timeout(_) => FlagError::TimeoutError, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod endpoint; | ||
pub mod errors; | ||
pub mod handler; | ||
pub mod request_handler; | ||
pub mod test_endpoint; | ||
pub mod types; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this puts the flags service behind the reverse proxy that's handling our other rust services.