mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 18:09:07 +08:00
feat: ingestion key management (#3699)
This commit is contained in:
parent
b12365ba07
commit
dcea79cef3
@ -377,6 +377,8 @@ func (aH *APIHandler) RegisterRoutes(router *mux.Router, am *AuthMiddleware) {
|
||||
router.HandleFunc("/api/v1/settings/ttl", am.ViewAccess(aH.getTTL)).Methods(http.MethodGet)
|
||||
router.HandleFunc("/api/v1/settings/apdex", am.AdminAccess(aH.setApdexSettings)).Methods(http.MethodPost)
|
||||
router.HandleFunc("/api/v1/settings/apdex", am.ViewAccess(aH.getApdexSettings)).Methods(http.MethodGet)
|
||||
router.HandleFunc("/api/v1/settings/ingestion_key", am.AdminAccess(aH.insertIngestionKey)).Methods(http.MethodPost)
|
||||
router.HandleFunc("/api/v1/settings/ingestion_key", am.ViewAccess(aH.getIngestionKeys)).Methods(http.MethodGet)
|
||||
|
||||
router.HandleFunc("/api/v1/metric_meta", am.ViewAccess(aH.getLatencyMetricMetadata)).Methods(http.MethodGet)
|
||||
|
||||
|
33
pkg/query-service/app/ingestion_key.go
Normal file
33
pkg/query-service/app/ingestion_key.go
Normal file
@ -0,0 +1,33 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"go.signoz.io/signoz/pkg/query-service/dao"
|
||||
"go.signoz.io/signoz/pkg/query-service/model"
|
||||
)
|
||||
|
||||
func (aH *APIHandler) insertIngestionKey(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := parseInsertIngestionKeyRequest(r)
|
||||
if aH.HandleError(w, err, http.StatusBadRequest) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := dao.DB().InsertIngestionKey(context.Background(), req); err != nil {
|
||||
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorInternal}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
aH.WriteJSON(w, r, map[string]string{"data": "ingestion key added successfully"})
|
||||
}
|
||||
|
||||
func (aH *APIHandler) getIngestionKeys(w http.ResponseWriter, r *http.Request) {
|
||||
ingestionKeys, err := dao.DB().GetIngestionKeys(context.Background())
|
||||
if err != nil {
|
||||
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorInternal}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
aH.WriteJSON(w, r, ingestionKeys)
|
||||
}
|
@ -734,6 +734,14 @@ func parseSetApdexScoreRequest(r *http.Request) (*model.ApdexSettings, error) {
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
func parseInsertIngestionKeyRequest(r *http.Request) (*model.IngestionKey, error) {
|
||||
var req model.IngestionKey
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
func parseRegisterRequest(r *http.Request) (*auth.RegisterRequest, error) {
|
||||
var req auth.RegisterRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
|
@ -35,6 +35,8 @@ type Queries interface {
|
||||
|
||||
GetApdexSettings(ctx context.Context, services []string) ([]model.ApdexSettings, *model.ApiError)
|
||||
|
||||
GetIngestionKeys(ctx context.Context) ([]model.IngestionKey, *model.ApiError)
|
||||
|
||||
PrecheckLogin(ctx context.Context, email, sourceUrl string) (*model.PrecheckResponse, model.BaseApiError)
|
||||
}
|
||||
|
||||
@ -62,4 +64,6 @@ type Mutations interface {
|
||||
UpdateUserGroup(ctx context.Context, userId, groupId string) *model.ApiError
|
||||
|
||||
SetApdexSettings(ctx context.Context, set *model.ApdexSettings) *model.ApiError
|
||||
|
||||
InsertIngestionKey(ctx context.Context, ingestionKey *model.IngestionKey) *model.ApiError
|
||||
}
|
||||
|
@ -78,6 +78,14 @@ func InitDB(dataSourceName string) (*ModelDaoSqlite, error) {
|
||||
threshold FLOAT NOT NULL,
|
||||
exclude_status_codes TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS ingestion_keys (
|
||||
key_id TEXT PRIMARY KEY,
|
||||
name TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
ingestion_key TEXT NOT NULL,
|
||||
ingestion_url TEXT NOT NULL,
|
||||
data_region TEXT NOT NULL
|
||||
);
|
||||
`
|
||||
|
||||
_, err = db.Exec(table_schema)
|
||||
|
39
pkg/query-service/dao/sqlite/ingestion.go
Normal file
39
pkg/query-service/dao/sqlite/ingestion.go
Normal file
@ -0,0 +1,39 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.signoz.io/signoz/pkg/query-service/model"
|
||||
)
|
||||
|
||||
func (mds *ModelDaoSqlite) GetIngestionKeys(ctx context.Context) ([]model.IngestionKey, *model.ApiError) {
|
||||
ingestion_keys := []model.IngestionKey{}
|
||||
err := mds.db.Select(&ingestion_keys, `SELECT * FROM ingestion_keys`)
|
||||
|
||||
if err != nil {
|
||||
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
|
||||
}
|
||||
return ingestion_keys, nil
|
||||
}
|
||||
|
||||
func (mds *ModelDaoSqlite) InsertIngestionKey(ctx context.Context, ingestion_key *model.IngestionKey) *model.ApiError {
|
||||
_, err := mds.db.ExecContext(ctx, `
|
||||
INSERT INTO ingestion_keys (
|
||||
ingestion_key,
|
||||
name,
|
||||
key_id,
|
||||
ingestion_url,
|
||||
data_region
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`, ingestion_key.IngestionKey, ingestion_key.Name, ingestion_key.KeyId, ingestion_key.IngestionURL, ingestion_key.DataRegion)
|
||||
if err != nil {
|
||||
return &model.ApiError{Typ: model.ErrorInternal, Err: err}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Organization struct {
|
||||
@ -42,6 +43,15 @@ type ApdexSettings struct {
|
||||
ExcludeStatusCodes string `json:"excludeStatusCodes" db:"exclude_status_codes"` // sqlite doesn't support array type
|
||||
}
|
||||
|
||||
type IngestionKey struct {
|
||||
KeyId string `json:"keyId" db:"key_id"`
|
||||
Name string `json:"name" db:"name"`
|
||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||
IngestionKey string `json:"ingestionKey" db:"ingestion_key"`
|
||||
IngestionURL string `json:"ingestionURL" db:"ingestion_url"`
|
||||
DataRegion string `json:"dataRegion" db:"data_region"`
|
||||
}
|
||||
|
||||
type UserFlag map[string]string
|
||||
|
||||
func (uf UserFlag) Value() (driver.Value, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user