-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
184 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import re | ||
|
||
from urllib.request import unquote, urlopen | ||
from urllib.parse import urlparse | ||
from remotecv.timing import get_time, get_interval | ||
from remotecv.utils import context | ||
|
||
|
||
def load_sync(path): | ||
start_time = get_time() | ||
if not re.match(r"^https?", path): | ||
path = f"http://{path}" | ||
path = unquote(path) | ||
return urlopen(path).read() | ||
netloc = urlparse(path).netloc.replace(".", "_") | ||
response = urlopen(path) | ||
code = response.code | ||
result = response.read() | ||
|
||
context.metrics.incr("worker.original_image.response_bytes", len(result)) | ||
context.metrics.timing( | ||
f"worker.original_image.fetch.{code}.{netloc}", | ||
get_interval(start_time, get_time()), | ||
) | ||
context.metrics.incr( | ||
f"worker.original_image.fetch.{code}.{netloc}", | ||
) | ||
context.metrics.incr(f"worker.original_image.status.{code}") | ||
context.metrics.incr(f"worker.original_image.status.{code}.{netloc}") | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# thumbor imaging service | ||
# https://github.com/thumbor/thumbor/wiki | ||
|
||
# Licensed under the MIT license: | ||
# http://www.opensource.org/licenses/mit-license | ||
# Copyright (c) 2022, globo.com <thumbor@g.globo> | ||
|
||
from importlib import import_module | ||
|
||
|
||
class Importer: | ||
@classmethod | ||
def import_class(cls, class_name, conf_value): | ||
module = import_module(conf_value) | ||
return getattr(module, class_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# thumbor imaging service | ||
# https://github.com/thumbor/thumbor/wiki | ||
|
||
# Licensed under the MIT license: | ||
# http://www.opensource.org/licenses/mit-license | ||
# Copyright (c) 2022, globo.com <thumbor@g.globo> | ||
|
||
|
||
class BaseMetrics: | ||
def __init__(self, config): | ||
self.config = config | ||
|
||
def initialize(self): | ||
pass | ||
|
||
def incr(self, metricname, value=1): | ||
raise NotImplementedError() | ||
|
||
def timing(self, metricname, value): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# thumbor imaging service | ||
# https://github.com/thumbor/thumbor/wiki | ||
|
||
# Licensed under the MIT license: | ||
# http://www.opensource.org/licenses/mit-license | ||
# Copyright (c) 2022, globo.com <thumbor@g.globo> | ||
|
||
from remotecv.metrics import BaseMetrics | ||
from remotecv.utils import logger | ||
|
||
|
||
class Metrics(BaseMetrics): | ||
def incr(self, metricname, value=1): | ||
logger.debug("METRICS: inc: %s:%d", metricname, value) | ||
|
||
def timing(self, metricname, value): | ||
logger.debug("METRICS: timing: %s:%d", metricname, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# thumbor imaging service | ||
# https://github.com/thumbor/thumbor/wiki | ||
|
||
# Licensed under the MIT license: | ||
# http://www.opensource.org/licenses/mit-license | ||
# Copyright (c) 2022, globo.com <thumbor@g.globo> | ||
|
||
import time | ||
|
||
|
||
def get_time(): | ||
return time.perf_counter_ns() | ||
|
||
|
||
def get_interval(start, end): | ||
return nano_to_ms(end - start) | ||
|
||
|
||
def nano_to_ms(ns_time): | ||
return ns_time / 1e6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.