• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash-client-python / 10096417506

25 Jul 2024 02:53PM UTC coverage: 97.05% (+0.007%) from 97.043%
10096417506

Pull #317

github

pre-commit-ci[bot]
[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
Pull Request #317: feat: add metrics metadata

5 of 5 new or added lines in 2 files covered. (100.0%)

921 of 949 relevant lines covered (97.05%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.56
/UnleashClient/utils.py
1
import logging
1✔
2
from enum import Enum
1✔
3
from threading import RLock
1✔
4
from typing import Any
1✔
5

6
import mmh3  # pylint: disable=import-error
1✔
7
from requests import Response
1✔
8

9
LOGGER = logging.getLogger("UnleashClient")
1✔
10

11

12
class InstanceAllowType(Enum):
1✔
13
    BLOCK = 1
1✔
14
    WARN = 2
1✔
15
    SILENTLY_ALLOW = 3
1✔
16

17

18
class InstanceCounter:
1✔
19
    def __init__(self):
1✔
20
        self.instances = {}
1✔
21
        self.lock = RLock()
1✔
22

23
    def __contains__(self, key):
1✔
24
        with self.lock:
1✔
25
            return key in self.instances
1✔
26

27
    def _reset(self):
1✔
28
        self.instances = {}
1✔
29

30
    def count(self, key):
1✔
31
        with self.lock:
1✔
32
            return self.instances.get(key) or 0
1✔
33

34
    def increment(self, key):
1✔
35
        with self.lock:
1✔
36
            if key in self:
1✔
37
                self.instances[key] += 1
1✔
38
            else:
39
                self.instances[key] = 1
1✔
40

41

42
def normalized_hash(
1✔
43
    identifier: str, activation_group: str, normalizer: int = 100, seed: int = 0
44
) -> int:
45
    return (
1✔
46
        mmh3.hash(f"{activation_group}:{identifier}", signed=False, seed=seed)
47
        % normalizer
48
        + 1
49
    )
50

51

52
def get_identifier(context_key_name: str, context: dict) -> Any:
1✔
53
    if context_key_name in context.keys():
1✔
54
        value = context[context_key_name]
1✔
55
    elif (
1✔
56
        "properties" in context.keys()
57
        and context_key_name in context["properties"].keys()
58
    ):
59
        value = context["properties"][context_key_name]
×
60
    else:
61
        value = None
1✔
62

63
    return value
1✔
64

65

66
def log_resp_info(resp: Response) -> None:
1✔
67
    LOGGER.debug("HTTP status code: %s", resp.status_code)
1✔
68
    LOGGER.debug("HTTP headers: %s", resp.headers)
1✔
69
    LOGGER.debug("HTTP content: %s", resp.text)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc