Skip to content

Commit b488e67

Browse files
[exporters] fix: allow source parameter propagation during fetching
1 parent 3b88a63 commit b488e67

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

libs/exporters/garf_exporter/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
"""Prometheus exporter for garf."""
1415

1516
from garf_exporter.exporter import GarfExporter
1617

1718
__all__ = [
1819
'GarfExporter',
1920
]
2021

21-
__version__ = '0.0.1'
22+
__version__ = '0.0.2'

libs/exporters/garf_exporter/collector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Collectors serves as a wrapper on top garf query."""
1516

1617
import os
1718
import pathlib

libs/exporters/garf_exporter/exporter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def export(
126126
labelnames=('collector',),
127127
namespace=namespace,
128128
)
129-
api_requests_counter = self._define_counter(name='api_requests_count')
129+
api_requests_counter = self._define_counter(
130+
namespace=namespace, name='api_requests_count'
131+
)
130132
metrics = self._define_metrics(
131133
report.query_specification, suffix, namespace
132134
)
@@ -245,16 +247,19 @@ def _define_gauge(
245247
registry=self.registry,
246248
)
247249

248-
def _define_counter(self, name: str) -> prometheus_client.Counter:
250+
def _define_counter(
251+
self, namespace: str, name: str
252+
) -> prometheus_client.Counter:
249253
"""Define Counter metric based on provided name.
250254
251255
Args:
256+
namespace: Global prefix for all Prometheus metrics.
252257
name: Name of the metric to be exposed to Prometheus (without prefix).
253258
254259
Returns:
255260
An instance of Counter that associated with registry.
256261
"""
257-
counter_name = f'garf_core_{name}'
262+
counter_name = f'{namespace}_{name}'
258263
if counter_name in self.registry._names_to_collectors:
259264
return self.registry._names_to_collectors.get(counter_name)
260265
return prometheus_client.Counter(

libs/exporters/garf_exporter/exporter_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def generate_metrics(
130130
for col in collectors:
131131
logging.info('Exporting from collector: %s', col.title)
132132
start = time()
133-
report = self.fetcher.fetch(col.query)
133+
report = self.fetcher.fetch(col.query, **self.source_parameters)
134134
end = time()
135135
exporter.report_fetcher_gauge.labels(collector=col.title).set(end - start)
136136
exporter.export(

0 commit comments

Comments
 (0)