Skip to content

Commit

Permalink
Merge branch 'main' into policy-alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
hasit committed Jan 26, 2024
2 parents d16d28c + 3834d85 commit 898a69e
Show file tree
Hide file tree
Showing 68 changed files with 15,476 additions and 1,460 deletions.
2 changes: 0 additions & 2 deletions .circleci/continue-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: 2.1
orbs:
docker: circleci/[email protected]
gcp-gcr: circleci/[email protected]
codecov: codecov/[email protected]

executors:
base-cimg-executor:
Expand Down Expand Up @@ -305,7 +304,6 @@ jobs:
$PKGS
mkdir -p /tmp/test-results
mv unit-tests.xml /tmp/test-results
- codecov/upload
- store_test_results:
path: /tmp/test-results
- run:
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<a href="https://goreportcard.com/report/github.com/fluxninja/aperture">
<img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/fluxninja/aperture?style=for-the-badge">
</a>
<a href="https://codecov.io/gh/fluxninja/aperture/branch/main/">
<img alt="Codecov Status" src="https://img.shields.io/codecov/c/github/fluxninja/aperture?style=for-the-badge&logo=codecov">
</a>
<a href="https://pkg.go.dev/github.com/fluxninja/aperture">
<img alt="Godoc Reference" src="https://img.shields.io/badge/godoc-reference-brightgreen?style=for-the-badge&logo=go&logoColor=white">
</a>
Expand Down
2 changes: 1 addition & 1 deletion api/buf.gen.aperture-langs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins:
out: gen/proto/java
- plugin: buf.build/grpc/python
out: gen/proto/python
- plugin: buf.build/protocolbuffers/python:v24.4
- plugin: buf.build/protocolbuffers/python:v25.2
out: gen/proto/python
- plugin: buf.build/protocolbuffers/pyi
out: gen/proto/python
Expand Down
18 changes: 0 additions & 18 deletions concurrency-limiting-test.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion sdks/aperture-go/examples/manual/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/fluxninja/aperture/api/v2 v2.0.0-20240123210709-ea3fb20237aa // indirect
github.com/fluxninja/aperture/api/v2 v2.0.0-20240126005715-ea93b670518e // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions sdks/aperture-go/examples/manual/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240123210709-ea3fb20237aa h1:eze+1jlQwCkuNPIk4RmTEBY7sLnL/WSDu/vWNLPz43I=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240123210709-ea3fb20237aa/go.mod h1:KSjIteqXmGJl1WOxQeBF9/K6/0sMHfKsRl5VOQkxyNg=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240126005715-ea93b670518e h1:KoW+oFm/1S8plY6DvVTJXs0jRgmvtW/psjuLh1yWHZM=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240126005715-ea93b670518e/go.mod h1:KSjIteqXmGJl1WOxQeBF9/K6/0sMHfKsRl5VOQkxyNg=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down
2 changes: 1 addition & 1 deletion sdks/aperture-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/fluxninja/aperture-go/v2
go 1.21.4

require (
github.com/fluxninja/aperture/api/v2 v2.0.0-20240123210709-ea3fb20237aa
github.com/fluxninja/aperture/api/v2 v2.0.0-20240126005715-ea93b670518e
github.com/gorilla/mux v1.8.1
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0
Expand Down
4 changes: 2 additions & 2 deletions sdks/aperture-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240123210709-ea3fb20237aa h1:eze+1jlQwCkuNPIk4RmTEBY7sLnL/WSDu/vWNLPz43I=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240123210709-ea3fb20237aa/go.mod h1:KSjIteqXmGJl1WOxQeBF9/K6/0sMHfKsRl5VOQkxyNg=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240126005715-ea93b670518e h1:KoW+oFm/1S8plY6DvVTJXs0jRgmvtW/psjuLh1yWHZM=
github.com/fluxninja/aperture/api/v2 v2.0.0-20240126005715-ea93b670518e/go.mod h1:KSjIteqXmGJl1WOxQeBF9/K6/0sMHfKsRl5VOQkxyNg=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down
2 changes: 1 addition & 1 deletion sdks/aperture-js/example/rate_limit_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function handleRequestRateLimit(apertureClient: ApertureClient) {
user_id: "some_user_id",
},
grpcCallOptions: {
deadline: Date.now() + 300, // ms
deadline: Date.now() + 1000, // ms
},
});
// END: RLStartFlow
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 13 additions & 37 deletions sdks/aperture-py/aperture_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import logging
import time
import typing
from dataclasses import dataclass
from typing import Callable, Dict, Optional, Type, TypeVar
from typing import Callable, Optional, Type, TypeVar

