-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Configurable import strict mode and max import message count #56
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR adds configurable strict mode for the /import endpoint, allowing developers to bypass validation when importing historical events. The implementation uses a new DeliveryOptions class with a builder pattern to configure delivery behavior, maintaining backward compatibility while adding flexibility.
- Introduces
DeliveryOptionsclass with builder pattern for configuringimportStrictModeanduseIpAddress - Updates
/importendpoint handling to support bothstrict=1(validation enabled) andstrict=0(validation bypassed) modes - Maintains backward compatibility by defaulting to
strict=1when using existingdeliver()methods
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java | New class providing builder pattern for delivery configuration with importStrictMode and useIpAddress options |
| src/main/java/com/mixpanel/mixpanelapi/MixpanelAPI.java | Refactored deliver() methods to use DeliveryOptions, added strict mode parameter to import URL, and updated response parsing to handle both strict=1 (JSON) and strict=0 (plain text) responses |
| src/test/java/com/mixpanel/mixpanelapi/MixpanelAPITest.java | Added comprehensive tests for DeliveryOptions builder, strict mode URL parameter generation, and useIpAddress option |
| /** | ||
| * Sets whether to use strict mode for import messages. | ||
| * | ||
| * will validate the supplied events and return a 400 status code if any of the events fail validation with details of the error |
Copilot
AI
Dec 5, 2025
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 line appears to be a leftover fragment from editing. It's not formatted as a proper JavaDoc comment (missing <p> tag or proper punctuation) and duplicates the content of the following line. Remove this line as the complete description starts on line 76.
| * will validate the supplied events and return a 400 status code if any of the events fail validation with details of the error |
| public void testImportWithStrictModeDisabled() { | ||
| // Test that strict=0 is in the URL when strictMode is false | ||
| final Map<String, String> capturedUrls = new HashMap<String, String>(); | ||
|
|
||
| MixpanelAPI api = new MixpanelAPI("events url", "people url", "groups url", "import url") { | ||
| @Override | ||
| public boolean sendImportData(String dataString, String endpointUrl, String token) { | ||
| capturedUrls.put("endpoint", endpointUrl); | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| ClientDelivery c = new ClientDelivery(); | ||
| long historicalTime = System.currentTimeMillis() - (90L * 24L * 60L * 60L * 1000L); | ||
|
|
||
| try { | ||
| JSONObject props = new JSONObject(); | ||
| props.put("time", historicalTime); | ||
| props.put("$insert_id", "insert-id-1"); | ||
| JSONObject importEvent = mBuilder.importEvent("user-1", "test event", props); | ||
| c.addMessage(importEvent); | ||
|
|
||
| // Disable strict mode | ||
| DeliveryOptions options = new DeliveryOptions.Builder() | ||
| .importStrictMode(false) | ||
| .build(); | ||
| api.deliver(c, options); | ||
|
|
||
| String url = capturedUrls.get("endpoint"); | ||
| assertTrue("With importStrictMode=false: strict=0 in URL", url.contains("strict=0")); | ||
|
|
||
| } catch (IOException e) { | ||
| fail("IOException: " + e.toString()); | ||
| } catch (JSONException e) { | ||
| fail("JSON error: " + e.toString()); | ||
| } | ||
|
|
||
| api.close(); | ||
| } |
Copilot
AI
Dec 5, 2025
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 tests verify that strict=0 is added to the URL, but they don't test the actual response parsing logic for strict=0 mode. The sendImportData method in lines 596-604 of MixpanelAPI.java handles plain text "0" and "1" responses for strict=0, but this logic isn't covered by tests.
Consider adding tests that verify:
- A response of "1" is treated as success in strict=0 mode
- A response of "0" is handled appropriately in strict=0 mode
- The fallback to JSON parsing still works when needed
This can be tested by mocking the HTTP response instead of overriding sendImportData().
jaredmixpanel
left a comment
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
Add configurable strict mode for import messages
This PR adds the ability to disable strict validation when importing historical events via the
/importendpoint.Changes
New
DeliveryOptionsclass with builder pattern for configuring delivery behaviorimportStrictMode(default:true) - Controls validation on/importendpointuseIpAddress(default:false) - Controls IP-based geolocation for events/people/groupsNew
deliver(ClientDelivery, DeliveryOptions)method for advanced delivery configurationUpdated
/importendpoint handling to support both strict modes:strict=1(default): Validates events, returns JSON response with validation errorsstrict=0: Bypasses validation, returns plain text"0"or"1"Backward compatible - Existing
deliver()methods unchanged, default tostrict=1Usage
Configurable Import Max Message Count Summary
Add
importMaxMessageCountbuilder option to allow custom configuration of the import batch size for the/importendpoint.Changes
New Builder Method
importMaxMessageCount(int)toMixpanelAPI.BuilderImplementation Details
mImportMaxMessageCountfield toMixpanelAPIclasssendImportMessages()to use configured batch size instead of staticConfig.IMPORT_MAX_MESSAGE_SIZEMath.min()safety check in constructor to enforce maximum of 2000 (Mixpanel API limit)Testing
testCustomImportMaxMessageCount()test caseUsage Example