Skip to content

Commit

Permalink
feat: add optional dependency tests for poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusArdelean committed Feb 22, 2024
1 parent 7ba21cb commit 7970c8b
Show file tree
Hide file tree
Showing 27 changed files with 4,164 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/system/inspect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,25 @@ describe('inspect', () => {

expect(result.dependencyGraph.equals(expected)).toBeTruthy();
});

it('should return expected dependencies for poetry-optional-dependencies', async () => {
const workspace = 'poetry-app-optional-dependencies';
testUtils.chdirWorkspaces(workspace);

const result = await inspect('.', FILENAMES.poetry.lockfile);

const expected = [
{
pkg: {
name: 'opentelemetry-distro',
version: '0.35b0',
},
directDeps: ['opentelemetry-distro'],
},
];

compareTransitiveLines(result.dependencyGraph, expected);
});
});

it('should return correct target file for poetry project when relative path to poetry lock file is passed', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python

from . import core
from . import exposition
from . import gc_collector
from . import platform_collector
from . import process_collector
from . import registry
from . import metrics_core
from . import metrics

__all__ = ['Counter', 'Gauge', 'Summary', 'Histogram', 'Info', 'Enum']

CollectorRegistry = registry.CollectorRegistry
REGISTRY = registry.REGISTRY
Metric = metrics_core.Metric
Counter = metrics.Counter
Gauge = metrics.Gauge
Summary = metrics.Summary
Histogram = metrics.Histogram
Info = metrics.Info
Enum = metrics.Enum

CONTENT_TYPE_LATEST = exposition.CONTENT_TYPE_LATEST
generate_latest = exposition.generate_latest
MetricsHandler = exposition.MetricsHandler
make_wsgi_app = exposition.make_wsgi_app
start_http_server = exposition.start_http_server
start_wsgi_server = exposition.start_wsgi_server
write_to_textfile = exposition.write_to_textfile
push_to_gateway = exposition.push_to_gateway
pushadd_to_gateway = exposition.pushadd_to_gateway
delete_from_gateway = exposition.delete_from_gateway
instance_ip_grouping_key = exposition.instance_ip_grouping_key

ProcessCollector = process_collector.ProcessCollector
PROCESS_COLLECTOR = process_collector.PROCESS_COLLECTOR

PlatformCollector = platform_collector.PlatformCollector
PLATFORM_COLLECTOR = platform_collector.PLATFORM_COLLECTOR

GCCollector = gc_collector.GCCollector
GC_COLLECTOR = gc_collector.GC_COLLECTOR

if __name__ == '__main__':
c = Counter('cc', 'A counter')
c.inc()

g = Gauge('gg', 'A gauge')
g.set(17)

s = Summary('ss', 'A summary', ['a', 'b'])
s.labels('c', 'd').observe(17)

h = Histogram('hh', 'A histogram')
h.observe(.6)

start_http_server(8000)
import time
while True:
time.sleep(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python
from __future__ import unicode_literals

import logging
import re
import socket
import threading
import time
from timeit import default_timer

from ..registry import REGISTRY

# Roughly, have to keep to what works as a file name.
# We also remove periods, so labels can be distinguished.

_INVALID_GRAPHITE_CHARS = re.compile(r"[^a-zA-Z0-9_-]")


def _sanitize(s):
return _INVALID_GRAPHITE_CHARS.sub('_', s)


class _RegularPush(threading.Thread):
def __init__(self, pusher, interval, prefix):
super(_RegularPush, self).__init__()
self._pusher = pusher
self._interval = interval
self._prefix = prefix

def run(self):
wait_until = default_timer()
while True:
while True:
now = default_timer()
if now >= wait_until:
# May need to skip some pushes.
while wait_until < now:
wait_until += self._interval
break
# time.sleep can return early.
time.sleep(wait_until - now)
try:
self._pusher.push(prefix=self._prefix)
except IOError:
logging.exception("Push failed")


class GraphiteBridge(object):
def __init__(self, address, registry=REGISTRY, timeout_seconds=30, _timer=time.time):
self._address = address
self._registry = registry
self._timeout = timeout_seconds
self._timer = _timer

def push(self, prefix=''):
now = int(self._timer())
output = []

prefixstr = ''
if prefix:
prefixstr = prefix + '.'

for metric in self._registry.collect():
for s in metric.samples:
if s.labels:
labelstr = '.' + '.'.join(
['{0}.{1}'.format(
_sanitize(k), _sanitize(v))
for k, v in sorted(s.labels.items())])
else:
labelstr = ''
output.append('{0}{1}{2} {3} {4}\n'.format(
prefixstr, _sanitize(s.name), labelstr, float(s.value), now))

conn = socket.create_connection(self._address, self._timeout)
conn.sendall(''.join(output).encode('ascii'))
conn.close()

def start(self, interval=60.0, prefix=''):
t = _RegularPush(self, interval, prefix)
t.daemon = True
t.start()
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from __future__ import unicode_literals

from timeit import default_timer

from .decorator import decorate


class ExceptionCounter(object):
def __init__(self, counter, exception):
self._counter = counter
self._exception = exception

def __enter__(self):
pass

def __exit__(self, typ, value, traceback):
if isinstance(value, self._exception):
self._counter.inc()

def __call__(self, f):
def wrapped(func, *args, **kwargs):
with self:
return func(*args, **kwargs)

return decorate(f, wrapped)


class InprogressTracker(object):
def __init__(self, gauge):
self._gauge = gauge

def __enter__(self):
self._gauge.inc()

def __exit__(self, typ, value, traceback):
self._gauge.dec()

def __call__(self, f):
def wrapped(func, *args, **kwargs):
with self:
return func(*args, **kwargs)

return decorate(f, wrapped)


class Timer(object):
def __init__(self, callback):
self._callback = callback

def _new_timer(self):
return self.__class__(self._callback)

def __enter__(self):
self._start = default_timer()

def __exit__(self, typ, value, traceback):
# Time can go backwards.
duration = max(default_timer() - self._start, 0)
self._callback(duration)

def __call__(self, f):
def wrapped(func, *args, **kwargs):
# Obtaining new instance of timer every time
# ensures thread safety and reentrancy.
with self._new_timer():
return func(*args, **kwargs)

return decorate(f, wrapped)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import unicode_literals

from .metrics import Counter, Enum, Gauge, Histogram, Info, Summary
from .metrics_core import (
CounterMetricFamily, GaugeHistogramMetricFamily, GaugeMetricFamily,
HistogramMetricFamily, InfoMetricFamily, Metric, Sample,
StateSetMetricFamily, SummaryMetricFamily, UnknownMetricFamily,
UntypedMetricFamily,
)
from .registry import CollectorRegistry, REGISTRY
from .samples import Exemplar, Sample, Timestamp

__all__ = (
'CollectorRegistry',
'Counter',
'CounterMetricFamily',
'Enum',
'Exemplar',
'Gauge',
'GaugeHistogramMetricFamily',
'GaugeMetricFamily',
'Histogram',
'HistogramMetricFamily',
'Info',
'InfoMetricFamily',
'Metric',
'REGISTRY',
'Sample',
'StateSetMetricFamily',
'Summary',
'SummaryMetricFamily',
'Timestamp',
'UnknownMetricFamily',
'UntypedMetricFamily',
)
Loading

0 comments on commit 7970c8b

Please sign in to comment.