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

Remove performance monitoring code #4576

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,6 @@ void should_not_use_node_in_cwd() throws Exception {
assertThat(pingBytes).isNotEqualTo(nodeBytes);
}

@Test
void should_record_perf_metrics() throws Exception {
String projectKey = "eslint_based_rules";
File projectDir = TestUtils.projectDir(projectKey);
SonarScanner build = getSonarScanner()
.setProjectKey(projectKey)
.setSourceEncoding("UTF-8")
.setSourceDirs(".")
.setProperty("sonar.javascript.monitoring", "true")
.setProperty(
"sonar.javascript.monitoring.path",
projectDir.toPath().resolve(".scannerwork").toString()
)
.setProjectDir(projectDir);

BuildResult buildResult = orchestrator.executeBuild(build);
assertThat(buildResult.isSuccess()).isTrue();
assertThat(projectDir.toPath().resolve(".scannerwork/metrics.json")).exists();
}

@Test
void quickfix() throws Exception {
var projectKey = "quickfix";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ void should_raise_issues_in_html_files() throws IOException {
// assertPerfMonitoringAvailable(perfMonitoringDir);
}

private void assertPerfMonitoringAvailable(Path perfMonitoringDir) throws IOException {
String content = Files.readString(perfMonitoringDir.resolve("metrics.json"));
assertThat(content)
.contains("\"ncloc\":4")
.containsPattern("\"parseTime\":\\d+")
.containsPattern("\"analysisTime\":\\d+")
.contains("\"component\":\"index.html\"");
}

@Test
void should_not_raise_issues_for_blacklisted_rules() {
var projectKey = "html-project-blacklisted-rules";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,4 @@ void test() throws Exception {
.isEmpty();
// assertPerfMonitoringAvailable(perfMonitoringDir);
}

// asserting perf monitoring on TypeScript project as it creates all kinds of metrics
private void assertPerfMonitoringAvailable(Path perfMonitoringDir) throws IOException {
String content = Files.readString(perfMonitoringDir.resolve("metrics.json"));
assertThat(content)
.contains("\"metricType\":\"FILE\"")
.contains("\"metricType\":\"SENSOR\"")
.contains("\"metricType\":\"PROGRAM\"")
.contains("\"metricType\":\"RULE\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -68,15 +67,6 @@ void single_line_inline_aws_lambda_for_js() throws IOException {
// assertPerfMonitoringAvailable(perfMonitoringDir);
}

private void assertPerfMonitoringAvailable(Path perfMonitoringDir) throws IOException {
String content = Files.readString(perfMonitoringDir.resolve("metrics.json"));
assertThat(content)
.contains("\"ncloc\":1")
.containsPattern("\"parseTime\":\\d+")
.containsPattern("\"analysisTime\":\\d+")
.contains("\"component\":\"file.yaml\"");
}

@Test
void dont_start_eslint_bridge_for_yaml_without_nodejs_aws() {
var projectKey = "yaml-aws-lambda-skipped";
Expand Down
4 changes: 0 additions & 4 deletions packages/bridge/src/errors/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,4 @@ export const EMPTY_JSTS_ANALYSIS_OUTPUT: JsTsAnalysisOutput = {
cognitiveComplexity: 0,
},
cpdTokens: [],
perf: {
parseTime: 0,
analysisTime: 0,
},
};
2 changes: 0 additions & 2 deletions packages/jsts/src/analysis/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
import { FileType, JsTsLanguage, AnalysisInput, AnalysisOutput, ErrorCode } from '@sonar/shared';
import { CpdToken, Issue, Metrics, SymbolHighlight, SyntaxHighlight } from '../linter';
import { Perf } from '../monitoring';

/**
*
Expand Down Expand Up @@ -63,6 +62,5 @@ export interface JsTsAnalysisOutput extends AnalysisOutput {
highlightedSymbols?: SymbolHighlight[];
metrics?: Metrics;
cpdTokens?: CpdToken[];
perf?: Perf;
ucfgPaths?: string[];
}
7 changes: 1 addition & 6 deletions packages/jsts/src/analysis/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
SymbolHighlight,
} from '../linter';
import { buildSourceCode } from '../builders';
import { measureDuration } from '../monitoring';
import { JsTsAnalysisInput, JsTsAnalysisOutput } from './analysis';

/**
Expand All @@ -51,11 +50,7 @@ import { JsTsAnalysisInput, JsTsAnalysisOutput } from './analysis';
export function analyzeJSTS(input: JsTsAnalysisInput, language: JsTsLanguage): JsTsAnalysisOutput {
debug(`Analyzing file "${input.filePath}" with linterId "${input.linterId}"`);
const linter = getLinter(input.linterId);
const building = () => buildSourceCode(input, language);
const { result: built, duration: parseTime } = measureDuration(building);
const analysis = () => analyzeFile(linter, input, built);
const { result: output, duration: analysisTime } = measureDuration(analysis);
return { ...output, perf: { parseTime, analysisTime } };
return analyzeFile(linter, input, buildSourceCode(input, language));
}

/**
Expand Down
3 changes: 0 additions & 3 deletions packages/jsts/src/embedded/analysis/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { Perf } from 'jsts/src/monitoring';
import { Issue } from '../../linter';
import { AnalysisInput, AnalysisOutput } from '@sonar/shared';

Expand All @@ -41,8 +40,6 @@ export interface EmbeddedAnalysisInput extends AnalysisInput {}
export interface EmbeddedAnalysisOutput extends AnalysisOutput {
issues: Issue[];
ucfgPaths?: string[];
// We only need monitoring metrics for embedded languages. See AnalysisProcessor.java
perf: Perf;
metrics: {
ncloc: number[];
};
Expand Down
12 changes: 2 additions & 10 deletions packages/jsts/src/embedded/analysis/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { getLinter, Issue, LinterWrapper } from '../../linter';
import { buildSourceCodes, ExtendedSourceCode, LanguageParser } from '../builder';
import { EmbeddedAnalysisInput, EmbeddedAnalysisOutput } from './analysis';
import { debug } from '@sonar/shared';
import { measureDuration } from '../../monitoring';
import { findNcloc } from '../../linter/visitors/metrics/ncloc';

/**
Expand Down Expand Up @@ -53,15 +52,8 @@ export function analyzeEmbedded(
): EmbeddedAnalysisOutput {
debug(`Analyzing file "${input.filePath}" with linterId "${input.linterId}"`);
const linter = getLinter(input.linterId);
const building = () => buildSourceCodes(input, languageParser);
const { result: extendedSourceCodes, duration: parseTime } = measureDuration(building);
const analysis = () => analyzeFile(linter, extendedSourceCodes);
const { result: output, duration: analysisTime } = measureDuration(analysis);

return {
...output,
perf: { parseTime, analysisTime },
};
const extendedSourceCodes = buildSourceCodes(input, languageParser);
return analyzeFile(linter, extendedSourceCodes);
}

/**
Expand Down
21 changes: 0 additions & 21 deletions packages/jsts/src/monitoring/index.ts

This file was deleted.

32 changes: 0 additions & 32 deletions packages/jsts/src/monitoring/measure.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/jsts/src/monitoring/performance.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/jsts/tests/analysis/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,24 +866,6 @@ describe('analyzeJSTS', () => {
});
});

it('should measure analysis duration', async () => {
const rules = [
{ key: 'no-extra-semi', configurations: [], fileTypeTarget: ['MAIN'] },
{ key: 'no-duplicate-string', configurations: [], fileTypeTarget: ['MAIN'] },
{ key: 'sonar-no-regex-spaces', configurations: [], fileTypeTarget: ['MAIN'] },
] as RuleConfig[];
initializeLinter(rules);

const filePath = path.join(__dirname, 'fixtures', 'measure.js');
const language = 'js';

const {
perf: { parseTime, analysisTime },
} = analyzeJSTS(await jsTsInput({ filePath }), language) as JsTsAnalysisOutput;
expect(parseTime).toBeGreaterThan(0);
expect(analysisTime).toBeGreaterThan(0);
});

it('should return parsing errors', async () => {
const rules = [];
initializeLinter(rules);
Expand Down
36 changes: 0 additions & 36 deletions packages/jsts/tests/monitoring/measure.test.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/yaml/tests/analysis/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,4 @@ describe('analyzeYAML', () => {
getLinter().linter.defineRule(rule.key, rule.module);
analyzeEmbedded(await embeddedInput({ filePath }), parseAwsFromYaml);
});

it('should measure analysis duration', async () => {
initializeLinter([
{ key: 'no-all-duplicated-branches', configurations: [], fileTypeTarget: ['MAIN'] },
]);
const {
perf: { parseTime, analysisTime },
metrics: { ncloc },
} = analyzeEmbedded(
await embeddedInput({ filePath: join(fixturesPath, 'monitoring.yaml') }),
parseAwsFromYaml,
);
expect(parseTime).toBeGreaterThan(0);
expect(analysisTime).toBeGreaterThan(0);
expect(ncloc).toHaveLength(1);
expect(ncloc[0]).toEqual(7);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.sonar.plugins.javascript.bridge.HtmlSensor;
import org.sonar.plugins.javascript.bridge.JsTsChecks;
import org.sonar.plugins.javascript.bridge.JsTsSensor;
import org.sonar.plugins.javascript.bridge.Monitoring;
import org.sonar.plugins.javascript.bridge.NodeDeprecationWarning;
import org.sonar.plugins.javascript.bridge.RulesBundles;
import org.sonar.plugins.javascript.bridge.YamlSensor;
Expand Down Expand Up @@ -156,7 +155,6 @@ public void define(Context context) {
RulesBundles.class,
JsTsChecks.class,
AnalysisWarningsWrapper.class,
Monitoring.class,
AnalysisWithProgram.class,
AnalysisWithWatchProgram.class,
AnalysisProcessor.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ abstract class AbstractAnalysis {
static final long PROGRESS_REPORT_PERIOD = TimeUnit.SECONDS.toMillis(10);

final BridgeServer bridgeServer;
final Monitoring monitoring;
final AnalysisProcessor analysisProcessor;
SensorContext context;
ContextUtils contextUtils;
Expand All @@ -49,12 +48,10 @@ abstract class AbstractAnalysis {

AbstractAnalysis(
BridgeServer bridgeServer,
Monitoring monitoring,
AnalysisProcessor analysisProcessor,
AnalysisWarningsWrapper analysisWarnings
) {
this.bridgeServer = bridgeServer;
this.monitoring = monitoring;
this.analysisProcessor = analysisProcessor;
this.analysisWarnings = analysisWarnings;
}
Expand Down
Loading
Loading