-
Notifications
You must be signed in to change notification settings - Fork 51
Updated the StatefulSet second exercise #781
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
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.
Other comments (6)
-
examples/ch9/statefulsets/counterapp/server.js (39-41)
Similar to the previous comment, errors in `writeCounter()` should be logged:
} catch (e) { console.error('Error writing counter:', e); return false; } - examples/ch9/statefulsets/counterapp/server.js (18-33) The application uses synchronous file operations (`fs.existsSync`, `fs.mkdirSync`, `fs.writeFileSync`, `fs.readFileSync`) which can block the Node.js event loop. For a production application, consider using the asynchronous versions of these functions to improve performance under load.
-
examples/ch9/statefulsets/counterapp/server.js (27-29)
The `JSON.parse()` call could throw an exception if the file contains invalid JSON, but it's not specifically handled. Consider adding a try-catch specifically for the parsing operation:
const raw = fs.readFileSync(DATA_FILE, 'utf8'); try { const obj = JSON.parse(raw); return typeof obj.count === 'number' ? obj.count : 0; } catch (parseError) { console.error('Error parsing counter file:', parseError); return 0; } -
examples/ch9/statefulsets/counterapp/src/app.js (1-7)
The fetchState function should provide error feedback to the user when the API call fails. Consider adding error handling to display a message when the API is unavailable.
async function fetchState() { try { const res = await fetch('/api/state'); if (!res.ok) { document.getElementById('count').textContent = 'Error'; document.getElementById('podName').textContent = 'API unavailable'; return; } const data = await res.json(); document.getElementById('count').textContent = data.count; document.getElementById('podName').textContent = `pod: ${data.podName}`; } catch (error) { document.getElementById('count').textContent = 'Error'; document.getElementById('podName').textContent = 'API unavailable'; console.error('Failed to fetch state:', error); } } -
examples/ch9/statefulsets/counterapp/src/app.js (9-14)
The increment function should provide error feedback when the API call fails. Consider adding error handling similar to fetchState.
async function increment() { try { const res = await fetch('/api/increment', { method: 'POST' }); if (!res.ok) { document.getElementById('count').textContent = 'Error'; return; } const data = await res.json(); document.getElementById('count').textContent = data.count; } catch (error) { document.getElementById('count').textContent = 'Error'; console.error('Failed to increment count:', error); } } -
examples/ch9/statefulsets/counterapp/src/app.js (16-19)
Consider adding a periodic refresh to automatically update the counter state. This would be particularly useful in a StatefulSet demonstration to show real-time updates from other pods.
window.addEventListener('DOMContentLoaded', () => { document.getElementById('incrementBtn').addEventListener('click', increment); fetchState(); // Refresh state every 5 seconds setInterval(fetchState, 5000); });
💡 To request another review, post a new comment with "/windsurf-review".
…nt limitations for stateful apps
|
@n0rq1 Thank you for the section I am going to merge it. I did make some changes after going through the exercise but I would like to call out that you did have failing CI on this pr. there was markdown linting violations and missing front-matter. Make sure you are running |
The second exercise provides a Dockerfile + code for a simple web app, the rest of the implementation is up to the user.
As opposed to what I originally had (Helm chart and some k8s manifests provided).