Skip to content

Commit

Permalink
Nightly page: Add the most bug number filed for a top crash (treshold…
Browse files Browse the repository at this point in the history
… is 10 crashes for the day's nightlies)
  • Loading branch information
pascalchevrel committed Dec 6, 2023
1 parent b33f536 commit d372779
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
34 changes: 34 additions & 0 deletions app/classes/ReleaseInsights/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ public static function getCrashesForBuildID(int $buildid): array
return self::arrayFromJson($data);
}

/**
* Get the list of bugs for a Build ID from Socorro
*
* @param string $signature Crash signature
* @return array<mixed> a list of crashes
*/
public static function getBugsforCrashSignature(string $signature): array
{
// The signature in the string varies so we create a unique file name in cache
$cache_id = 'https://crash-stats.mozilla.org/api/Bugs/?signatures=' . $signature;

if (defined('TESTING_CONTEXT')) {
if ($signature == 'failure') {
$cache_id = TEST_FILES .'/empty.json';
} else {
$cache_id = TEST_FILES .'/crash-stats.mozilla.org_signature.json';
}
}

// If we can't retrieve cached data, we create and cache it.
// We cache because we want to avoid http request latency
if (! $data = Cache::getKey($cache_id, 30)) {
$data = file_get_contents($cache_id);

// No data returned, bug or incorrect date, don't cache.
if (empty($data)) {
return [];
}
Cache::setKey($cache_id, $data);
}

return self::arrayFromJson($data);
}

/**
* Return an Array from a Json string
* This is an utility function as we use json_decode in multiple places,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$nightly_pairs,
$build_crashes,
$top_sigs,
$crash_bugs,
$bug_list,
$bug_list_karma,
$previous_date,
Expand All @@ -26,6 +27,7 @@
'nightly_pairs' => $nightly_pairs,
'build_crashes' => $build_crashes,
'top_sigs' => $top_sigs,
'crash_bugs' => $crash_bugs,
'bug_list' => $bug_list,
'bug_list_karma' => $bug_list_karma,
'previous_date' => $previous_date,
Expand Down
39 changes: 39 additions & 0 deletions app/models/nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,50 @@
'OOM | small',
];

// $top_signatures_only = array_column(array_values($top_sigs), 'term');
$top_sigs_worth_a_bug = [];
foreach ($top_sigs as $k => $values) {
foreach ($values as $target) {
if (in_array($target['term'] , $known_top_crashes)) {
continue;
}
if (isset($top_sigs_worth_a_bug[$target['term']])){
$top_sigs_worth_a_bug[$target['term']] += $target['count'];
} else {
$top_sigs_worth_a_bug[$target['term']] = $target['count'];
}
}
}
// We take 10 crashes for a day as a treshold
$top_sigs_worth_a_bug = array_filter($top_sigs_worth_a_bug, fn($n) => $n > 10);

// We escape weird crash signature characters for url use
$top_sigs_worth_a_bug = array_keys($top_sigs_worth_a_bug);
$top_sigs_worth_a_bug = array_map('urlencode', $top_sigs_worth_a_bug);

// dd($top_sigs_worth_a_bug);
// Query bugs for signatures
$crash_bugs = [];
if (! empty($top_sigs_worth_a_bug)) {
foreach ($top_sigs_worth_a_bug as $sig) {
$bugs_for_top_sigs = Utils::getBugsforCrashSignature($sig)['hits'];
$tmp = array_column($bugs_for_top_sigs, 'id');
if (!empty($tmp)) {
$crash_bugs[urldecode($sig)] = max(
array_unique(
array_column($bugs_for_top_sigs, 'id')
)
);
}
}
}
// dd($crash_bugs);
return [
$display_date,
$nightly_pairs,
$build_crashes,
$top_sigs,
$crash_bugs,
$bug_list,
$bug_list_karma,
$previous_date,
Expand Down
14 changes: 11 additions & 3 deletions app/views/templates/nightly.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
</tbody>
</table>
</div>

<ol>

{%for sig in top_sigs[dataset.buildid] %}
{% if sig.term in known_top_crashes %}
{% set button, alert ='btn btn-info btn-sm', 'Known top crash' %}
Expand All @@ -108,8 +108,16 @@
{% else %}
{% set button, alert = '', '' %}
{% endif %}
<li>
<a href="https://crash-stats.mozilla.org/signature/?signature={{ sig.term }}" title="Go to Crash Stats"><img src="/assets/img/socorro.png" width="16" height="16" alt=""/></a> <a href="https://crash-stop-addon.herokuapp.com/sumup.html?s={{ sig.term }}">{{ sig.term }}</a> <b title="{{ sig.count }}">({{ ((sig.count/build_crashes[dataset.buildid])*100)|number_format(2) }}%)</b> <span class="{{ button }}">{{ alert }}</span>

{% if sig.term in crash_bugs|keys %}
{% set crash_bug_button, crash_bug_link = 'btn btn-success btn-sm', '<a class="text-light" href="https://bugzilla.mozilla.org/' ~ crash_bugs[sig.term] ~ '">' ~ crash_bugs[sig.term] ~ '</a>' %}
{% else %}
{% set crash_bug_button, crash_bug_link = '', '' %}
{% endif %}


<li class="mb-1">
<a href="https://crash-stats.mozilla.org/signature/?signature={{ sig.term }}" title="Go to Crash Stats"><img src="/assets/img/socorro.png" width="16" height="16" alt=""/></a> <a class="text-info" href="https://crash-stop-addon.herokuapp.com/sumup.html?s={{ sig.term }}">{{ sig.term }}</a> <b title="{{ sig.count }}">({{ ((sig.count/build_crashes[dataset.buildid])*100)|number_format(2) }}%)</b> <span class="{{ button }}">{{ alert }}</span> <span class="{{ crash_bug_button }}">{{ crash_bug_link|raw }}</span>
</li>
{% endfor %}
</ol>
Expand Down
1 change: 1 addition & 0 deletions tests/Files/crash-stats.mozilla.org_signature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hits": [{"id": 1195531, "signature": "mozilla::layers::LockD3DTexture<T>"}, {"id": 1239188, "signature": "CrashStatsLogForwarder::CrashAction"}, {"id": 1239188, "signature": "mozilla::layers::LockD3DTexture<T>"}, {"id": 1362366, "signature": "mozilla::layers::LockD3DTexture<T>"}, {"id": 1658991, "signature": "mozilla::layers::LockD3DTexture<T>"}, {"id": 1704445, "signature": "mozilla::layers::LockD3DTexture<T>"}, {"id": 1709600, "signature": "mozilla::layers::LockD3DTexture<T>"}, {"id": 1709603, "signature": "mozilla::layers::LockD3DTexture<T>"}], "total": 8}
11 changes: 10 additions & 1 deletion tests/Unit/ReleaseInsights/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@
expect(U::getCrashesForBuildID(20200927094817))->toBeArray()->not->toBeEmpty();
});

test('Utils::getBugsforCrashSignature', function () {
expect(U::getBugsforCrashSignature('failure'))
->toBeArray()
->toBeEmpty();
expect(U::getBugsforCrashSignature('some signature'))
->toBeArray()
->not->toBeEmpty();
});

test('Utils::getIP', function () {
expect(U::getIP())->toBeNull();

Expand Down Expand Up @@ -189,4 +198,4 @@
test('Utils::isJson', function () {
$this->assertFalse(U::isJson('1'));
$this->assertFalse(U::isJson('[1:]'));
});
});

0 comments on commit d372779

Please sign in to comment.