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 support for Delta temporality #2505

Merged
merged 16 commits into from
Jul 13, 2023
Merged

Add support for Delta temporality #2505

merged 16 commits into from
Jul 13, 2023

Conversation

srikanthccv
Copy link
Member

@srikanthccv srikanthccv commented Mar 25, 2023

Fixes #2405
Fixes #1707

Enable using --prefer-delta CLI flag.

The delta temporality is low on memory, and programs with strict memory constraints use delta.

Corresponding collector PR SigNoz/signoz-otel-collector#121

Let's look at the example data for a metric http_requests_count with different temporalities.

Assume

  • Collection is done every 5s
  • Two counter measurements, one for each kind, are recorded in the same application
t v(cumulative) v(delta)
12.00 0 0
12.05 12 12
12.10 14 2
12.15 16 2
12.20 22 6
12.25 25 3
12.30 32 7
12.35 37 5
12.40 45 8
12.45 49 4
12.50 59 10
12.55 66 7

The request rate with a step interval of '15's

t v(cumulative) v(delta)
12.00 (0, 12, 14) (0, 12, 2)
12.15 (16, 22, 25) (2, 6, 3)
12.30 (32, 37, 45) (7, 5, 8)
12.45 (49, 59, 66) (4, 10, 7)

For the cumulative temporality, we take the highest value at the timestamp and calculate the running difference of the value
and for delta it will be sum of the values in the step interval group.

t v(cumulative) v(delta)
12.00 (14-0)/15 ~= 0.93 (0+12+2)/15 ~= 0.93
12.15 (25-14)/15 ~= 0.73 (2+6+3)/15 ~= 0.73
12.30 (45-25)/15 ~= 1.33 (7+5+8)/15 ~= 1.33
12.45 (66-45)/15 ~= 1.4 (4+10+7)/15 ~= 1.4

Use the following script to generate the above equivalent data.

app.py
import time
import random

from opentelemetry.metrics import get_meter_provider, set_meter_provider
from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry.sdk.metrics.export import (
    AggregationTemporality,
    PeriodicExportingMetricReader,
)
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter

temporality_cumulative = {Counter: AggregationTemporality.CUMULATIVE}
temporality_delta = {Counter: AggregationTemporality.DELTA}

# The metrics that are exported using this exporter will represent a cumulative value
exporter = OTLPMetricExporter(
    preferred_temporality=temporality_cumulative,
)

# The metrics that are exported using this exporter will represent a delta value
exporter2 = OTLPMetricExporter(
    preferred_temporality=temporality_delta,
)

# The PeriodicExportingMetricReader takes the preferred aggregation
# from the passed in exporter
reader = PeriodicExportingMetricReader(
    exporter,
    export_interval_millis=5_000,
)

# The PeriodicExportingMetricReader takes the preferred aggregation
# from the passed in exporter
reader2 = PeriodicExportingMetricReader(
    exporter2,
    export_interval_millis=5_000,
)

provider1 = MeterProvider(metric_readers=[reader])

meter1 = provider1.get_meter("preferred-temporality", "0.1.2")

counter_cumulative = meter1.create_counter("my-counter-cumulative")

provider2 = MeterProvider(metric_readers=[reader2])

meter2 = provider2.get_meter("preferred-temporality", "0.1.2")

counter_delta = meter2.create_counter("my-counter-delta")

indian_cities = ["Mumbai", "Delhi", "Bangalore", "Hyderabad", "Ahmedabad"]
american_cities = ["New York", "Los Angeles", "Chicago", "Houston", "Philadelphia"]

while True:
    labels = {"indian_city": random.choice(indian_cities), "american_city": random.choice(american_cities)}
    count = random.randint(1, 100)
    counter_cumulative.add(count, labels)
    counter_delta.add(count, labels)
    time.sleep(1)
requirements.txt
backoff==2.2.1
certifi==2022.12.7
charset-normalizer==3.1.0
Deprecated==1.2.13
googleapis-common-protos==1.58.0
grpcio==1.51.3
idna==3.4
opentelemetry-api==1.16.0
opentelemetry-distro==0.37b0
opentelemetry-exporter-otlp==1.16.0
opentelemetry-exporter-otlp-proto-grpc==1.16.0
opentelemetry-exporter-otlp-proto-http==1.16.0
opentelemetry-instrumentation==0.37b0
opentelemetry-proto==1.16.0
opentelemetry-sdk==1.16.0
opentelemetry-semantic-conventions==0.37b0
protobuf==4.22.1
requests==2.28.2
typing_extensions==4.5.0
urllib3==1.26.15
wrapt==1.15.0

Run the program for some time and try charting the SUM_RATE for both metrics.

@SigNoz SigNoz deleted a comment from github-actions bot Jul 10, 2023
@SigNoz SigNoz deleted a comment from sonarcloud bot Jul 10, 2023
@SigNoz SigNoz deleted a comment from github-advanced-security bot Jul 10, 2023
@SigNoz SigNoz deleted a comment from CLAassistant Jul 10, 2023
@srikanthccv srikanthccv changed the title Delta temporality preview Add support for Delta temporality Jul 10, 2023
@srikanthccv srikanthccv marked this pull request as ready for review July 10, 2023 17:35
ankitnayan
ankitnayan previously approved these changes Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signoz Otel Collect Issue Can't find counter metrics in dashboard
2 participants