-
Notifications
You must be signed in to change notification settings - Fork 93
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
Conversation
6955f08
to
590f311
Compare
590f311
to
6d742a8
Compare
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
ebb485b
to
fa62a77
Compare
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; |
There was a problem hiding this comment.
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
5595ef4
to
98205bc
Compare
98205bc
to
67270df
Compare
67270df
to
3823b50
Compare
} | ||
|
||
private void processNotebooksFiles(List<PythonInputFile> pythonFiles, SensorContext context) { | ||
pythonFiles = parseNotebooks(pythonFiles, context); | ||
pythonFiles = this.parseNotebooks(pythonFiles, context); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
bf32141
to
d7f764c
Compare
cba6ca6
to
47eab69
Compare
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
47eab69
to
cddb775
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
SONARPY-2451
SONARPY-2459