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

chore: flutter symbol collector CLI tool #1673

Merged
merged 48 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7bfcaf9
chore: flutter symbol collector CLI tool
vaind Oct 11, 2023
d1313bd
renames
vaind Oct 12, 2023
7a0c73e
symbol collector CLI integration
vaind Oct 12, 2023
ac1c1c0
fixup getVersion()
vaind Oct 12, 2023
7218df6
collector upload
vaind Oct 12, 2023
d394181
collect platform info with symbol archive
vaind Oct 12, 2023
5e963aa
download and extract zip archives
vaind Oct 12, 2023
c4aa8a8
download via cli bin
vaind Oct 12, 2023
a7a80ea
upload via symbol-collector cli
vaind Oct 12, 2023
667c144
add symbol collector CI
vaind Oct 13, 2023
5390bcf
extract inner zip files
vaind Oct 13, 2023
2bc4ed7
test symbol collector in CI
vaind Oct 13, 2023
ed79ef4
fix tests
vaind Oct 13, 2023
ff91b35
chore: update changelog
vaind Oct 13, 2023
795e7a4
fix tests
vaind Oct 13, 2023
816ae3e
fix tests
vaind Oct 13, 2023
5170a46
upload android symbols
vaind Oct 13, 2023
caa9b62
fix duplicate upload
vaind Oct 13, 2023
4724c81
upload symbols for all of 3.13.*
vaind Oct 24, 2023
b55becb
cache previous symbol collector successful uploads
vaind Oct 24, 2023
cb298d6
fix artifacts
vaind Oct 24, 2023
57efb36
we need to use cache
vaind Oct 24, 2023
8d686cb
cron
vaind Oct 24, 2023
bdfcfdc
test
vaind Oct 24, 2023
cee0761
use artifacts
vaind Oct 24, 2023
611f636
run for all v3 flutter versions
vaind Oct 24, 2023
321198c
fixup changelog
vaind Oct 24, 2023
6834bc8
fixup changelog
vaind Oct 25, 2023
dfb8fee
refactor: move status cache to a separate file
vaind Oct 25, 2023
deca8fc
change artifact action to download from previous runs
vaind Oct 25, 2023
12f6033
fix status cache
vaind Oct 25, 2023
0dc96c3
fix status cache
vaind Oct 25, 2023
3875129
register symbol collector CLI updater
vaind Oct 25, 2023
6ba64f6
log status change
vaind Oct 25, 2023
d352c73
fix status caching
vaind Oct 25, 2023
6d163a6
fix
vaind Oct 25, 2023
b7e4719
process all flutter v3 subversions
vaind Oct 25, 2023
2edb9be
try to fix memory usage
vaind Oct 25, 2023
adf8f60
cleanup earlier
vaind Oct 25, 2023
6529c4b
roll back changes after figuring out the issue is with symbol collect…
vaind Oct 25, 2023
6f1fc8d
update symbol-collector to the latest version
vaind Oct 26, 2023
7b9fb06
rename .successful to .cache
vaind Oct 26, 2023
e7a20f3
don't use version in the status cache
vaind Oct 26, 2023
9461372
remove temp code
vaind Oct 26, 2023
986f954
run cron every hour
vaind Oct 26, 2023
9b74649
update symbol collector issue link
vaind Oct 27, 2023
5edbf3d
Merge branch 'main' into feat/flutter-symbol-upload
vaind Oct 30, 2023
0d8652b
minor fixes
vaind Oct 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/flutter-symbols.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Flutter symbols collection
on:
schedule:
# Run once an hour. It takes just a couple of minutes because of status caching.
- cron: "10 * * * *"
workflow_dispatch:
inputs:
flutter_version:
description: Flutter version, can be either a specific version (3.17.0) or a wildcard (3.2.*)
required: false
type: string
default: "3.*.*"

defaults:
run:
working-directory: scripts/flutter_symbol_collector

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1

- run: dart pub get

- run: dart test

run:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1

- run: dart pub get

- name: Download status cache of previously processed files
run: |
gh run download --name 'flutter-symbol-collector-database' --dir .cache
grep -r "" .cache
continue-on-error: true
env:
GITHUB_TOKEN: ${{ github.token }}

- run: dart run bin/flutter_symbol_collector.dart --version=${{ inputs.flutter_version || '3.*.*' }}
timeout-minutes: 300
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Upload updated status cache of processed files
uses: actions/upload-artifact@v3
if: always()
with:
name: flutter-symbol-collector-database
path: scripts/flutter_symbol_collector/.cache
9 changes: 9 additions & 0 deletions .github/workflows/update-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ jobs:
changelog-entry: false
secrets:
api-token: ${{ secrets.CI_DEPLOY_KEY }}

