Merge branch 'develop' into issue-3400-ui-horizontal-scroll-logs-context

This commit is contained in:
Palash Gupta 2023-08-24 18:35:51 +05:30 committed by GitHub
commit 23f94538c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 22 deletions

View File

@ -24,10 +24,6 @@ server {
try_files $uri $uri/ /index.html;
}
location /api/alertmanager {
proxy_pass http://alertmanager:9093/api/v2;
}
location ~ ^/api/(v1|v3)/logs/(tail|livetail){
proxy_pass http://query-service:8080;
proxy_http_version 1.1;

View File

@ -24,10 +24,6 @@ server {
try_files $uri $uri/ /index.html;
}
location /api/alertmanager {
proxy_pass http://alertmanager:9093/api/v2;
}
location ~ ^/api/(v1|v3)/logs/(tail|livetail){
proxy_pass http://query-service:8080;
proxy_http_version 1.1;

View File

@ -1,4 +1,4 @@
import { AxiosAlertManagerInstance } from 'api';
import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import convertObjectIntoParams from 'lib/query/convertObjectIntoParams';
@ -11,15 +11,15 @@ const getTriggered = async (
try {
const queryParams = convertObjectIntoParams(props);
const response = await AxiosAlertManagerInstance.get(
`/alerts?${queryParams}`,
);
const response = await axios.get(`/alerts?${queryParams}`);
const amData = JSON.parse(response.data.data);
return {
statusCode: 200,
error: null,
message: response.data.status,
payload: response.data,
payload: amData.data,
};
} catch (error) {
return ErrorResponseHandler(error as AxiosError);

View File

@ -49,7 +49,7 @@ func InitDB(dataSourceName string) (*sqlx.DB, error) {
_, err = db.Exec(table_schema)
if err != nil {
return nil, fmt.Errorf("Error in creating dashboard table: %s", err.Error())
return nil, fmt.Errorf("error in creating dashboard table: %s", err.Error())
}
table_schema = `CREATE TABLE IF NOT EXISTS rules (
@ -61,7 +61,7 @@ func InitDB(dataSourceName string) (*sqlx.DB, error) {
_, err = db.Exec(table_schema)
if err != nil {
return nil, fmt.Errorf("Error in creating rules table: %s", err.Error())
return nil, fmt.Errorf("error in creating rules table: %s", err.Error())
}
table_schema = `CREATE TABLE IF NOT EXISTS notification_channels (
@ -76,7 +76,7 @@ func InitDB(dataSourceName string) (*sqlx.DB, error) {
_, err = db.Exec(table_schema)
if err != nil {
return nil, fmt.Errorf("Error in creating notification_channles table: %s", err.Error())
return nil, fmt.Errorf("error in creating notification_channles table: %s", err.Error())
}
table_schema = `CREATE TABLE IF NOT EXISTS ttl_status (
@ -92,7 +92,7 @@ func InitDB(dataSourceName string) (*sqlx.DB, error) {
_, err = db.Exec(table_schema)
if err != nil {
return nil, fmt.Errorf("Error in creating ttl_status table: %s", err.Error())
return nil, fmt.Errorf("error in creating ttl_status table: %s", err.Error())
}
return db, nil
@ -179,7 +179,7 @@ func CreateDashboard(data map[string]interface{}, fm interfaces.FeatureLookup) (
func GetDashboards() ([]Dashboard, *model.ApiError) {
dashboards := []Dashboard{}
query := fmt.Sprintf("SELECT * FROM dashboards;")
query := `SELECT * FROM dashboards`
err := db.Select(&dashboards, query)
if err != nil {
@ -197,9 +197,9 @@ func DeleteDashboard(uuid string, fm interfaces.FeatureLookup) *model.ApiError {
return dErr
}
query := fmt.Sprintf("DELETE FROM dashboards WHERE uuid='%s';", uuid)
query := `DELETE FROM dashboards WHERE uuid=?`
result, err := db.Exec(query)
result, err := db.Exec(query, uuid)
if err != nil {
return &model.ApiError{Typ: model.ErrorExec, Err: err}
@ -224,9 +224,9 @@ func DeleteDashboard(uuid string, fm interfaces.FeatureLookup) *model.ApiError {
func GetDashboard(uuid string) (*Dashboard, *model.ApiError) {
dashboard := Dashboard{}
query := fmt.Sprintf("SELECT * FROM dashboards WHERE uuid='%s';", uuid)
query := `SELECT * FROM dashboards WHERE uuid=?`
err := db.Get(&dashboard, query)
err := db.Get(&dashboard, query, uuid)
if err != nil {
return nil, &model.ApiError{Typ: model.ErrorNotFound, Err: fmt.Errorf("no dashboard found with uuid: %s", uuid)}
}

View File

@ -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/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/{id}", am.ViewAccess(aH.getRule)).Methods(http.MethodGet)
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) {
defer r.Body.Close()