Skip to content

Commit 798cebd

Browse files
feat(executors): add support for selecting port for starting server
* Add option for adding cache parameters when initializing executor from source alias * Unify attributes names for telemetry
1 parent db15f96 commit 798cebd

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

libs/executors/garf_executors/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def setup_executor(
5757
'ApiExecutionContext',
5858
]
5959

60-
__version__ = '0.2.1'
60+
__version__ = '0.2.2'

libs/executors/garf_executors/api_executor.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,22 @@ def __init__(self, fetcher: report_fetcher.ApiReportFetcher) -> None:
5858

5959
@classmethod
6060
def from_fetcher_alias(
61-
cls, source: str, fetcher_parameters: dict[str, str] | None = None
61+
cls,
62+
source: str,
63+
fetcher_parameters: dict[str, str] | None = None,
64+
enable_cache: bool = False,
65+
cache_ttl_seconds: int = 3600,
6266
) -> ApiQueryExecutor:
6367
if not fetcher_parameters:
6468
fetcher_parameters = {}
6569
concrete_api_fetcher = fetchers.get_report_fetcher(source)
66-
return ApiQueryExecutor(fetcher=concrete_api_fetcher(**fetcher_parameters))
70+
return ApiQueryExecutor(
71+
fetcher=concrete_api_fetcher(
72+
**fetcher_parameters,
73+
enable_cache=enable_cache,
74+
cache_ttl_seconds=cache_ttl_seconds,
75+
)
76+
)
6777

6878
@tracer.start_as_current_span('api.execute')
6979
def execute(
@@ -86,11 +96,13 @@ def execute(
8696
GarfExecutorError: When failed to execute query.
8797
"""
8898
span = trace.get_current_span()
89-
span.set_attribute('fetcher', self.fetcher.__class__.__name__)
90-
span.set_attribute('api_client', self.fetcher.api_client.__class__.__name__)
99+
span.set_attribute('fetcher.class', self.fetcher.__class__.__name__)
100+
span.set_attribute(
101+
'api.client.class', self.fetcher.api_client.__class__.__name__
102+
)
91103
try:
92-
span.set_attribute('query_title', title)
93-
span.set_attribute('query_text', query)
104+
span.set_attribute('query.title', title)
105+
span.set_attribute('query.text', query)
94106
logger.debug('starting query %s', query)
95107
results = self.fetcher.fetch(
96108
query_specification=query,

libs/executors/garf_executors/entrypoints/server.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import fastapi
2020
import pydantic
21+
import typer
2122
import uvicorn
2223
from garf_io import reader
2324
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
25+
from typing_extensions import Annotated
2426

2527
import garf_executors
2628
from garf_executors import exceptions
@@ -29,6 +31,7 @@
2931
initialize_tracer()
3032
app = fastapi.FastAPI()
3133
FastAPIInstrumentor.instrument_app(app)
34+
typer_app = typer.Typer()
3235

3336

3437
class ApiExecutorRequest(pydantic.BaseModel):
@@ -104,5 +107,12 @@ def execute_batch(request: ApiExecutorRequest) -> ApiExecutorResponse:
104107
return ApiExecutorResponse(results=results)
105108

106109

110+
@typer_app.command()
111+
def main(
112+
port: Annotated[int, typer.Option(help='Port to start the server')] = 8000,
113+
):
114+
uvicorn.run(app, port=port)
115+
116+
107117
if __name__ == '__main__':
108-
uvicorn.run(app)
118+
typer_app()

libs/executors/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies = [
1111
"pydantic",
1212
"opentelemetry-api",
1313
"opentelemetry-sdk",
14+
"opentelemetry-exporter-otlp",
1415
]
1516
authors = [
1617
{name = "Google Inc. (gTech gPS CSE team)", email = "no-reply@google.com"},
@@ -51,7 +52,7 @@ sql=[
5152
server=[
5253
"fastapi[standard]",
5354
"opentelemetry-instrumentation-fastapi",
54-
"opentelemetry-exporter-otlp",
55+
"typer",
5556
]
5657
all = [
5758
"garf-executors[bq,sql,server]"

0 commit comments

Comments
 (0)