Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

QS: logs pipelines preview http handler (#3701)

Raj Kamal Singha84a70df140d
diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.go
index 0f6b7f3090..87f05ab098 100644
--- a/pkg/query-service/app/http_handler.go
+++ b/pkg/query-service/app/http_handler.go
@@ -2320,6 +2320,7 @@ func (aH *APIHandler) RegisterLogsRoutes(router *mux.Router, am *AuthMiddleware)
subRouter.HandleFunc("/aggregate", am.ViewAccess(aH.logAggregate)).Methods(http.MethodGet)
// log pipelines
+ subRouter.HandleFunc("/pipelines/preview", am.ViewAccess(aH.PreviewLogsPipelinesHandler)).Methods(http.MethodPost)
subRouter.HandleFunc("/pipelines/{version}", am.ViewAccess(aH.ListLogsPipelinesHandler)).Methods(http.MethodGet)
subRouter.HandleFunc("/pipelines", am.EditAccess(aH.CreateLogsPipeline)).Methods(http.MethodPost)
}
@@ -2455,6 +2456,26 @@ func parseAgentConfigVersion(r *http.Request) (int, *model.ApiError) {
return int(version64), nil
}
+func (ah *APIHandler) PreviewLogsPipelinesHandler(w http.ResponseWriter, r *http.Request) {
+ req := logparsingpipeline.PipelinesPreviewRequest{}
+
+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
+ RespondError(w, model.BadRequest(err), nil)
+ return
+ }
+
+ resultLogs, apiErr := ah.LogsParsingPipelineController.PreviewLogsPipelines(
+ r.Context(), &req,
+ )
+
+ if apiErr != nil {
+ RespondError(w, apiErr, nil)
+ return
+ }
+
+ ah.Respond(w, resultLogs)
+}
+
func (ah *APIHandler) ListLogsPipelinesHandler(w http.ResponseWriter, r *http.Request) {
version, err := parseAgentConfigVersion(r)
diff --git a/pkg/query-service/app/logparsingpipeline/controller.go b/pkg/query-service/app/logparsingpipeline/controller.go
index 2aa036b394..fc10047c36 100644
--- a/pkg/query-service/app/logparsingpipeline/controller.go
+++ b/pkg/query-service/app/logparsingpipeline/controller.go
@@ -140,3 +140,29 @@ func (ic *LogParsingPipelineController) GetPipelinesByVersion(
Pipelines: pipelines,
}, nil
}
+
+type PipelinesPreviewRequest struct {
+ Pipelines []Pipeline `json:"pipelines"`
+ Logs []model.SignozLog `json:"logs"`
+}
+
+type PipelinesPreviewResponse struct {
+ OutputLogs []model.SignozLog `json:"logs"`
+}
+
+func (ic *LogParsingPipelineController) PreviewLogsPipelines(
+ ctx context.Context,
+ request *PipelinesPreviewRequest,
+) (*PipelinesPreviewResponse, *model.ApiError) {
+ result, err := SimulatePipelinesProcessing(
+ ctx, request.Pipelines, request.Logs,
+ )
+
+ if err != nil {
+ return nil, err
+ }
+
+ return &PipelinesPreviewResponse{
+ OutputLogs: result,
+ }, nil
+}