garf-executors 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {garf_executors-0.1.0 → garf_executors-0.1.2}/PKG-INFO +1 -1
  2. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/__init__.py +1 -1
  3. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/api_executor.py +8 -1
  4. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/entrypoints/cli.py +8 -3
  5. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/entrypoints/server.py +1 -1
  6. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/entrypoints/tracer.py +4 -6
  7. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/executor.py +30 -15
  8. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors.egg-info/PKG-INFO +1 -1
  9. {garf_executors-0.1.0 → garf_executors-0.1.2}/README.md +0 -0
  10. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/bq_executor.py +0 -0
  11. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/config.py +0 -0
  12. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/entrypoints/__init__.py +0 -0
  13. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/entrypoints/utils.py +0 -0
  14. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/exceptions.py +0 -0
  15. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/execution_context.py +0 -0
  16. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/fetchers.py +0 -0
  17. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/sql_executor.py +0 -0
  18. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors/telemetry.py +0 -0
  19. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors.egg-info/SOURCES.txt +0 -0
  20. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors.egg-info/dependency_links.txt +0 -0
  21. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors.egg-info/entry_points.txt +0 -0
  22. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors.egg-info/requires.txt +0 -0
  23. {garf_executors-0.1.0 → garf_executors-0.1.2}/garf_executors.egg-info/top_level.txt +0 -0
  24. {garf_executors-0.1.0 → garf_executors-0.1.2}/pyproject.toml +0 -0
  25. {garf_executors-0.1.0 → garf_executors-0.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: garf-executors
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Executes queries against API and writes data to local/remote storage.
5
5
  Author-email: "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>, Andrei Markin <andrey.markin.ppc@gmail.com>
6
6
  License: Apache 2.0
@@ -50,4 +50,4 @@ __all__ = [
50
50
  'ApiExecutionContext',
51
51
  ]
52
52
 
53
- __version__ = '0.1.0'
53
+ __version__ = '0.1.2'
@@ -20,9 +20,11 @@ GarfReport and saving it to local/remote storage.
20
20
 
21
21
  from __future__ import annotations
22
22
 
23
+ import asyncio
23
24
  import logging
24
25
 
25
26
  from garf_core import report_fetcher
27
+ from opentelemetry import trace
26
28
 
27
29
  from garf_executors import exceptions, execution_context, executor, fetchers
28
30
  from garf_executors.telemetry import tracer
@@ -76,7 +78,7 @@ class ApiQueryExecutor(executor.Executor):
76
78
  Returns:
77
79
  Result of writing the report.
78
80
  """
79
- return await self.execute(query, context, title, context)
81
+ return await asyncio.to_thread(self.execute, query, title, context)
80
82
 
81
83
  @tracer.start_as_current_span('api.execute')
82
84
  def execute(
@@ -98,7 +100,12 @@ class ApiQueryExecutor(executor.Executor):
98
100
  Raises:
99
101
  GarfExecutorError: When failed to execute query.
100
102
  """
103
+ span = trace.get_current_span()
104
+ span.set_attribute('fetcher', self.fetcher.__class__.__name__)
105
+ span.set_attribute('api_client', self.fetcher.api_client.__class__.__name__)
101
106
  try:
107
+ span.set_attribute('query_title', title)
108
+ span.set_attribute('query_text', query)
102
109
  logger.debug('starting query %s', query)
103
110
  results = self.fetcher.fetch(
104
111
  query_specification=query,
@@ -28,8 +28,13 @@ from garf_io import reader
28
28
  import garf_executors
29
29
  from garf_executors import config, exceptions
30
30
  from garf_executors.entrypoints import utils
31
+ from garf_executors.entrypoints.tracer import initialize_tracer
32
+ from garf_executors.telemetry import tracer
31
33
 
34
+ initialize_tracer()
32
35
 
36
+
37
+ @tracer.start_as_current_span('garf.entrypoints.cli')
33
38
  def main():
34
39
  parser = argparse.ArgumentParser()
35
40
  parser.add_argument('query', nargs='*')
@@ -49,7 +54,7 @@ def main():
49
54
  parser.add_argument('--dry-run', dest='dry_run', action='store_true')
50
55
  parser.add_argument('-v', '--version', dest='version', action='store_true')
51
56
  parser.add_argument(
52
- '--parallel-threshold', dest='parallel_threshold', default=None, type=int
57
+ '--parallel-threshold', dest='parallel_threshold', default=10, type=int
53
58
  )
54
59
  parser.set_defaults(parallel_queries=True)
55
60
  parser.set_defaults(dry_run=False)
@@ -77,7 +82,7 @@ def main():
77
82
  args.source, context.fetcher_parameters
78
83
  )
79
84
  batch = {query: reader_client.read(query) for query in args.query}
80
- query_executor.execute_batch(batch, context, args.parallel_queries)
85
+ query_executor.execute_batch(batch, context, args.parallel_threshold)
81
86
  else:
82
87
  extra_parameters = utils.ParamsParser(
83
88
  ['source', args.output, 'macro', 'template']
@@ -99,7 +104,7 @@ def main():
99
104
  if args.parallel_queries:
100
105
  logger.info('Running queries in parallel')
101
106
  batch = {query: reader_client.read(query) for query in args.query}
102
- query_executor.execute_batch(batch, context, args.parallel_queries)
107
+ query_executor.execute_batch(batch, context, args.parallel_threshold)
103
108
  else:
104
109
  logger.info('Running queries sequentially')
105
110
  for query in args.query:
@@ -94,7 +94,7 @@ async def execute(request: ApiExecutorRequest) -> ApiExecutorResponse:
94
94
 
95
95
 
96
96
  @app.post('/api/execute:batch')
97
- async def execute_batch(request: ApiExecutorRequest) -> ApiExecutorResponse:
97
+ def execute_batch(request: ApiExecutorRequest) -> ApiExecutorResponse:
98
98
  query_executor = garf_executors.setup_executor(
99
99
  request.source, request.context.fetcher_parameters
100
100
  )
@@ -34,11 +34,9 @@ def initialize_tracer():
34
34
 
35
35
  tracer_provider = TracerProvider(resource=resource)
36
36
 
37
- otlp_processor = BatchSpanProcessor(
38
- OTLPSpanExporter(
39
- endpoint=os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT'), insecure=True
37
+ if otel_endpoint := os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT'):
38
+ otlp_processor = BatchSpanProcessor(
39
+ OTLPSpanExporter(endpoint=otel_endpoint, insecure=True)
40
40
  )
41
- )
42
- tracer_provider.add_span_processor(otlp_processor)
43
-
41
+ tracer_provider.add_span_processor(otlp_processor)
44
42
  trace.set_tracer_provider(tracer_provider)
@@ -14,14 +14,18 @@
14
14
 
15
15
  """Defines common functionality between executors."""
16
16
 
17
- from concurrent import futures
17
+ import asyncio
18
+
19
+ from opentelemetry import trace
18
20
 
19
21
  from garf_executors import execution_context
22
+ from garf_executors.telemetry import tracer
20
23
 
21
24
 
22
25
  class Executor:
23
26
  """Defines common functionality between executors."""
24
27
 
28
+ @tracer.start_as_current_span('api.execute_batch')
25
29
  def execute_batch(
26
30
  self,
27
31
  batch: dict[str, str],
@@ -38,17 +42,28 @@ class Executor:
38
42
  Returns:
39
43
  Results of execution.
40
44
  """
41
- results = []
42
- with futures.ThreadPoolExecutor(max_workers=parallel_threshold) as executor:
43
- future_to_query = {
44
- executor.submit(
45
- self.execute,
46
- query,
47
- title,
48
- context,
49
- ): query
50
- for title, query in batch.items()
51
- }
52
- for future in futures.as_completed(future_to_query):
53
- results.append(future.result())
54
- return results
45
+ span = trace.get_current_span()
46
+ span.set_attribute('api.parallel_threshold', parallel_threshold)
47
+ return asyncio.run(
48
+ self._run(
49
+ batch=batch, context=context, parallel_threshold=parallel_threshold
50
+ )
51
+ )
52
+
53
+ async def _run(
54
+ self,
55
+ batch: dict[str, str],
56
+ context: execution_context.ExecutionContext,
57
+ parallel_threshold: int,
58
+ ):
59
+ semaphore = asyncio.Semaphore(value=parallel_threshold)
60
+
61
+ async def run_with_semaphore(fn):
62
+ async with semaphore:
63
+ return await fn
64
+
65
+ tasks = [
66
+ self.aexecute(query=query, title=title, context=context)
67
+ for title, query in batch.items()
68
+ ]
69
+ return await asyncio.gather(*(run_with_semaphore(task) for task in tasks))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: garf-executors
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Executes queries against API and writes data to local/remote storage.
5
5
  Author-email: "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>, Andrei Markin <andrey.markin.ppc@gmail.com>
6
6
  License: Apache 2.0
File without changes
File without changes