Calculate MTTR for jenkins builds

Hi

I would like to calculate MTTR for some jenkins builds. I have these fields in multiple documents:

Using Elasticsearch 8.3.0

input :

name, type [type1|type2], status [failure|success], buildDateTime

Output (something like this):

only for type=type2, some-name, duration from failure to success

What I have done to far:

  • Create a transform
    • group by terms(name)
    • group by terms(type)
    • group by terms(status)
    • aggregations mix(buildDateTime)
    • aggregations max(buildDateTime)
  • Start the transform
  • Edit the destination index in the Data Views
    • Add field
    • Set format to "Duration"
    • Set value
long d = ChronoUnit.MILLIS.between(doc['buildDateTime.min'].value, doc['buildDateTime.max'].value);

emit(d)
  • Add a lens type visualization in my dashboard and add the fields

When I look at the graph it does not look right. What am I missing?

Hi,

When I look at the graph it does not look right. What am I missing?

Unfortunately, I cannot see the graph so I can't tell if it looks right or not.

One suggestion though, might be to calculate d (duration) in the transform itself, here is how you do it:

{
  ...
  "aggregations": {
    "buildDateTime_min": {
      "min": {
        "field": "buildDateTime"
      }
    },
    "buildDateTime_max": {
      "max": {
        "field": "buildDateTime"
      }
    },
    "buildDateTime_duration": {
      "bucket_script": {
        "buckets_path": {
          "time_min": "buildDateTime_min",   
          "time_max": "buildDateTime_max"    
        },
        "script": "params.time_max - params.time_min"
      }
    }
  }
  ...
}

Then you can visualize the duration which is available in the destination index as buildDateTime_duration field.

You can read more about bucket_script pipeline aggregation here.

I think I have using the wrong way to calculate the duration. How can i model this in a transform (only for duration from FAILURE to SUCCESS?

Input:
name1, type2, 2023-1-1, FAILURE,
name1, type2, 2023-1-3, SUCCESS

Output:
name1, type2, 2 days

Input:
name1, type2, 2023-2-1, SUCCESS
name1, type2, 2023-2-2, FAILURE,
name1, type2, 2023-2-3, FAILURE,
name1, type2, 2023-2-4, FAILURE,
name1, type2, 2023-2-5, SUCCESS

Output:
name1, type2, 3 days

MTTR will then be (2+3)/2
name1, type2, 2.5 days