Skip to content

Commit

Permalink
Add version as tag to internal metrics. (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
keep94 authored Sep 16, 2022
1 parent 5ce2efc commit e982323
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name: Linters & Tests

on:
push:
branches: [ master ]
pull_request:
types:
- opened
- reopened
branches: [ master ]
workflow_call:
inputs:
env_yml:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setuptools.setup(
name='wavefront-sdk-python',
version='1.8.11', # The version number. Update with each pull request.
version='1.8.12', # The version number. Update with each pull request.
author='Wavefront by VMware',
url='https://github.com/wavefrontHQ/wavefront-sdk-python',
license='Apache-2.0',
Expand Down
17 changes: 17 additions & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import requests

from wavefront_sdk.client import WavefrontClient
from wavefront_sdk.common.metrics import registry
from wavefront_sdk.entities.tracing.span_log import SpanLog


Expand All @@ -29,6 +30,22 @@ def setUp(self):
self._response = Mock()
self._response.status_code = 200

def test_send_version_with_internal_metrics(self):
no_registry = registry.WavefrontSdkMetricsRegistry(
wf_metric_sender=None)
with patch.object(
registry,
'WavefrontSdkMetricsRegistry',
return_value=no_registry) as mock_registry:
WavefrontClient(
'no_server',
'no_token',
flush_interval_seconds=86400,
enable_internal_metrics=True)
self.assertRegex(
mock_registry.call_args[1]['tags']['version'],
r'^(v\d+\.\d+\.\d+)|(unknown)$')

def test_send_span_with_span_logs(self):

self._sender.send_span(
Expand Down
2 changes: 2 additions & 0 deletions wavefront_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ def __init__(self, server, token, max_queue_size=50000, batch_size=10000,
ingestion_type = 'proxy'

if enable_internal_metrics:
version = utils.get_version(constants.WAVEFRONT_SDK_PYTHON)
self._sdk_metrics_registry = registry.WavefrontSdkMetricsRegistry(
wf_metric_sender=self,
tags={'version': version},
prefix=f'{constants.SDK_METRIC_PREFIX}'
f'.core.sender.{ingestion_type}'
)
Expand Down
26 changes: 20 additions & 6 deletions wavefront_sdk/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,35 @@ def event_to_json(name, start_time, end_time, source, tags,
return str(json.dumps(event))


def get_sem_ver(name):
"""Return semantic version of sdk used in Wavefront reportable format.
Ex: <major>.<2-digit-minor><2-digit-patch> (1.0603 => v1.6.3)
def get_version(name):
"""Return semantic version of sdk used ex: 'v1.6.3'.
@param name: SDK Name
@type name: str
@return: Semantic version in wavefront format as String
@return: The version of this library. ex: 'v1.6.3' If version can't be
found, returns 'unknown'
"""
try:
version = pkg_resources.require(name)[0].version
return get_sem_ver_value(version)
return "v" + version
except pkg_resources.DistributionNotFound:
LOGGER.warning('Unable to get version info,'
' No distribution found for : %s', name)
return "unknown"


def get_sem_ver(name):
"""Return semantic version of sdk used in Wavefront reportable format.
Ex: <major>.<2-digit-minor><2-digit-patch> (1.0603 => v1.6.3)
@param name: SDK Name
@type name: str
@return: Semantic version in wavefront format as String. Ex: '1.0603'
"""
version = get_version(name)
if version.startswith('v'):
return get_sem_ver_value(version[1:])
return "0.0"


Expand Down

0 comments on commit e982323

Please sign in to comment.