mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 17:45:55 +08:00
fix: use query-service API to fetch triggered alerts (#3417)
This commit is contained in:
parent
0bee0a6d90
commit
7586b50c5a
@ -24,10 +24,6 @@ server {
|
|||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/alertmanager {
|
|
||||||
proxy_pass http://alertmanager:9093/api/v2;
|
|
||||||
}
|
|
||||||
|
|
||||||
location ~ ^/api/(v1|v3)/logs/(tail|livetail){
|
location ~ ^/api/(v1|v3)/logs/(tail|livetail){
|
||||||
proxy_pass http://query-service:8080;
|
proxy_pass http://query-service:8080;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
@ -24,10 +24,6 @@ server {
|
|||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/alertmanager {
|
|
||||||
proxy_pass http://alertmanager:9093/api/v2;
|
|
||||||
}
|
|
||||||
|
|
||||||
location ~ ^/api/(v1|v3)/logs/(tail|livetail){
|
location ~ ^/api/(v1|v3)/logs/(tail|livetail){
|
||||||
proxy_pass http://query-service:8080;
|
proxy_pass http://query-service:8080;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { AxiosAlertManagerInstance } from 'api';
|
import axios from 'api';
|
||||||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import convertObjectIntoParams from 'lib/query/convertObjectIntoParams';
|
import convertObjectIntoParams from 'lib/query/convertObjectIntoParams';
|
||||||
@ -11,15 +11,15 @@ const getTriggered = async (
|
|||||||
try {
|
try {
|
||||||
const queryParams = convertObjectIntoParams(props);
|
const queryParams = convertObjectIntoParams(props);
|
||||||
|
|
||||||
const response = await AxiosAlertManagerInstance.get(
|
const response = await axios.get(`/alerts?${queryParams}`);
|
||||||
`/alerts?${queryParams}`,
|
|
||||||
);
|
const amData = JSON.parse(response.data.data);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
error: null,
|
error: null,
|
||||||
message: response.data.status,
|
message: response.data.status,
|
||||||
payload: response.data,
|
payload: amData.data,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return ErrorResponseHandler(error as AxiosError);
|
return ErrorResponseHandler(error as AxiosError);
|
||||||
|
@ -319,6 +319,8 @@ func (aH *APIHandler) RegisterRoutes(router *mux.Router, am *AuthMiddleware) {
|
|||||||
router.HandleFunc("/api/v1/channels", am.EditAccess(aH.createChannel)).Methods(http.MethodPost)
|
router.HandleFunc("/api/v1/channels", am.EditAccess(aH.createChannel)).Methods(http.MethodPost)
|
||||||
router.HandleFunc("/api/v1/testChannel", am.EditAccess(aH.testChannel)).Methods(http.MethodPost)
|
router.HandleFunc("/api/v1/testChannel", am.EditAccess(aH.testChannel)).Methods(http.MethodPost)
|
||||||
|
|
||||||
|
router.HandleFunc("/api/v1/alerts", am.ViewAccess(aH.getAlerts)).Methods(http.MethodGet)
|
||||||
|
|
||||||
router.HandleFunc("/api/v1/rules", am.ViewAccess(aH.listRules)).Methods(http.MethodGet)
|
router.HandleFunc("/api/v1/rules", am.ViewAccess(aH.listRules)).Methods(http.MethodGet)
|
||||||
router.HandleFunc("/api/v1/rules/{id}", am.ViewAccess(aH.getRule)).Methods(http.MethodGet)
|
router.HandleFunc("/api/v1/rules/{id}", am.ViewAccess(aH.getRule)).Methods(http.MethodGet)
|
||||||
router.HandleFunc("/api/v1/rules", am.EditAccess(aH.createRule)).Methods(http.MethodPost)
|
router.HandleFunc("/api/v1/rules", am.EditAccess(aH.createRule)).Methods(http.MethodPost)
|
||||||
@ -1195,6 +1197,25 @@ func (aH *APIHandler) createChannel(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aH *APIHandler) getAlerts(w http.ResponseWriter, r *http.Request) {
|
||||||
|
params := r.URL.Query()
|
||||||
|
amEndpoint := constants.GetAlertManagerApiPrefix()
|
||||||
|
resp, err := http.Get(amEndpoint + "v1/alerts" + "?" + params.Encode())
|
||||||
|
if err != nil {
|
||||||
|
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
aH.Respond(w, string(body))
|
||||||
|
}
|
||||||
|
|
||||||
func (aH *APIHandler) createRule(w http.ResponseWriter, r *http.Request) {
|
func (aH *APIHandler) createRule(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user