Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set functionality #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion aiodogstatsd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ def gauge(
"""
self._report(name, typedefs.MType.GAUGE, value, tags, sample_rate)

def set(
self,
name: typedefs.MName,
*,
value: typedefs.MDisplayValue,
tags: Optional[typedefs.MTags] = None,
sample_rate: Optional[typedefs.MSampleRate] = None,
) -> None:
"""
Add a value to a set, optionally setting tags and a sample rate.
"""
self._report(name, typedefs.MType.SET, value, tags, sample_rate)

def increment(
self,
name: typedefs.MName,
Expand Down Expand Up @@ -221,7 +234,7 @@ def _report(
self,
name: typedefs.MName,
type_: typedefs.MType,
value: typedefs.MValue,
value: typedefs.MDisplayValue,
tags: Optional[typedefs.MTags] = None,
sample_rate: Optional[typedefs.MSampleRate] = None,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion aiodogstatsd/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def build(
*,
name: typedefs.MName,
namespace: Optional[typedefs.MNamespace],
value: typedefs.MValue,
value: typedefs.MDisplayValue,
type_: typedefs.MType,
tags: typedefs.MTags,
sample_rate: typedefs.MSampleRate,
Expand Down
3 changes: 3 additions & 0 deletions aiodogstatsd/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"MName",
"MNamespace",
"MType",
"MDisplayValue",
"MValue",
"MSampleRate",
"MTagKey",
Expand All @@ -16,6 +17,7 @@

MName = str
MNamespace = str
MDisplayValue = Union[float, int, str]
MValue = Union[float, int]
MSampleRate = Union[float, int]

Expand All @@ -31,6 +33,7 @@ class MType(enum.Enum):
GAUGE = "g"
HISTOGRAM = "h"
TIMING = "ms"
SET = "s"


@enum.unique
Expand Down
9 changes: 9 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ async def test_gauge(self, statsd_client, statsd_server, wait_for):

assert collected == [b"test_gauge:42|g|#whoami:batman,and:robin"]

async def test_set(self, statsd_client, statsd_server, wait_for):
udp_server, collected = statsd_server

async with udp_server:
statsd_client.set("test_set", value="hello", tags={"and": "robin"})
await wait_for(collected)

assert collected == [b"test_set:hello|s|#whoami:batman,and:robin"]

async def test_increment(self, statsd_client, statsd_server, wait_for):
udp_server, collected = statsd_server

Expand Down