Skip to content

Add new histogram to generator - messaging system latency - #3453

Merged
joe-elliott merged 16 commits into
grafana:mainfrom
adirmatzkin:generator-messaging-system-latency
May 3, 2024
Merged

Add new histogram to generator - messaging system latency#3453
joe-elliott merged 16 commits into
grafana:mainfrom
adirmatzkin:generator-messaging-system-latency

Conversation

@adirmatzkin

@adirmatzkin adirmatzkin commented Mar 3, 2024

Copy link
Copy Markdown
Contributor

What this PR does:
This PR adds a new metric calculated by the metrics-generator service-graph processor.
The metric is a histogram for the latency between 2 services communicating through a messaging system.

Which issue(s) this PR fixes:
Fixes #3232

Screenshot 2024-03-03 18 14 48

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
@CLAassistant

CLAassistant commented Mar 3, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@adirmatzkin adirmatzkin changed the title Generator messaging system latency Mar 3, 2024
@joe-elliott

joe-elliott commented Mar 4, 2024

Copy link
Copy Markdown
Collaborator

Thanks for putting some time into this. It's a fairly small change should be a pretty easy review, but we do need this to be configurable.

We are currently trying to keep metrics generator series down and histograms tend to generate a lot of series.

I will give this more time tomorrow.

@adirmatzkin

Copy link
Copy Markdown
Contributor Author

We are currently trying to keep metrics generator series down and histograms tend to generate a lot of series.

Just pushed some changes to allow controlling the metric from config.
Not sure I did it in all the relevant places... saw it working in a specific config change I tested though.

Also, the metric is initialized even if the config is set to false... probably not the best, but it felt simpler due to the current structure of the code... Is that fine? Maybe you guys have a different idea?

@joe-elliott joe-elliott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few questions, but looking good!

also, we will need a changelog

Comment thread modules/generator/overrides.go

func unixNanosDiffSec(unixNanoStart uint64, unixNanoEnd uint64) float64 {
// handling potential underflow of unit64s substraction
diff := int64(unixNanoEnd) - int64(unixNanoStart)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of casting we could check to see if diff > end for overflow. is that better?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, we recently made a change to protect span metrics from negative latencies:

https://github.com/grafana/tempo/pull/3412/files

@mdisibio should we make sure the same protections are here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of casting we could check to see if diff > end for overflow. is that better?

I agree we can make it cleaner,
Really liked your idea, very clever 🙃 My only concern about it is how clear it will be. After making the check if diff > end, if underflow did happen, meaning the subtraction yields a negative number - don't we want to return it?

If not, maybe we could make this function a bit more specific and move the negative values "protection" into it.. and then.. return 0?
It could also be that simple:

func unixNanosDiffSec(unixNanoStart uint64, unixNanoEnd uint64) float64 {
	if unixNanoStart > unixNanoEnd {
		// To prevent underflow, return 0.
		return 0
	}
	// Safe subtraction.
	return float64(unixNanoEnd-unixNanoStart) / 1e9
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's follow suit with the linked PR for consistency and return 0.

i think your suggested unixNanosDiffSec in this PR is perfect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this one is resolved? 🤔

Comment thread modules/generator/processor/servicegraphs/servicegraphs.go

@adirmatzkin adirmatzkin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to changelog.
Will update docs after making a decision about the "negative diffs"


func unixNanosDiffSec(unixNanoStart uint64, unixNanoEnd uint64) float64 {
// handling potential underflow of unit64s substraction
diff := int64(unixNanoEnd) - int64(unixNanoStart)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of casting we could check to see if diff > end for overflow. is that better?

I agree we can make it cleaner,
Really liked your idea, very clever 🙃 My only concern about it is how clear it will be. After making the check if diff > end, if underflow did happen, meaning the subtraction yields a negative number - don't we want to return it?

If not, maybe we could make this function a bit more specific and move the negative values "protection" into it.. and then.. return 0?
It could also be that simple:

func unixNanosDiffSec(unixNanoStart uint64, unixNanoEnd uint64) float64 {
	if unixNanoStart > unixNanoEnd {
		// To prevent underflow, return 0.
		return 0
	}
	// Safe subtraction.
	return float64(unixNanoEnd-unixNanoStart) / 1e9
}
@joe-elliott

Copy link
Copy Markdown
Collaborator

Thanks for the work. This is looking good.

heads up you will need this commit in your branch (merge or rebase) to get CI to pass:

7540d57

@adirmatzkin

Copy link
Copy Markdown
Contributor Author

heads up you will need this commit in your branch (merge or rebase) to get CI to pass:

Synced from upstream + added docs.
@joe-elliott anything else needed? 🙃

@joe-elliott joe-elliott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just have a few small thoughts.

Also, what do you think about adding the ConnectionType to the expired edge metric? If someone is wanting to do service graph metrics through queues I'm concerned it will create a lot of expired edges. It might be nice for an operator to know if their expired edges are largely queues or synchronous calls.

Comment thread docs/sources/tempo/configuration/_index.md
Comment thread docs/sources/tempo/metrics-generator/service_graphs/_index.md
Comment thread modules/generator/processor/servicegraphs/servicegraphs.go
Comment thread modules/generator/processor/servicegraphs/servicegraphs.go
Comment thread modules/generator/processor/servicegraphs/servicegraphs.go Outdated
Comment thread docs/sources/tempo/metrics-generator/service_graphs/estimate-cardinality.md Outdated
adirmatzkin and others added 4 commits April 25, 2024 18:57
…ardinality.md

use present when possible

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>
@adirmatzkin
adirmatzkin force-pushed the generator-messaging-system-latency branch from 0b29823 to 7121ecb Compare April 25, 2024 16:12

@adirmatzkin adirmatzkin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge this one? @joe-elliott
Just rebased 🙃

Comment thread modules/generator/processor/servicegraphs/servicegraphs.go
@knylander-grafana

Copy link
Copy Markdown
Contributor

Thank you for updating the docs

@adirmatzkin

Copy link
Copy Markdown
Contributor Author

@joe-elliott I think we're ready 🥳

@joe-elliott

Copy link
Copy Markdown
Collaborator

running CI!

@joe-elliott

Copy link
Copy Markdown
Collaborator

Thanks, Adir!

@joe-elliott
joe-elliott merged commit 35aa72e into grafana:main May 3, 2024
joe-elliott pushed a commit to joe-elliott/tempo that referenced this pull request May 7, 2024
* introduce new service-graph metric for messaging-system latency

* added tests for new histogram values

* fix linting

* make new metric optional via config

* fix typo

* fix failing tests

* add feature to changelog

* negative times diff consistency - return 0 instead of negative

* update docs

* Update docs/sources/tempo/metrics-generator/service_graphs/estimate-cardinality.md

use present when possible

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>

* change 1e9 to time const

* added a reference to the "wait" config of the processor

* fixed indentations and formatting stuff from rebasing

* removed mistaken println found by linter

---------

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>
mattdurham pushed a commit to mattdurham/tempo that referenced this pull request Jun 18, 2026
* introduce new service-graph metric for messaging-system latency

* added tests for new histogram values

* fix linting

* make new metric optional via config

* fix typo

* fix failing tests

* add feature to changelog

* negative times diff consistency - return 0 instead of negative

* update docs

* Update docs/sources/tempo/metrics-generator/service_graphs/estimate-cardinality.md

use present when possible

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>

* change 1e9 to time const

* added a reference to the "wait" config of the processor

* fixed indentations and formatting stuff from rebasing

* removed mistaken println found by linter

---------

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants