mendhak / teamcity-graphite

Teamcity plugin which sends various build, code and test metrics to Graphite.
http://code.mendhak.com/teamcity-graphite/
10 stars 3 forks source link

Each buildStepRUNNER metrics is sent twice; the first time with value 0 #10

Closed sferencik closed 7 years ago

sferencik commented 8 years ago

Each buildStepRUNNER metrics is sent twice; the first time with value 0.

This is shown in the following sequence:

[2016-10-05 09:49:54,616] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:sourcesUpdate : 3822.0
[2016-10-05 09:49:54,616] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:firstStepPreparation : 64.0
[2016-10-05 09:49:54,616] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:buildStepRUNNER_11 : 0.0
[2016-10-05 09:49:55,716] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:buildStepRUNNER_11 : 95.0
[2016-10-05 09:49:55,716] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:buildStepRUNNER_38 : 0.0
...
[2016-10-05 09:52:53,860] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:buildStepRUNNER_38 : 179302.0
[2016-10-05 09:52:54,060] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:buildFinishing : 32.0
[2016-10-05 09:52:54,060] console                           [Info] TEAMCITY-GRAPHITE::: buildStageDuration:artifactsPublishing : 122.0

This is confirmed by debugging into the BuildStatusListener: for each build runner, the statisticValuePublished() method is invoked twice: as the build starts, with value 0.0, and as the build finishes, with the actual run-time value.

This is a problem in the resultant Graphite stats. The count of runs (per build runner) is doubled, and the average runtimes are halved.

sferencik commented 8 years ago

I've raised an issue with JetBrains: TW-47322.

sferencik commented 8 years ago

JetBrains have explained they can't stop sending the 0s but they guarantee they won't send a 0 for the build step completion. If a step managed to complete in under 1 ms, they'd artificially send 1.

In that sense, I propose to change the plugin to ignore the buildStepRUNNER_* events with value 0.

mendhak commented 8 years ago

Sorry for the silence. Is this change something you can do, I think it should be safe to outright ignore any metric value that's 0.

sferencik commented 8 years ago

Yes, my colleague or I will send a pull request.

We can ignore all the time/duration metrics with zero value, but not all the metrics in general. Some metrics (test count, artifact size, success rate, passed test cout) can have legitimate zero values.

For the record, the different metric keys are listed in this TeamCity docu page (see the table at the bottom) and this StackOverflow response gives some example values, which do indeed show valid zero values.

BTW, the plugin's statisticValuePublished() method already recognises time/duration metrics so we can make use of that categorisation.