symbol-collector:
uses: getsentry/github-workflows/.github/workflows/updater.yml@v2
with:
path: scripts/update-symbol-collector.sh
name: Symbol collector CLI
changelog-entry: false
secrets:
api-token: ${{ secrets.CI_DEPLOY_KEY }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- Log warning if both tracesSampleRate and tracesSampler are set ([#1701](https://github.com/getsentry/sentry-dart/pull/1701))
- Better Flutter framework stack traces - we now collect Flutter framework debug symbols for iOS, macOS and Android automatically on the Sentry server ([#1673](https://github.com/getsentry/sentry-dart/pull/1673))

### Features

Expand Down
6 changes: 6 additions & 0 deletions scripts/flutter_symbol_collector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

.temp
.cache
4 changes: 4 additions & 0 deletions scripts/flutter_symbol_collector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Flutter symbol collector

This is an internal tool to collect Flutter debug symbols and upload them to Sentry.
This application is not intended for public usage - we're uploading the symbols in CI automatically so you don't have to.
7 changes: 7 additions & 0 deletions scripts/flutter_symbol_collector/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include: package:lints/recommended.yaml

linter:
rules:
prefer_relative_imports: true
unnecessary_brace_in_string_interps: true
unawaited_futures: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import 'package:args/args.dart';
import 'package:file/local.dart';
import 'package:flutter_symbol_collector/flutter_symbol_collector.dart';
import 'package:github/github.dart';
import 'package:logging/logging.dart';

const githubToken = String.fromEnvironment('GITHUB_TOKEN');
final githubAuth = githubToken.isEmpty
? Authentication.anonymous()
: Authentication.withToken(githubToken);
final source = FlutterSymbolSource(githubAuth: githubAuth);
final fs = LocalFileSystem();
final tempDir = fs.currentDirectory.childDirectory('.temp');
final stateCache =
DirectoryStatusCache(fs.currentDirectory.childDirectory('.cache'));
late final SymbolCollectorCli collector;

void main(List<String> arguments) async {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}'
'${record.error == null ? '' : ': ${record.error}'}');
});

final parser = ArgParser()..addOption('version', defaultsTo: '');
final args = parser.parse(arguments);
final argVersion = args['version'] as String;

collector = await SymbolCollectorCli.setup(tempDir);

// If a specific version was given, run just for this version.
if (argVersion.isNotEmpty &&
!argVersion.contains('*') &&
argVersion.split('.').length == 3) {
Logger.root.info('Running for a single flutter version: $argVersion');
await processFlutterVersion(FlutterVersion(argVersion));
} else {
// Otherwise, walk all the versions and run for the matching ones.
final versionRegex = RegExp(argVersion.isEmpty
? '.*'
: '^${argVersion.replaceAll('.', '\\.').replaceAll('*', '.+')}\$');
Logger.root.info('Running for all Flutter versions matching $versionRegex');
final versions = await source
.listFlutterVersions()
.where((v) => !v.isPreRelease)
.where((v) => versionRegex.hasMatch(v.tagName))
.toList();
Logger.root.info(
'Found ${versions.length} Flutter versions matching $versionRegex');
for (var version in versions) {
await processFlutterVersion(version);
}
}
}

Future<void> processFlutterVersion(FlutterVersion version) async {
if (bool.hasEnvironment('CI')) {
print('::group::Processing Flutter ${version.tagName}');
}
Logger.root.info('Processing Flutter ${version.tagName}');
Logger.root.info('Engine version: ${await version.engineVersion}');

final archives = await source.listSymbolArchives(version);
final dir = tempDir.childDirectory(version.tagName);
for (final archive in archives) {
final status = await stateCache.getStatus(archive);
if (status == SymbolArchiveStatus.success) {
Logger.root
.info('Skipping ${archive.path} - already processed successfully');
continue;
}

final archiveDir = dir.childDirectory(archive.platform.operatingSystem);
try {
if (await source.downloadAndExtractTo(archiveDir, archive.path)) {
if (await collector.upload(archiveDir, archive.platform, version)) {
await stateCache.setStatus(archive, SymbolArchiveStatus.success);
continue;
}
}
await stateCache.setStatus(archive, SymbolArchiveStatus.error);
} finally {
if (await archiveDir.exists()) {
await archiveDir.delete(recursive: true);
}
}
}

if (await dir.exists()) {
await dir.delete(recursive: true);
}

if (bool.hasEnvironment('CI')) {
print('::endgroup::');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'src/flutter_symbol_source.dart';
export 'src/flutter_version.dart';
export 'src/symbol_collector_cli.dart';
export 'src/status_cache.dart';
export 'src/symbol_archive.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:gcloud/storage.dart';
import 'package:platform/platform.dart';

import 'symbol_archive.dart';

abstract class FlutterSymbolResolver {
final String _prefix;
final Bucket _bucket;
final _resolvedFiles = List<SymbolArchive>.empty(growable: true);
Platform get platform;

FlutterSymbolResolver(this._bucket, String prefix)
: _prefix = prefix.endsWith('/')
? prefix.substring(0, prefix.length - 1)
: prefix;

Future<void> tryResolve(String path) async {
path = '$_prefix/$path';
final matches = await _bucket
.list(prefix: path)
.where((v) => v.isObject)
.where((v) => v.name == path) // because it's a prefix search
.map((v) => v.name)
.toList();
if (matches.isNotEmpty) {
_resolvedFiles.add(SymbolArchive(matches.single, platform));
}
}

Future<List<SymbolArchive>> listArchives();
}

class IosSymbolResolver extends FlutterSymbolResolver {
IosSymbolResolver(super.bucket, super.prefix);

@override
final platform = FakePlatform(operatingSystem: Platform.iOS);

@override
Future<List<SymbolArchive>> listArchives() async {
await tryResolve('ios-release/Flutter.dSYM.zip');
return _resolvedFiles;
}
}

class MacOSSymbolResolver extends FlutterSymbolResolver {
MacOSSymbolResolver(super.bucket, super.prefix);

@override
final platform = FakePlatform(operatingSystem: Platform.macOS);

@override
Future<List<SymbolArchive>> listArchives() async {
// darwin-x64-release directory contains a fat (arm64+x86_64) binary.
await tryResolve('darwin-x64-release/FlutterMacOS.dSYM.zip');
return _resolvedFiles;
}
}

class AndroidSymbolResolver extends FlutterSymbolResolver {
final String architecture;

AndroidSymbolResolver(super.bucket, super.prefix, this.architecture);

@override
final platform = FakePlatform(operatingSystem: Platform.android);

@override
Future<List<SymbolArchive>> listArchives() async {
await tryResolve('android-$architecture-release/symbols.zip');
return _resolvedFiles;
}
}
Loading
Loading