import grpc
from aperture_sdk._gen.aperture.flowcontrol.check.v1.check_pb2 import (
Expand All @@ -16,9 +15,9 @@
from aperture_sdk._gen.aperture.flowcontrol.check.v1.check_pb2_grpc import (
FlowControlServiceStub,
)
from aperture_sdk.client_common import *
from aperture_sdk.const import (
default_grpc_reconnection_time,
default_rpc_timeout,
flow_start_timestamp_label,
library_name,
library_version,
Expand All @@ -27,7 +26,6 @@
)
from aperture_sdk.flow import Flow
from aperture_sdk.utils import TWrappedReturn, run_fn
from grpc import AuthMetadataContext, AuthMetadataPluginCallback
from opentelemetry import baggage, trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, SERVICE_VERSION, Resource
Expand All @@ -37,26 +35,6 @@

TApertureClient = TypeVar("TApertureClient", bound="ApertureClient")
TWrappedFunction = Callable[..., TWrappedReturn]
Labels = Dict[str, str]


class ApertureCloudAuthMetadataPlugin(grpc.AuthMetadataPlugin):
def __init__(self, api_key):
self.api_key = api_key

def __call__(
self, context: AuthMetadataContext, callback: AuthMetadataPluginCallback
) -> None:
callback((("x-api-key", self.api_key),), None)


@dataclass
class FlowParams:
explicit_labels: Optional[Labels] = None
check_timeout: datetime.timedelta = default_rpc_timeout
ramp_mode: bool = False
result_cache_key: Optional[str] = None
global_cache_keys: Optional[typing.List[str]] = None


class ApertureClient:
Expand All @@ -69,7 +47,7 @@ def __init__(
channel: grpc.Channel,
otlp_exporter: OTLPSpanExporter,
):
self.logger = logging.getLogger("aperture-py-sdk")
self.logger = logging.getLogger("aperture-py")

resource = Resource.create(
{
Expand Down Expand Up @@ -102,14 +80,14 @@ def new_client(
credentials = grpc.ssl_channel_credentials()
if api_key:
metadata_plugin_instance = ApertureCloudAuthMetadataPlugin(api_key)

credentials = grpc.composite_channel_credentials(
credentials,
grpc.metadata_call_credentials(
metadata_plugin=metadata_plugin_instance,
name="x-api-key",
),
)

otlp_exporter = OTLPSpanExporter(
endpoint=address,
insecure=insecure,
Expand Down Expand Up @@ -169,11 +147,9 @@ def start_flow(
try:
# stub.Check is typed to accept an int, but it actually accepts a float
timeout = typing.cast(int, params.check_timeout.total_seconds())
response = (
stub.Check(request)
if timeout == 0
else stub.Check(request, timeout=timeout)
)
if timeout == 0:
timeout = None
response = stub.Check(request, timeout=timeout)
except grpc.RpcError as e:
self.logger.debug(f"Aperture gRPC call failed: {e.details()}")
response = None
Expand All @@ -199,12 +175,12 @@ def decorate(
def decorator(fn: TWrappedFunction) -> TWrappedFunction:
@functools.wraps(fn)
async def wrapper(*args, **kwargs):
with self.start_flow(control_point, params) as flow:
if flow.should_run():
return await run_fn(fn, *args, **kwargs)
else:
if on_reject:
return on_reject()
flow = self.start_flow(control_point, params)
if flow.should_run():
return await run_fn(fn, *args, **kwargs)
else:
if on_reject:
return on_reject()

return wrapper

Expand Down
Loading

0 comments on commit 898a69e

Please sign in to comment.