Skip to content

Commit

Permalink
Merge branch 'add-extended-aggregation' into add_buffered_metric_object
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewqian2001datadog committed Oct 28, 2024
2 parents 8fc12f5 + 79590b0 commit 8378644
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: "Ensure labels"

permissions:
pull-requests: read

on: # yamllint disable-line rule:truthy
pull_request:
types:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: "CodeQL"

permissions:
contents: read
checks: write

on:
push:
branches: [ master ]
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
name: "Pull Request Labeler"

permissions:
contents: read
pull-requests: write

on:
- pull_request

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Build

permissions:
contents: write
pull-requests: write

on:
pull_request:
release:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Configuration for https://github.com/actions/stale

name: "Stale issues and pull requests"

permissions:
contents: write
issues: write
pull-requests: write

on:
schedule:
- cron: "0 5 * * *"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: test

permissions:
contents: read

on:
push:
branches:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Run Integration Tests

permissions:
contents: read

on: # yamllint disable-line rule:truthy
pull_request:
types:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.50.1 / 2024-09-18

* [Added] Add the ability for buffering and aggregation to work at the same time. See [#851](https://github.com/DataDog/datadogpy/pull/851).

## v0.50.0 / 2024-08-20

* [Added] Add client side aggregation. See [#844](https://github.com/DataDog/datadogpy/pull/844).
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This project does not have a strict release schedule. However, we would make a r
Our team will trigger the release pipeline.

### Prerequisite
- Install [datadog_checks_dev](https://datadog-checks-base.readthedocs.io/en/latest/datadog_checks_dev.cli.html#installation) using Python 3.
- Install [datadog_checks_dev](https://datadoghq.dev/integrations-core/setup/#ddev) using Python 3.
- Setup PyPI, see the internal documentation for more details

### Update Changelog and version
Expand Down
24 changes: 24 additions & 0 deletions datadog/dogstatsd/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
GaugeMetric,
SetMetric,
)
from datadog.dogstatsd.buffered_metrics import (
HistogramMetric,
DistributionMetric,
TimingMetric
)
from datadog.dogstatsd.metric_types import MetricType


Expand All @@ -14,10 +19,18 @@ def __init__(self):
MetricType.GAUGE: {},
MetricType.SET: {},
}
self.buffered_metrics_map = {
MetricType.HISTOGRAM: {},
MetricType.DISTRIBUTION: {},
MetricType.TIMING: {}
}
self._locks = {
MetricType.COUNT: threading.RLock(),
MetricType.GAUGE: threading.RLock(),
MetricType.SET: threading.RLock(),
MetricType.HISTOGRAM: threading.RLock(),
MetricType.DISTRIBUTION: threading.RLock(),
MetricType.TIMING: threading.RLock()
}

def flush_aggregated_metrics(self):
Expand All @@ -30,6 +43,16 @@ def flush_aggregated_metrics(self):
metrics.extend(metric.get_data() if isinstance(metric, SetMetric) else [metric])
return metrics

def flush_aggregated_buffered_metrics(self):
metrics = []
for metric_type in self.buffered_metrics_map.keys():
with self._locks[metric_type]:
current_metrics = self.buffered_metrics_map[metric_type]
self.buffered_metrics_map[metric_type] = {}
for metric in current_metrics.values():
metrics.append(metric)
return metrics

def get_context(self, name, tags):
tags_str = ",".join(tags) if tags is not None else ""
return "{}:{}".format(name, tags_str)
Expand Down Expand Up @@ -60,3 +83,4 @@ def add_metric(
self.metrics_map[metric_type][context] = metric_class(
name, value, tags, rate, timestamp
)

2 changes: 1 addition & 1 deletion datadog/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.50.1.dev"
__version__ = "0.50.2.dev"

0 comments on commit 8378644

Please sign in to comment.