Skip to content

Internal Bugfix - add telemetry guards for string overflow #4538

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

damntrecky
Copy link
Contributor

Types of changes

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Description

These changes are to prevent emitting telemetry items that are too long and is a defensive coding strategy to prevent overflows in the backend.

Checklist

  • [x ] My code follows the code style of this project
  • [x ] I have added tests to cover my changes
  • A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • I have added metrics for my changes (if required)

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@damntrecky damntrecky requested review from a team as code owners May 31, 2024 20:36
@@ -1,10 +0,0 @@
<component name="CopyrightManager">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NIT: Re-add this

@@ -1,6 +0,0 @@
<component name="CopyrightManager">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NIT: Re-add this

object CodeTransformTelemetryMetadataSingleton {
private val instance = CodeTransformTelemetryMetadata()

fun getInstance() = instance
Copy link
Contributor

Choose a reason for hiding this comment

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

getInstance() in this project implies the platform "service" construct, rather than a singleton

Copy link
Contributor Author

@damntrecky damntrecky Jun 10, 2024

Choose a reason for hiding this comment

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

Are you saying the coding style for this repo of getInstance is reserved as a keyword for a "service" level construct? Or project level?

If its service level, then it would fit because this is a single instance shared across our service preventing duplicates.

Copy link
Contributor

Choose a reason for hiding this comment

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

service as in the intellij platform service construct


package software.aws.toolkits.jetbrains.services.codemodernizer.model

object CodeTransformTelemetryMetadataSingleton {
Copy link
Contributor

Choose a reason for hiding this comment

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

i like the modularization for testing, but now your project service is sharing state across all instances, which is probably not what you want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only have one instance at a time right now and we do want to share this across any reference to it. For simplicity we are not managing the state of the object within any of our manager classes.

If we move to a multi instance service, we can make this a variable with session or sessionContext.

Copy link
Contributor

Choose a reason for hiding this comment

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

in the interest of avoiding global state that isn't managed by the platform then, can you convert this into a light service?
https://plugins.jetbrains.com/docs/intellij/plugin-services.html#light-services

your test will need to have an ApplicationRule applied

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I'll check out adding these changes to convert to:

@Service(Service.Level.PROJECT)
public final class MyProjectService {
...

import junit.framework.TestCase.assertEquals
import org.junit.Test

open class CodeTransformTelemetryMetadataSingletonTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't need to be open

Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to fix, but in future avoid unnecessary diffs

@damntrecky damntrecky enabled auto-merge (squash) June 11, 2024 21:58
import com.intellij.openapi.components.Service

@Service(Service.Level.APP)
public final class CodeTransformTelemetryService {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rli Should I drop the the instance and getInstance and just have my metadata a member of my telemetry class?

It looks like the service docs are implying that it will find the service level singelton if existed when calling my class like

service<CodeTransformTelemetryService>()
Screenshot 2024-06-11 at 4 05 26 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

instance for sure
getInstance is just a convenience to save needing to import two things every time. you are the only consumer of the service so it can go either way

Copy link

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
3.0% Duplication on New Code

See analysis details on SonarCloud

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.

3 participants