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

SONARPY-2451 SONARPY-2459 SONARPY-2464 Collect data for the Jupyter notebooks #2235

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

ghislainpiot
Copy link
Contributor

@ghislainpiot ghislainpiot commented Dec 11, 2024

@ghislainpiot ghislainpiot changed the base branch from master to SONARPY-2454 December 12, 2024 08:35
Base automatically changed from SONARPY-2454 to master December 12, 2024 08:43
Copy link
Contributor

@joke1196 joke1196 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite good. I added suggestions for the shape of the API, and the workaround the functional API of java.


public SensorTelemetryStorage() {
data = new HashMap<>();
data.put(NOTEBOOK_PRESENT_KEY, "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could hide the implementation detail of the Map by making it private and accessing it through an API that is more domain oriented, i.e. updateMetrics. Following this direction We could also provide a specific type for the metrics key, i.e. TelemetryKey so that user to not pass any string to the Telemetry but only predefined key. I think it is good to be strict here so that we do not have a mess later on when other devs try to use the telemetry API

List<PythonInputFile> generatedIPythonFiles = new ArrayList<>();

sensorTelemetryStorage.data.put(SensorTelemetryStorage.NOTEBOOK_TOTAL_KEY, String.valueOf(pythonFiles.size()));
final int[] numberOfFailedParsing = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a workaround as you need a final var for the lambda? I think it would be more readable to an if

Suggested change
final int[] numberOfFailedParsing = {0};
int numberOfFailedParsing = 0;
if(result.isPresent()){
generatedIPythonFiles.add(result.get());
}else {
numberOfFailedParsing++;
}

instead of trying to work against java.

@@ -50,6 +50,8 @@ public final class TestsUtils {
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION))
.addPlugin(PLUGIN_LOCATION)
.setServerProperty("sonar.telemetry.enable", "false") // Disable telemetry waiting for ORCH-497
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be part of this PR. Maybe a merge issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a rebase/base branch thing, should be ok now

@ghislainpiot ghislainpiot force-pushed the SONARPY-2451 branch 2 times, most recently from ebb485b to fa62a77 Compare December 12, 2024 13:17
@joke1196 joke1196 changed the title SONARPY-2451 Collect data for the Jupyter notebooks SONARPY-2451 SONARPY-2459 Collect data for the Jupyter notebooks Dec 12, 2024
public static final MetricKey NOTEBOOK_TOTAL_KEY = new MetricKey("python.notebook.total");
public static final MetricKey NOTEBOOK_PARSE_ERROR_KEY = new MetricKey("python.notebook.parse_error");
public static final MetricKey NOTEBOOK_RECOGNITION_ERROR_KEY = new MetricKey("python.notebook.recognition_error");
public static final MetricKey NOTEBOOK_EXCEPTION_KEY = new MetricKey("python.notebook.exceptions");
final Map<String, String> data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could make this private

@ghislainpiot ghislainpiot force-pushed the SONARPY-2451 branch 2 times, most recently from 5595ef4 to 98205bc Compare December 13, 2024 16:24
@ghislainpiot ghislainpiot changed the title SONARPY-2451 SONARPY-2459 Collect data for the Jupyter notebooks SONARPY-2451 SONARPY-2459 SONARPY-2464 Collect data for the Jupyter notebooks Dec 13, 2024
}

private void processNotebooksFiles(List<PythonInputFile> pythonFiles, SensorContext context) {
pythonFiles = parseNotebooks(pythonFiles, context);
pythonFiles = this.parseNotebooks(pythonFiles, context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this this needed?

data.put(key.key(), value);
}

public enum MetricKey {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this enum massively used outside of the SensorTelemetryStorage - probably it makes sense to make it a top-level class

public class SensorTelemetryStorage {
private static final Logger LOG = LoggerFactory.getLogger(SensorTelemetryStorage.class);

private final Map<String, String> data;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the key of the data map can't be of MetricKey type?

data = new HashMap<>();
}

public Map<String, String> data() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that this method is used for test purposes only, so probably it should not be public.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, as discussed some small changes required but no need to revisit again

@ghislainpiot ghislainpiot force-pushed the SONARPY-2451 branch 3 times, most recently from bf32141 to d7f764c Compare December 16, 2024 13:06
@ghislainpiot ghislainpiot force-pushed the SONARPY-2451 branch 2 times, most recently from cba6ca6 to 47eab69 Compare December 17, 2024 10:18
Copy link
Contributor

@Seppli11 Seppli11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. However, I had a question during review and there are some minor nitpicks.

for (PythonInputFile inputFile : pythonFiles) {
try {
sensorTelemetryStorage.updateMetric(TelemetryMetricKey.NOTEBOOK_PRESENT_KEY, "1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when the key is not present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field is just not present. I don't think it is possible to have a default value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't pose an issue to analyze the data afterward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will, we cannot set a default value because if there are no notebooks the sensor doesn't run

}
}

public void updateMetric(TelemetryMetricKey key, String value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few calls to updateMetric where value is an int and String.valueOf is called. Would it maybe make sense to have an overload?

private final Map<TelemetryMetricKey, String> data;

public SensorTelemetryStorage() {
data = new EnumMap<>(TelemetryMetricKey.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: the assignment could be moved to the field declaration and the constructor can be removed

Copy link
Contributor

@Seppli11 Seppli11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghislainpiot ghislainpiot merged commit a22456e into master Dec 17, 2024
13 checks passed
@ghislainpiot ghislainpiot deleted the SONARPY-2451 branch December 17, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants