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

Cache extracted runtime #4179

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
013b768
fix resource name - maybe not use it from there
kebetsi Sep 14, 2023
4e28738
only define runtime cache in build task as all others depend on it
kebetsi Sep 14, 2023
f0afab7
remove duplicate runtimes from resources and use copies of up to date…
kebetsi Sep 14, 2023
6061219
Merge branch 'feature/bundle-node-runtime-in-analyzer' into fix-slow-…
kebetsi Sep 14, 2023
cbfebe7
Merge branch 'feature/bundle-node-runtime-in-analyzer' into fix-slow-…
kebetsi Sep 18, 2023
03101b5
Revert "only define runtime cache in build task as all others depend …
kebetsi Sep 18, 2023
d0202fa
leave it only for build and build_win
kebetsi Sep 18, 2023
68f4225
fix script in build win
kebetsi Sep 18, 2023
771f817
Use VM with more ram for windows
saberduck Sep 18, 2023
b213497
embeddedNode compares versions before deploying
kebetsi Sep 18, 2023
1bd5d89
add test
kebetsi Sep 18, 2023
7176269
make assertions on extracted files
kebetsi Sep 18, 2023
97f22c3
simplify test code
kebetsi Sep 18, 2023
c377279
Limit threads used in tests
saberduck Sep 18, 2023
aed352c
Run only test for Windows CI
saberduck Sep 18, 2023
df683bb
Add npm run build for Windows CI
saberduck Sep 18, 2023
9fc6e97
implement Environment abstraction for testing
kebetsi Sep 18, 2023
7118d02
set deployment folder to `~/.sonar/js/`
kebetsi Sep 18, 2023
f45bccc
Merge branch 'fix-slow-tests' into cache-extracted-runtime
kebetsi Sep 18, 2023
53134f7
UGLY: include the version.txt file in the JARs
kebetsi Sep 18, 2023
62811c3
improve some coverage with environment abstraction
kebetsi Sep 18, 2023
27f3207
improve coverage
kebetsi Sep 19, 2023
0e2c48a
remove extraction from all bridgeServerImpl tests
kebetsi Sep 19, 2023
c264fd2
Remove embeddedNode from BridgeServer constructor, since we instancia…
kebetsi Sep 19, 2023
9636987
cleanup
kebetsi Sep 19, 2023
68b9435
apply review changes
kebetsi Sep 19, 2023
d1d3a6e
fix DI and remove extra directory creation
kebetsi Sep 19, 2023
729c3d9
improve coverage
kebetsi Sep 19, 2023
007fb2e
fix test and improve coverage
kebetsi Sep 19, 2023
cd67ce0
blop commit to unblock CI
kebetsi Sep 19, 2023
9523c17
Revert "blop commit to unblock CI"
kebetsi Sep 19, 2023
653f888
fix tests for windows
kebetsi Sep 19, 2023
b7cc2ef
fix tests for MacOS
kebetsi Sep 19, 2023
83c2bc9
add writing permission on cached node runtime, since we need to overw…
kebetsi Sep 19, 2023
de7cdfb
update ruling results
kebetsi Sep 20, 2023
a6a7eb1
add some logs
kebetsi Sep 20, 2023
ee68280
remove extra debug
kebetsi Sep 20, 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
8 changes: 3 additions & 5 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
image: base-windows-jdk17-v*
platform: windows
region: eu-central-1
type: c6id.2xlarge
type: c6i.4xlarge
subnet_id: ${CIRRUS_AWS_SUBNET}
preemptible: false
use_ssd: true
Expand All @@ -68,7 +68,6 @@
CIRRUS_CLONE_DEPTH: 10
SONARSOURCE_QA: true
<<: *MAVEN_CACHE
<<: *RUNTIME_CACHE
node_version_script:
- node -v
qa_script:
Expand Down Expand Up @@ -115,6 +114,8 @@
build_script:
- source cirrus-env CI
- npm config set registry "${ARTIFACTORY_URL}/api/npm/npm"
# TODO should be as close to build_task as possible, ie. remove incompatible bash scripts
- npm run build && npm run test
- mvn test
cleanup_before_cache_script: cleanup_maven_repository

Expand Down Expand Up @@ -174,7 +175,6 @@
- TEST: '!CoverageTest,!TypeScriptAnalysisTest,!EslintBasedRulesTest,!SonarLintTest'
- TEST: 'CoverageTest,TypeScriptAnalysisTest,EslintBasedRulesTest,SonarLintTest'
<<: *MAVEN_CACHE
<<: *RUNTIME_CACHE
qa_script:
- source /c/buildTools-docker/bin/cirrus-env QA
- source /c/buildTools-docker/bin/set_maven_build_version $BUILD_NUMBER
Expand All @@ -200,7 +200,6 @@
- RULING: TypeScriptRulingTest
- RULING: CssRulingTest
<<: *MAVEN_CACHE
<<: *RUNTIME_CACHE
submodules_script:
- git submodule update --init
ruling_script:
Expand All @@ -213,7 +212,7 @@
diff_artifacts:
path: '**/target/actual/**/*'

promote_task:

Check warning on line 215 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L215

task "promote" depends on task "ws_scan", but their only_if conditions are different

Check warning on line 215 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L215

