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

DXCDT-282: Support suspended log streams #725

Merged
merged 8 commits into from
Jan 30, 2023

Conversation

willvedd
Copy link
Contributor

@willvedd willvedd commented Jan 27, 2023

🔧 Changes

Log streams were added with #495 which initially ignored log streams that were in a suspended status. This was mostly because the behavior of these log streams were slightly different and unknown. Ignoring these log streams caused a couple issues but most notably, if a target tenant has a log stream that has been suspended and applying configuration to it, the Deploy CLI will think that the suspended log stream does not exist and attempt to create a new one. With strict limits on the number of log streams, this is likely to be problematic.

This time around, the behavior of suspended log streams is better understood:

  • Cannot be put log stream directly into a suspended status
  • Log streams are put into a suspended state after some number of failed log deliveries
  • Cannot specify any status at creation but can specify either paused or active status at update
  • Cannot specify "status": "suspended" when updating an already suspended log stream
  • Can update other properties of a suspended log stream, status remains suspended, will not activate

In addition to adding suspended log streams support and updating the tests, I expanded the documentation around HTTP recordings and some basic troubleshooting instructions.

📚 References

🔬 Testing

Added a couple of unit tests, but they're not great and mostly test the implementation. To really ensure functionality, the existing E2E tests add partial support. However, it is impossible to directly put a log stream into a suspended state, so we are not able to test this against real remote tenants.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@willvedd willvedd requested a review from a team as a code owner January 27, 2023 21:21
Comment on lines 23 to 24
- `access_denied: {"error":"access_denied","error_description":"Unauthorized"}` - The client ID/secret pair provided through `AUTH0_E2E_CLIENT_ID` and `AUTH0_E2E_CLIENT_SECRET` respectively is not valid, double-check their correct values
- `APIError: Nock: Disallowed net connect for "auth0-deploy-cli-e2e.us.auth0.com:443/oauth/token"` - Recordings already exist for this test, will need to remove the correlating recordings file and try again. Re-recording the entire file is necessary even if HTTP request changes are additive.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While re-recording the E2E tests, I came against these errors. I seem to always forget how to go through this process so any documentation is helpful to jog my memory.

Comment on lines +741 to +745
- name: Suspended DD Log Stream
sink:
datadogApiKey: some-sensitive-api-key
datadogRegion: us
type: datadog
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 omission of status is key here. This simulates what a suspend log stream will look like when exported from Auth0 tenant to local configuration files.

Comment on lines +65 to +102
logStreams: [
{
id: 'log-stream-1',
name: 'Splunky',
type: 'splunk',
status: 'paused',
sink: {
splunkDomain: 'test-splunk.com',
splunkPort: '8089',
splunkToken: '7b838bd0-028e-4d78-a82c-3564a2007770',
splunkSecure: false,
},
},
{
id: 'log-stream-2',
name: 'HTTP Log Stream',
type: 'http',
status: 'active',
sink: {
httpAuthorization: '_VALUE_NOT_SHOWN_', // secret obfuscated
httpContentFormat: 'JSONLINES',
httpContentType: 'application/json',
httpEndpoint: 'https://example.com/test',
},
},
{
id: 'log-stream-3',
name: 'Suspended HTTP Log Stream',
type: 'http',
// status property omitted if suspended
sink: {
httpAuthorization: '_VALUE_NOT_SHOWN_', // secret obfuscated
httpContentFormat: 'JSONLINES',
httpContentType: 'application/json',
httpEndpoint: 'https://suspended.com/logs',
},
},
],
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 difference between the output of the function and the mockLogStreams input is enough where I'd prefer to not write cryptic code to generate the expected value. Although more lines of code, it's clearer what the output is IMO.

delete value.id; // Not expecting ID in PATCH payload
delete value.type; // Not expecting type in PATCH payload
//@ts-ignore because it's actually ok for status property to be omitted in PATCH payload
if (value?.status === 'suspended') delete value.status; // Not expecting status in PATCH payload if suspended
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the major addition here. I'm not in love with this test, it's more testing the implementation than behavior. But at least it's an extra assertion to make 🤷‍♂️ . This is why I add it to the E2E test for more security.

@codecov-commenter
Copy link

Codecov Report

Base: 83.53% // Head: 83.49% // Decreases project coverage by -0.05% ⚠️

Coverage data is based on head (976d8e7) compared to base (4a191bd).
Patch coverage: 77.77% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #725      +/-   ##
==========================================
- Coverage   83.53%   83.49%   -0.05%     
==========================================
  Files         114      114              
  Lines        3340     3344       +4     
  Branches      615      617       +2     
==========================================
+ Hits         2790     2792       +2     
- Misses        323      324       +1     
- Partials      227      228       +1     
Impacted Files Coverage Δ
src/types.ts 100.00% <ø> (ø)
src/tools/auth0/handlers/logStreams.ts 70.83% <77.77%> (-4.17%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines +120 to +125
logStreams: {
getAll: (arg0: SharedPaginationParams) => Promise<LogStream[]>;
create: (arg0: { id: string }) => Promise<LogStream>;
update: (arg0: {}, arg1: Partial<LogStream>) => Promise<LogStream>;
delete: (arg0: Asset) => Promise<void>;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This applies stricter type the Auth0 Management API when working with log streams. This is important because I do a lot of checking against the status field so want to make sure it's correct.

Comment on lines 59 to 61
const nonSuspendedLogStreams = logStreams.filter(
(logStream: LogStream) => logStream.status !== 'suspended'
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this line allows us to unignore suspended log streams.

test/e2e/e2e_recordings.md Outdated Show resolved Hide resolved
willvedd and others added 3 commits January 30, 2023 08:37
…to DXCDT-282-support-suspended-log-streams
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
@willvedd willvedd merged commit f252e8e into master Jan 30, 2023
@willvedd willvedd deleted the DXCDT-282-support-suspended-log-streams branch January 30, 2023 23:21
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.

None yet

4 participants