Prabal864 opened a new pull request, #4338:
URL: https://github.com/apache/hertzbeat/pull/4338

   Fixes #1343.
   
   Adds a "Preview" capability for notice templates: render a template's 
content against a representative sample alert and see the output, without 
saving the template or sending anything.
   
   ### What's new
   
   - `NoticeTemplateRenderer` — extracted the FreeMarker rendering logic that 
lived inside `AbstractAlertNotifyHandlerImpl.renderContent()` into a shared 
utility. Both the real notify dispatch path (all `AlertNotifyHandler` 
implementations) and the new preview endpoint now render a template through the 
exact same code, so preview output matches what actually gets sent.
   - `POST /api/notice/template/preview` — accepts a (possibly unsaved, no `id` 
needed) `NoticeTemplate`, renders it against a sample alert, returns the 
rendered text. Errors (e.g. malformed template syntax) come back as a normal 
`Message.fail` response rather than a 500.
   
   ### Why not reuse `/receiver/send-test-msg`?
   
   That endpoint tests a *receiver channel* by actually sending a message 
through it. This is testing a *template's content*, with no receiver involved 
and nothing sent — a different concern.
   
   ### Testing
   
   - Added `previewNoticeTemplate` / `previewNoticeTemplateWithInvalidContent` 
to `NoticeConfigControllerTest`, covering the success path and the 
malformed-template-syntax path.
   - Ran the full `hertzbeat-alerter` test suite (459 tests) after the 
extraction — it caught a real regression on my first pass: pulling 
`renderContent` into a static utility that re-fetched 
`ResourceBundleUtil.getBundle("alerter")` internally silently dropped the 
per-instance `bundle` field that `AbstractAlertNotifyHandlerImpl` subclasses 
(and their tests) inject/mock. Fixed by passing the `ResourceBundle` through as 
a parameter instead of having the utility fetch it itself. All 459 tests pass 
after the fix.
   - `checkstyle:check` — 0 violations.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to