task "promote" depends on task "ws_scan", but their only_if conditions are different
depends_on:
- ws_scan
- build_win
Expand All @@ -234,6 +233,5 @@
#artifacts that will have downloadable links in burgr
ARTIFACTS: org.sonarsource.javascript:sonar-javascript-plugin:jar
<<: *MAVEN_CACHE
<<: *RUNTIME_CACHE
script: cirrus_promote_maven
cleanup_before_cache_script: cleanup_maven_repository
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clear": "rimraf lib/*",
"check-format": "prettier --list-different .",
"test": "jest",
"test-with-coverage": "jest --coverage",
"test-with-coverage": "jest --maxWorkers=75% --coverage",
"format": "prettier --write .",
"compile": "tsc -b packages/tsconfig.app.json packages/tsconfig.test.json profiling",
"check-distribution": "bash tools/check-distribution-filepath-length.sh",
Expand Down
46 changes: 46 additions & 0 deletions sonar-plugin/sonar-javascript-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
<resource>win-x64/node.exe.xz</resource>
<file>${project.build.directory}/node/win-x64/node.exe.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
ilia-kebets-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
<resource>win-x64/version.txt</resource>
<file>${project.build.directory}/node/win-x64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand All @@ -188,6 +192,10 @@
<resource>linux-x64/node.xz</resource>
<file>${project.build.directory}/node/linux-x64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-x64/version.txt</resource>
<file>${project.build.directory}/node/linux-x64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand All @@ -212,6 +220,10 @@
<resource>darwin-arm64/node.xz</resource>
<file>${project.build.directory}/node/darwin-arm64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>darwin-arm64/version.txt</resource>
<file>${project.build.directory}/node/darwin-arm64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand All @@ -236,14 +248,26 @@
<resource>win-x64/node.exe.xz</resource>
<file>${project.build.directory}/node/win-x64/node.exe.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>win-x64/version.txt</resource>
<file>${project.build.directory}/node/win-x64/version.txt</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-x64/node.xz</resource>
<file>${project.build.directory}/node/linux-x64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-x64/version.txt</resource>
<file>${project.build.directory}/node/linux-x64/version.txt</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>darwin-arm64/node.xz</resource>
<file>${project.build.directory}/node/darwin-arm64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>darwin-arm64/version.txt</resource>
<file>${project.build.directory}/node/darwin-arm64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand Down Expand Up @@ -292,6 +316,28 @@
</executions>
</plugin>

<!-- copy runtimes so they are accessible by unit tests -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/test-classes</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/node</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.sonar.plugins.javascript.bridge.BridgeServerImpl;
import org.sonar.plugins.javascript.bridge.BundleImpl;
import org.sonar.plugins.javascript.bridge.CssRuleSensor;
import org.sonar.plugins.javascript.bridge.EmbeddedNode;
import org.sonar.plugins.javascript.bridge.EnvironmentImpl;
import org.sonar.plugins.javascript.bridge.HtmlSensor;
import org.sonar.plugins.javascript.bridge.JsTsChecks;
import org.sonar.plugins.javascript.bridge.JsTsSensor;
Expand Down Expand Up @@ -152,7 +152,7 @@ public void define(Context context) {
AnalysisProcessor.class,
YamlSensor.class,
HtmlSensor.class,
EmbeddedNode.class
EnvironmentImpl.class
);

context.addExtensions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.HashMap;
Expand All @@ -48,7 +49,6 @@
import javax.annotation.Nullable;
import org.sonar.api.SonarProduct;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
Expand All @@ -75,7 +75,7 @@ private enum Status {
"SONARJS_EXISTING_NODE_PROCESS_PORT";
private static final Gson GSON = new Gson();

private static final String DEPLOY_LOCATION = "bridge-bundle";
private static final Path DEPLOY_LOCATION = Path.of(".sonar", "js", "bridge-bundle");

private final HttpClient client;
private final NodeCommandBuilder nodeCommandBuilder;
Expand All @@ -100,19 +100,17 @@ public BridgeServerImpl(
Bundle bundle,
RulesBundles rulesBundles,
NodeDeprecationWarning deprecationWarning,
TempFolder tempFolder,
Monitoring monitoring,
EmbeddedNode embeddedNode
Environment environment
) {
this(
nodeCommandBuilder,
DEFAULT_TIMEOUT_SECONDS,
bundle,
rulesBundles,
deprecationWarning,
tempFolder,
monitoring,
embeddedNode
ilia-kebets-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
environment
);
}

Expand All @@ -122,9 +120,8 @@ public BridgeServerImpl(
Bundle bundle,
RulesBundles rulesBundles,
NodeDeprecationWarning deprecationWarning,
TempFolder tempFolder,
Monitoring monitoring,
EmbeddedNode embeddedNode
ilia-kebets-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
Environment environment
) {
this.nodeCommandBuilder = nodeCommandBuilder;
this.timeoutSeconds = timeoutSeconds;
Expand All @@ -134,10 +131,17 @@ public BridgeServerImpl(
this.rulesBundles = rulesBundles;
this.deprecationWarning = deprecationWarning;
this.hostAddress = InetAddress.getLoopbackAddress().getHostAddress();
this.deployLocation = tempFolder.newDir(DEPLOY_LOCATION).toPath();
this.deployLocation = getPluginCache(environment.getUserHome());
this.monitoring = monitoring;
this.heartbeatService = Executors.newSingleThreadScheduledExecutor();
this.embeddedNode = embeddedNode;
this.embeddedNode = new EmbeddedNode(environment);
}

/**
* @return a path to `DEPLOY_LOCATION` from the given `baseDir`
*/
private Path getPluginCache(String baseDir) {
return Path.of(baseDir).resolve(DEPLOY_LOCATION);
}

void heartbeat() {
Expand All @@ -163,7 +167,13 @@ int getTimeoutSeconds() {
return timeoutSeconds;
}

/**
* Extracts the bridge files and node.js runtime (if included)
*
* @throws IOException
*/
void deploy() throws IOException {
Files.createDirectories(deployLocation);
ilia-kebets-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
bundle.deploy(deployLocation);
embeddedNode.deployNode(deployLocation);
}
Expand Down
Loading