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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix(logs pipelines): Migrate model.APIErrors to errors (#9598)
Piyush Singariya4bfd7ba3d770
diff --git a/pkg/query-service/agentConf/agent_features.go b/pkg/query-service/agentConf/agent_features.goindex 9f68d579b4..459b20aa6f 100644--- a/pkg/query-service/agentConf/agent_features.go+++ b/pkg/query-service/agentConf/agent_features.go@@ -1,7 +1,6 @@package agentConfimport (- "github.com/SigNoz/signoz/pkg/query-service/model""github.com/SigNoz/signoz/pkg/types/opamptypes""github.com/SigNoz/signoz/pkg/valuer")@@ -25,6 +24,6 @@ type AgentFeature interface {// TODO(Raj): maybe refactor agentConf further and clean this upserializedSettingsUsed string,- apiErr *model.ApiError,+ err error,)}diff --git a/pkg/query-service/agentConf/db.go b/pkg/query-service/agentConf/db.goindex 511e7f0ef9..c64355ef2a 100644--- a/pkg/query-service/agentConf/db.go+++ b/pkg/query-service/agentConf/db.go@@ -7,16 +7,26 @@ import ("strings""time"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/query-service/model""github.com/SigNoz/signoz/pkg/sqlstore""github.com/SigNoz/signoz/pkg/types""github.com/SigNoz/signoz/pkg/types/opamptypes""github.com/SigNoz/signoz/pkg/valuer"- "github.com/pkg/errors""go.uber.org/zap""golang.org/x/exp/slices")+var (+ CodeConfigVersionNotFound = errors.MustNewCode("config_version_not_found")+ CodeElementTypeRequired = errors.MustNewCode("element_type_required")+ CodeConfigElementsRequired = errors.MustNewCode("config_elements_required")+ CodeConfigVersionInsertFailed = errors.MustNewCode("config_version_insert_failed")+ CodeConfigElementInsertFailed = errors.MustNewCode("config_element_insert_failed")+ CodeConfigDeployStatusUpdateFailed = errors.MustNewCode("config_deploy_status_update_failed")+ CodeConfigHistoryGetFailed = errors.MustNewCode("config_history_get_failed")+)+// Repo handles DDL and DML ops on ingestion rulestype Repo struct {store sqlstore.SQLStore@@ -24,7 +34,7 @@ type Repo struct {func (r *Repo) GetConfigHistory(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementType, limit int,-) ([]opamptypes.AgentConfigVersion, *model.ApiError) {+) ([]opamptypes.AgentConfigVersion, error) {var c []opamptypes.AgentConfigVersionerr := r.store.BunDB().NewSelect().Model(&c).@@ -39,7 +49,7 @@ func (r *Repo) GetConfigHistory(Scan(ctx)if err != nil {- return nil, model.InternalError(err)+ return nil, errors.WrapInternalf(err, CodeConfigHistoryGetFailed, "failed to get config history")}incompleteStatuses := []opamptypes.DeployStatus{opamptypes.DeployInitiated, opamptypes.Deploying}@@ -54,7 +64,7 @@ func (r *Repo) GetConfigHistory(func (r *Repo) GetConfigVersion(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementType, v int,-) (*opamptypes.AgentConfigVersion, *model.ApiError) {+) (*opamptypes.AgentConfigVersion, error) {var c opamptypes.AgentConfigVersionerr := r.store.BunDB().NewSelect().Model(&c).@@ -69,9 +79,9 @@ func (r *Repo) GetConfigVersion(if err != nil {if errors.Is(err, sql.ErrNoRows) {- return nil, model.NotFoundError(err)+ return nil, errors.WrapNotFoundf(err, CodeConfigVersionNotFound, "config version not found")}- return nil, model.InternalError(err)+ return nil, errors.WrapInternalf(err, errors.CodeInternal, "failed to get config version")}return &c, nil@@ -79,7 +89,7 @@ func (r *Repo) GetConfigVersion(func (r *Repo) GetLatestVersion(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementType,-) (*opamptypes.AgentConfigVersion, *model.ApiError) {+) (*opamptypes.AgentConfigVersion, error) {var c opamptypes.AgentConfigVersionerr := r.store.BunDB().NewSelect().Model(&c).@@ -93,9 +103,9 @@ func (r *Repo) GetLatestVersion(if err != nil {if errors.Is(err, sql.ErrNoRows) {- return nil, model.NotFoundError(err)+ return nil, errors.WrapNotFoundf(err, CodeConfigVersionNotFound, "config latest version not found")}- return nil, model.InternalError(err)+ return nil, errors.WrapInternalf(err, errors.CodeInternal, "failed to get latest config version")}return &c, nil@@ -103,18 +113,16 @@ func (r *Repo) GetLatestVersion(func (r *Repo) insertConfig(ctx context.Context, orgId valuer.UUID, userId valuer.UUID, c *opamptypes.AgentConfigVersion, elements []string,-) (fnerr *model.ApiError) {+) error {if c.ElementType.StringValue() == "" {- return model.BadRequest(fmt.Errorf(- "element type is required for creating agent config version",- ))+ return errors.NewInvalidInputf(CodeElementTypeRequired, "element type is required for creating agent config version")}// allowing empty elements for logs - use case is deleting all pipelinesif len(elements) == 0 && c.ElementType != opamptypes.ElementTypeLogPipelines {zap.L().Error("insert config called with no elements ", zap.String("ElementType", c.ElementType.StringValue()))- return model.BadRequest(fmt.Errorf("config must have atleast one element"))+ return errors.NewInvalidInputf(CodeConfigElementsRequired, "config must have atleast one element")}if c.Version != 0 {@@ -122,15 +130,13 @@ func (r *Repo) insertConfig(// in a monotonically increasing order starting with 1. hence, we reject insert// requests with version anything other than 0. here, 0 indicates un-assignedzap.L().Error("invalid version assignment while inserting agent config", zap.Int("version", c.Version), zap.String("ElementType", c.ElementType.StringValue()))- return model.BadRequest(fmt.Errorf(- "user defined versions are not supported in the agent config",- ))+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "user defined versions are not supported in the agent config")}configVersion, err := r.GetLatestVersion(ctx, orgId, c.ElementType)- if err != nil && err.Type() != model.ErrorNotFound {+ if err != nil && !errors.Ast(err, errors.TypeNotFound) {zap.L().Error("failed to fetch latest config version", zap.Error(err))- return model.InternalError(fmt.Errorf("failed to fetch latest config version"))+ return err}if configVersion != nil {@@ -141,7 +147,7 @@ func (r *Repo) insertConfig(}defer func() {- if fnerr != nil {+ if err != nil {// remove all the damage (invalid rows from db)r.store.BunDB().NewDelete().Model(new(opamptypes.AgentConfigVersion)).Where("id = ?", c.ID).Where("org_id = ?", orgId).Exec(ctx)r.store.BunDB().NewDelete().Model(new(opamptypes.AgentConfigElement)).Where("version_id = ?", c.ID).Exec(ctx)@@ -153,10 +159,9 @@ func (r *Repo) insertConfig(NewInsert().Model(c).Exec(ctx)-if dbErr != nil {zap.L().Error("error in inserting config version: ", zap.Error(dbErr))- return model.InternalError(errors.Wrap(dbErr, "failed to insert ingestion rule"))+ return errors.WrapInternalf(dbErr, CodeConfigVersionInsertFailed, "failed to insert config version")}for _, e := range elements {@@ -172,7 +177,7 @@ func (r *Repo) insertConfig(}_, dbErr = r.store.BunDB().NewInsert().Model(agentConfigElement).Exec(ctx)if dbErr != nil {- return model.InternalError(dbErr)+ return errors.WrapInternalf(dbErr, CodeConfigElementInsertFailed, "failed to insert config element")}}@@ -214,8 +219,7 @@ func (r *Repo) updateDeployStatus(ctx context.Context,func (r *Repo) updateDeployStatusByHash(ctx context.Context, orgId valuer.UUID, confighash string, status string, result string,-) *model.ApiError {-+) error {_, err := r.store.BunDB().NewUpdate().Model(new(opamptypes.AgentConfigVersion)).Set("deploy_status = ?", status).@@ -225,7 +229,7 @@ func (r *Repo) updateDeployStatusByHash(Exec(ctx)if err != nil {zap.L().Error("failed to update deploy status", zap.Error(err))- return model.InternalError(errors.Wrap(err, "failed to update deploy status"))+ return errors.WrapInternalf(err, CodeConfigDeployStatusUpdateFailed, "failed to update deploy status")}return nildiff --git a/pkg/query-service/agentConf/manager.go b/pkg/query-service/agentConf/manager.goindex c69bc49b0e..6658f9f13c 100644--- a/pkg/query-service/agentConf/manager.go+++ b/pkg/query-service/agentConf/manager.go@@ -8,6 +8,7 @@ import ("sync""sync/atomic"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/query-service/app/opamp"filterprocessor "github.com/SigNoz/signoz/pkg/query-service/app/opamp/otelconfig/filterprocessor"tsp "github.com/SigNoz/signoz/pkg/query-service/app/opamp/otelconfig/tailsampler"@@ -16,13 +17,16 @@ import ("github.com/SigNoz/signoz/pkg/types/opamptypes""github.com/SigNoz/signoz/pkg/valuer""github.com/google/uuid"- "github.com/pkg/errors""go.uber.org/zap"yaml "gopkg.in/yaml.v3")var m *Manager+var (+ CodeConfigVersionNoConfig = errors.MustNewCode("config_version_no_config")+)+func init() {m = &Manager{}}@@ -103,16 +107,14 @@ func (m *Manager) RecommendAgentConfig(orgId valuer.UUID, currentConfYaml []bytefor _, feature := range m.agentFeatures {featureType := opamptypes.NewElementType(string(feature.AgentFeatureType()))- latestConfig, apiErr := GetLatestVersion(context.Background(), orgId, featureType)- if apiErr != nil && apiErr.Type() != model.ErrorNotFound {- return nil, "", errors.Wrap(apiErr.ToError(), "failed to get latest agent config version")+ latestConfig, err := GetLatestVersion(context.Background(), orgId, featureType)+ if err != nil && !errors.Ast(err, errors.TypeNotFound) {+ return nil, "", err}- updatedConf, serializedSettingsUsed, apiErr := feature.RecommendAgentConfig(orgId, recommendation, latestConfig)- if apiErr != nil {- return nil, "", errors.Wrap(apiErr.ToError(), fmt.Sprintf(- "failed to generate agent config recommendation for %s", featureType,- ))+ updatedConf, serializedSettingsUsed, err := feature.RecommendAgentConfig(orgId, recommendation, latestConfig)+ if err != nil {+ return nil, "", errors.WithAdditionalf(err, "agent config recommendation for %s failed", featureType)}recommendation = updatedConf@@ -178,26 +180,26 @@ func (m *Manager) ReportConfigDeploymentStatus(func GetLatestVersion(ctx context.Context, orgId valuer.UUID, elementType opamptypes.ElementType,-) (*opamptypes.AgentConfigVersion, *model.ApiError) {+) (*opamptypes.AgentConfigVersion, error) {return m.GetLatestVersion(ctx, orgId, elementType)}func GetConfigVersion(ctx context.Context, orgId valuer.UUID, elementType opamptypes.ElementType, version int,-) (*opamptypes.AgentConfigVersion, *model.ApiError) {+) (*opamptypes.AgentConfigVersion, error) {return m.GetConfigVersion(ctx, orgId, elementType, version)}func GetConfigHistory(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementType, limit int,-) ([]opamptypes.AgentConfigVersion, *model.ApiError) {+) ([]opamptypes.AgentConfigVersion, error) {return m.GetConfigHistory(ctx, orgId, typ, limit)}// StartNewVersion launches a new config version for given set of elementsfunc StartNewVersion(ctx context.Context, orgId valuer.UUID, userId valuer.UUID, eleType opamptypes.ElementType, elementIds []string,-) (*opamptypes.AgentConfigVersion, *model.ApiError) {+) (*opamptypes.AgentConfigVersion, error) {// create a new versioncfg := opamptypes.NewAgentConfigVersion(orgId, userId, eleType)@@ -217,17 +219,16 @@ func NotifyConfigUpdate(ctx context.Context) {m.notifyConfigUpdateSubscribers()}-func Redeploy(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementType, version int) *model.ApiError {-+func Redeploy(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementType, version int) error {configVersion, err := GetConfigVersion(ctx, orgId, typ, version)if err != nil {zap.L().Error("failed to fetch config version during redeploy", zap.Error(err))- return model.WrapApiError(err, "failed to fetch details of the config version")+ return err}if configVersion == nil || (configVersion != nil && configVersion.Config == "") {zap.L().Debug("config version has no conf yaml", zap.Any("configVersion", configVersion))- return model.BadRequest(fmt.Errorf("the config version can not be redeployed"))+ return errors.NewInvalidInputf(CodeConfigVersionNoConfig, "the config version can not be redeployed")}switch typ {case opamptypes.ElementTypeSamplingRules:@@ -246,7 +247,7 @@ func Redeploy(ctx context.Context, orgId valuer.UUID, typ opamptypes.ElementTypeconfigHash, err := opamp.UpsertControlProcessors(ctx, "traces", processorConf, m.OnConfigUpdate)if err != nil {zap.L().Error("failed to call agent config update for trace processor", zap.Error(err))- return model.InternalError(fmt.Errorf("failed to deploy the config"))+ return errors.WithAdditionalf(err, "failed to deploy the config")}m.updateDeployStatus(ctx, orgId, opamptypes.ElementTypeSamplingRules, version, opamptypes.DeployInitiated.StringValue(), "Deployment started", configHash, configVersion.Config)diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.goindex ad896188fb..bf22a5b648 100644--- a/pkg/query-service/app/http_handler.go+++ b/pkg/query-service/app/http_handler.go@@ -5,9 +5,9 @@ import ("context""database/sql""encoding/json"- "errors""fmt"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/modules/thirdpartyapi""io"@@ -1791,7 +1791,7 @@ func (aH *APIHandler) GetWaterfallSpansForTraceWithMetadata(w http.ResponseWrite}traceID := mux.Vars(r)["traceId"]if traceID == "" {- RespondError(w, model.BadRequest(errors.New("traceID is required")), nil)+ render.Error(w, errors.NewInvalidInputf(errors.CodeInvalidInput, "traceID is required"))return}@@ -1825,7 +1825,7 @@ func (aH *APIHandler) GetFlamegraphSpansForTrace(w http.ResponseWriter, r *http.traceID := mux.Vars(r)["traceId"]if traceID == "" {- RespondError(w, model.BadRequest(errors.New("traceID is required")), nil)+ render.Error(w, errors.NewInvalidInputf(errors.CodeInvalidInput, "traceID is required"))return}@@ -1926,9 +1926,9 @@ func (aH *APIHandler) setTTL(w http.ResponseWriter, r *http.Request) {}ctx := r.Context()- claims, errv2 := authtypes.ClaimsFromContext(ctx)- if errv2 != nil {- RespondError(w, &model.ApiError{Err: errors.New("failed to get org id from context"), Typ: model.ErrorInternal}, nil)+ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(w, errors.NewInternalf(errors.CodeInternal, "failed to get org id from context"))return}@@ -1995,17 +1995,16 @@ func (aH *APIHandler) getTTL(w http.ResponseWriter, r *http.Request) {}ctx := r.Context()- claims, errv2 := authtypes.ClaimsFromContext(ctx)- if errv2 != nil {- RespondError(w, &model.ApiError{Err: errors.New("failed to get org id from context"), Typ: model.ErrorInternal}, nil)+ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(w, err)return}-- result, apiErr := aH.reader.GetTTL(r.Context(), claims.OrgID, ttlParams)- if apiErr != nil && aH.HandleError(w, apiErr.Err, http.StatusInternalServerError) {+ result, err := aH.reader.GetTTL(r.Context(), claims.OrgID, ttlParams)+ if err != nil {+ render.Error(w, err)return}-aH.WriteJSON(w, r, result)}@@ -2070,7 +2069,7 @@ func (aH *APIHandler) getHealth(w http.ResponseWriter, r *http.Request) {func (aH *APIHandler) registerUser(w http.ResponseWriter, r *http.Request) {if aH.SetupCompleted {- RespondError(w, &model.ApiError{Err: errors.New("self-registration is disabled"), Typ: model.ErrorBadData}, nil)+ render.Error(w, errors.NewInvalidInputf(errors.CodeInvalidInput, "self-registration is disabled"))return}@@ -3453,7 +3452,7 @@ func (aH *APIHandler) InstallIntegration(w http.ResponseWriter, r *http.Request)}claims, err := authtypes.ClaimsFromContext(r.Context())if err != nil {- RespondError(w, model.UnauthorizedError(errors.New("unauthorized")), nil)+ render.Error(w, err)return}@@ -4064,7 +4063,7 @@ func (aH *APIHandler) logAggregate(w http.ResponseWriter, r *http.Request) {aH.WriteJSON(w, r, model.GetLogsAggregatesResponse{})}-func parseAgentConfigVersion(r *http.Request) (int, *model.ApiError) {+func parseAgentConfigVersion(r *http.Request) (int, error) {versionString := mux.Vars(r)["version"]if versionString == "latest" {@@ -4074,11 +4073,11 @@ func parseAgentConfigVersion(r *http.Request) (int, *model.ApiError) {version64, err := strconv.ParseInt(versionString, 0, 8)if err != nil {- return 0, model.BadRequestStr("invalid version number")+ return 0, errors.WrapInvalidInputf(err, errors.CodeInvalidInput, "invalid version number")}if version64 <= 0 {- return 0, model.BadRequestStr("invalid version number")+ return 0, errors.NewInvalidInputf(errors.CodeInvalidInput, "invalid version number")}return int(version64), nil@@ -4088,16 +4087,13 @@ func (aH *APIHandler) PreviewLogsPipelinesHandler(w http.ResponseWriter, r *httpreq := logparsingpipeline.PipelinesPreviewRequest{}if err := json.NewDecoder(r.Body).Decode(&req); err != nil {- RespondError(w, model.BadRequest(err), nil)+ render.Error(w, errors.WrapInvalidInputf(err, errors.CodeInvalidInput, "failed to decode request body"))return}- resultLogs, apiErr := aH.LogsParsingPipelineController.PreviewLogsPipelines(- r.Context(), &req,- )-- if apiErr != nil {- RespondError(w, apiErr, nil)+ resultLogs, err := aH.LogsParsingPipelineController.PreviewLogsPipelines(r.Context(), &req)+ if err != nil {+ render.Error(w, err)return}@@ -4105,9 +4101,9 @@ func (aH *APIHandler) PreviewLogsPipelinesHandler(w http.ResponseWriter, r *http}func (aH *APIHandler) ListLogsPipelinesHandler(w http.ResponseWriter, r *http.Request) {- claims, errv2 := authtypes.ClaimsFromContext(r.Context())- if errv2 != nil {- render.Error(w, errv2)+ claims, err := authtypes.ClaimsFromContext(r.Context())+ if err != nil {+ render.Error(w, err)return}@@ -4119,35 +4115,33 @@ func (aH *APIHandler) ListLogsPipelinesHandler(w http.ResponseWriter, r *http.Reversion, err := parseAgentConfigVersion(r)if err != nil {- RespondError(w, model.WrapApiError(err, "Failed to parse agent config version"), nil)+ render.Error(w, err)return}var payload *logparsingpipeline.PipelinesResponse- var apierr *model.ApiError-if version != -1 {- payload, apierr = aH.listLogsPipelinesByVersion(context.Background(), orgID, version)+ payload, err = aH.listLogsPipelinesByVersion(r.Context(), orgID, version)} else {- payload, apierr = aH.listLogsPipelines(context.Background(), orgID)+ payload, err = aH.listLogsPipelines(r.Context(), orgID)}-- if apierr != nil {- RespondError(w, apierr, payload)+ if err != nil {+ render.Error(w, err)return}+aH.Respond(w, payload)}// listLogsPipelines lists logs piplines for latest versionfunc (aH *APIHandler) listLogsPipelines(ctx context.Context, orgID valuer.UUID) (- *logparsingpipeline.PipelinesResponse, *model.ApiError,+ *logparsingpipeline.PipelinesResponse, error,) {// get lateset agent configlatestVersion := -1lastestConfig, err := agentConf.GetLatestVersion(ctx, orgID, opamptypes.ElementTypeLogPipelines)- if err != nil && err.Type() != model.ErrorNotFound {- return nil, model.WrapApiError(err, "failed to get latest agent config version")+ if err != nil && !errorsV2.Ast(err, errorsV2.TypeNotFound) {+ return nil, err}if lastestConfig != nil {@@ -4156,14 +4150,14 @@ func (aH *APIHandler) listLogsPipelines(ctx context.Context, orgID valuer.UUID)payload, err := aH.LogsParsingPipelineController.GetPipelinesByVersion(ctx, orgID, latestVersion)if err != nil {- return nil, model.WrapApiError(err, "failed to get pipelines")+ return nil, err}// todo(Nitya): make a new API for history paginationlimit := 10history, err := agentConf.GetConfigHistory(ctx, orgID, opamptypes.ElementTypeLogPipelines, limit)if err != nil {- return nil, model.WrapApiError(err, "failed to get config history")+ return nil, err}payload.History = historyreturn payload, nil@@ -4171,18 +4165,18 @@ func (aH *APIHandler) listLogsPipelines(ctx context.Context, orgID valuer.UUID)// listLogsPipelinesByVersion lists pipelines along with config version historyfunc (aH *APIHandler) listLogsPipelinesByVersion(ctx context.Context, orgID valuer.UUID, version int) (- *logparsingpipeline.PipelinesResponse, *model.ApiError,+ *logparsingpipeline.PipelinesResponse, error,) {payload, err := aH.LogsParsingPipelineController.GetPipelinesByVersion(ctx, orgID, version)if err != nil {- return nil, model.WrapApiError(err, "failed to get pipelines by version")+ return nil, err}// todo(Nitya): make a new API for history paginationlimit := 10history, err := agentConf.GetConfigHistory(ctx, orgID, opamptypes.ElementTypeLogPipelines, limit)if err != nil {- return nil, model.WrapApiError(err, "failed to retrieve agent config history")+ return nil, err}payload.History = history@@ -4218,14 +4212,14 @@ func (aH *APIHandler) CreateLogsPipeline(w http.ResponseWriter, r *http.Request)createPipeline := func(ctx context.Context,postable []pipelinetypes.PostablePipeline,- ) (*logparsingpipeline.PipelinesResponse, *model.ApiError) {+ ) (*logparsingpipeline.PipelinesResponse, error) {if len(postable) == 0 {zap.L().Warn("found no pipelines in the http request, this will delete all the pipelines")}- validationErr := aH.LogsParsingPipelineController.ValidatePipelines(ctx, postable)- if validationErr != nil {- return nil, validationErr+ err := aH.LogsParsingPipelineController.ValidatePipelines(ctx, postable)+ if err != nil {+ return nil, err}return aH.LogsParsingPipelineController.ApplyPipelines(ctx, orgID, userID, postable)@@ -4233,7 +4227,7 @@ func (aH *APIHandler) CreateLogsPipeline(w http.ResponseWriter, r *http.Request)res, err := createPipeline(r.Context(), req.Pipelines)if err != nil {- RespondError(w, err, nil)+ render.Error(w, err)return}diff --git a/pkg/query-service/app/integrations/controller.go b/pkg/query-service/app/integrations/controller.goindex aa44ea8cc4..7935563286 100644--- a/pkg/query-service/app/integrations/controller.go+++ b/pkg/query-service/app/integrations/controller.go@@ -106,7 +106,7 @@ func (c *Controller) Uninstall(ctx context.Context, orgId string, req *Uninstallreturn nil}-func (c *Controller) GetPipelinesForInstalledIntegrations(ctx context.Context, orgId string) ([]pipelinetypes.GettablePipeline, *model.ApiError) {+func (c *Controller) GetPipelinesForInstalledIntegrations(ctx context.Context, orgId string) ([]pipelinetypes.GettablePipeline, error) {return c.mgr.GetPipelinesForInstalledIntegrations(ctx, orgId)}diff --git a/pkg/query-service/app/integrations/manager.go b/pkg/query-service/app/integrations/manager.goindex 21d7e3ea2d..cb7932b03a 100644--- a/pkg/query-service/app/integrations/manager.go+++ b/pkg/query-service/app/integrations/manager.go@@ -256,7 +256,7 @@ func (m *Manager) UninstallIntegration(func (m *Manager) GetPipelinesForInstalledIntegrations(ctx context.Context,orgId string,-) ([]pipelinetypes.GettablePipeline, *model.ApiError) {+) ([]pipelinetypes.GettablePipeline, error) {installedIntegrations, apiErr := m.getInstalledIntegrations(ctx, orgId)if apiErr != nil {return nil, apiErrdiff --git a/pkg/query-service/app/logparsingpipeline/collector_config.go b/pkg/query-service/app/logparsingpipeline/collector_config.goindex 46bf3bfa54..1bbac49354 100644--- a/pkg/query-service/app/logparsingpipeline/collector_config.go+++ b/pkg/query-service/app/logparsingpipeline/collector_config.go@@ -8,15 +8,23 @@ import ("gopkg.in/yaml.v3"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/query-service/constants"- coreModel "github.com/SigNoz/signoz/pkg/query-service/model""github.com/SigNoz/signoz/pkg/types/pipelinetypes"- "github.com/pkg/errors""go.uber.org/zap")var lockLogsPipelineSpec sync.RWMutex+var (+ CodeCollectorConfigUnmarshalFailed = errors.MustNewCode("collector_config_unmarshal_failed")+ CodeCollectorConfigMarshalFailed = errors.MustNewCode("collector_config_marshal_failed")+ CodeCollectorConfigServiceNotFound = errors.MustNewCode("collector_config_service_not_found")+ CodeCollectorConfigServiceMarshalFailed = errors.MustNewCode("collector_config_service_marshal_failed")+ CodeCollectorConfigServiceUnmarshalFailed = errors.MustNewCode("collector_config_service_unmarshal_failed")+ CodeCollectorConfigLogsPipelineNotFound = errors.MustNewCode("collector_config_logs_pipeline_not_found")+)+// check if the processors already exist// if yes then update the processor.// if something doesn't exists then remove it.@@ -57,15 +65,15 @@ type otelPipeline struct {func getOtelPipelineFromConfig(config map[string]interface{}) (*otelPipeline, error) {if _, ok := config["service"]; !ok {- return nil, fmt.Errorf("service not found in OTEL config")+ return nil, errors.NewInvalidInputf(CodeCollectorConfigServiceNotFound, "service not found in OTEL config")}b, err := json.Marshal(config["service"])if err != nil {- return nil, err+ return nil, errors.WrapInternalf(err, CodeCollectorConfigServiceMarshalFailed, "could not marshal OTEL config")}p := otelPipeline{}if err := json.Unmarshal(b, &p); err != nil {- return nil, err+ return nil, errors.WrapInternalf(err, CodeCollectorConfigServiceUnmarshalFailed, "could not unmarshal OTEL config")}return &p, nil}@@ -163,21 +171,16 @@ func checkDuplicateString(pipeline []string) bool {return false}-func GenerateCollectorConfigWithPipelines(- config []byte,- pipelines []pipelinetypes.GettablePipeline,-) ([]byte, *coreModel.ApiError) {+func GenerateCollectorConfigWithPipelines(config []byte, pipelines []pipelinetypes.GettablePipeline) ([]byte, error) {var collectorConf map[string]interface{}err := yaml.Unmarshal([]byte(config), &collectorConf)if err != nil {- return nil, coreModel.BadRequest(err)+ return nil, errors.WrapInvalidInputf(err, CodeCollectorConfigUnmarshalFailed, "could not unmarshal collector config")}signozPipelineProcessors, signozPipelineProcNames, err := PreparePipelineProcessor(pipelines)if err != nil {- return nil, coreModel.BadRequest(errors.Wrap(- err, "could not prepare otel collector processors for log pipelines",- ))+ return nil, err}// Escape any `$`s as `$$$` in config generated for pipelines, to ensure any occurrences@@ -186,9 +189,7 @@ func GenerateCollectorConfigWithPipelines(procConf := signozPipelineProcessors[procName]serializedProcConf, err := yaml.Marshal(procConf)if err != nil {- return nil, coreModel.InternalError(fmt.Errorf(- "could not marshal processor config for %s: %w", procName, err,- ))+ return nil, errors.WrapInternalf(err, CodeCollectorConfigMarshalFailed, "could not marshal processor config for %s", procName)}escapedSerializedConf := strings.ReplaceAll(string(serializedProcConf), "$", "$$",@@ -197,9 +198,7 @@ func GenerateCollectorConfigWithPipelines(var escapedConf map[string]interface{}err = yaml.Unmarshal([]byte(escapedSerializedConf), &escapedConf)if err != nil {- return nil, coreModel.InternalError(fmt.Errorf(- "could not unmarshal dollar escaped processor config for %s: %w", procName, err,- ))+ return nil, errors.WrapInternalf(err, CodeCollectorConfigUnmarshalFailed, "could not unmarshal dollar escaped processor config for %s", procName)}signozPipelineProcessors[procName] = escapedConf@@ -211,12 +210,10 @@ func GenerateCollectorConfigWithPipelines(// build the new processor list in service.pipelines.logsp, err := getOtelPipelineFromConfig(collectorConf)if err != nil {- return nil, coreModel.BadRequest(err)+ return nil, err}if p.Pipelines.Logs == nil {- return nil, coreModel.InternalError(fmt.Errorf(- "logs pipeline doesn't exist",- ))+ return nil, errors.NewInternalf(CodeCollectorConfigLogsPipelineNotFound, "logs pipeline doesn't exist")}updatedProcessorList, _ := buildCollectorPipelineProcessorsList(p.Pipelines.Logs.Processors, signozPipelineProcNames)@@ -227,7 +224,7 @@ func GenerateCollectorConfigWithPipelines(updatedConf, err := yaml.Marshal(collectorConf)if err != nil {- return nil, coreModel.BadRequest(err)+ return nil, errors.WrapInternalf(err, CodeCollectorConfigMarshalFailed, "could not marshal collector config")}return updatedConf, nildiff --git a/pkg/query-service/app/logparsingpipeline/controller.go b/pkg/query-service/app/logparsingpipeline/controller.goindex 12a8d702e3..b2470c342c 100644--- a/pkg/query-service/app/logparsingpipeline/controller.go+++ b/pkg/query-service/app/logparsingpipeline/controller.go@@ -7,6 +7,7 @@ import ("slices""strings"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/query-service/agentConf""github.com/SigNoz/signoz/pkg/query-service/constants""github.com/SigNoz/signoz/pkg/query-service/model"@@ -17,20 +18,23 @@ import ("github.com/SigNoz/signoz/pkg/types/pipelinetypes""github.com/SigNoz/signoz/pkg/valuer""github.com/google/uuid"- "github.com/pkg/errors""go.uber.org/zap")+var (+ CodeRawPipelinesMarshalFailed = errors.MustNewCode("raw_pipelines_marshal_failed")+)+// Controller takes care of deployment cycle of log parsing pipelines.type LogParsingPipelineController struct {Repo- GetIntegrationPipelines func(context.Context, string) ([]pipelinetypes.GettablePipeline, *model.ApiError)+ GetIntegrationPipelines func(context.Context, string) ([]pipelinetypes.GettablePipeline, error)}func NewLogParsingPipelinesController(sqlStore sqlstore.SQLStore,- getIntegrationPipelines func(context.Context, string) ([]pipelinetypes.GettablePipeline, *model.ApiError),+ getIntegrationPipelines func(context.Context, string) ([]pipelinetypes.GettablePipeline, error),) (*LogParsingPipelineController, error) {repo := NewRepo(sqlStore)return &LogParsingPipelineController{@@ -53,7 +57,7 @@ func (ic *LogParsingPipelineController) ApplyPipelines(orgID valuer.UUID,userID valuer.UUID,postable []pipelinetypes.PostablePipeline,-) (*PipelinesResponse, *model.ApiError) {+) (*PipelinesResponse, error) {var pipelines []pipelinetypes.GettablePipeline// scan through postable pipelines, to select the existing pipelines or insert missing ones@@ -68,9 +72,9 @@ func (ic *LogParsingPipelineController) ApplyPipelines(// the same pipeline id.r.ID = uuid.NewString()r.OrderID = idx + 1- pipeline, apiErr := ic.insertPipeline(ctx, orgID, &r)- if apiErr != nil {- return nil, model.WrapApiError(apiErr, "failed to insert pipeline")+ pipeline, err := ic.insertPipeline(ctx, orgID, &r)+ if err != nil {+ return nil, err}pipelines = append(pipelines, *pipeline)@@ -90,13 +94,12 @@ func (ic *LogParsingPipelineController) ApplyPipelines(return ic.GetPipelinesByVersion(ctx, orgID, cfg.Version)}-func (ic *LogParsingPipelineController) ValidatePipelines(- ctx context.Context,+func (ic *LogParsingPipelineController) ValidatePipelines(ctx context.Context,postedPipelines []pipelinetypes.PostablePipeline,-) *model.ApiError {+) error {for _, p := range postedPipelines {if err := p.IsValid(); err != nil {- return model.BadRequestStr(err.Error())+ return errors.WithAdditionalf(err, "invalid pipeline: %s", p.Name)}}@@ -121,39 +124,29 @@ func (ic *LogParsingPipelineController) ValidatePipelines(}sampleLogs := []model.SignozLog{{Body: ""}}- _, _, simulationErr := SimulatePipelinesProcessing(- ctx, gettablePipelines, sampleLogs,- )- if simulationErr != nil {- return model.BadRequest(fmt.Errorf(- "invalid pipelines config: %w", simulationErr.ToError(),- ))- }-- return nil+ _, _, err := SimulatePipelinesProcessing(ctx, gettablePipelines, sampleLogs)+ return err}// Returns effective list of pipelines including user created// pipelines and pipelines for installed integrationsfunc (ic *LogParsingPipelineController) getEffectivePipelinesByVersion(ctx context.Context, orgID valuer.UUID, version int,-) ([]pipelinetypes.GettablePipeline, *model.ApiError) {+) ([]pipelinetypes.GettablePipeline, error) {result := []pipelinetypes.GettablePipeline{}if version >= 0 {- savedPipelines, errors := ic.getPipelinesByVersion(ctx, orgID.String(), version)- if errors != nil {- zap.L().Error("failed to get pipelines for version", zap.Int("version", version), zap.Errors("errors", errors))- return nil, model.InternalError(fmt.Errorf("failed to get pipelines for given version %v", errors))+ savedPipelines, err := ic.getPipelinesByVersion(ctx, orgID.String(), version)+ if err != nil {+ zap.L().Error("failed to get pipelines for version", zap.Int("version", version), zap.Error(err))+ return nil, err}result = savedPipelines}- integrationPipelines, apiErr := ic.GetIntegrationPipelines(ctx, orgID.String())- if apiErr != nil {- return nil, model.WrapApiError(- apiErr, "could not get pipelines for installed integrations",- )+ integrationPipelines, err := ic.GetIntegrationPipelines(ctx, orgID.String())+ if err != nil {+ return nil, err}// Filter out any integration pipelines included in pipelines saved by user@@ -194,12 +187,11 @@ func (ic *LogParsingPipelineController) getEffectivePipelinesByVersion(// GetPipelinesByVersion responds with version info and associated pipelinesfunc (ic *LogParsingPipelineController) GetPipelinesByVersion(ctx context.Context, orgId valuer.UUID, version int,-) (*PipelinesResponse, *model.ApiError) {-- pipelines, errors := ic.getEffectivePipelinesByVersion(ctx, orgId, version)- if errors != nil {- zap.L().Error("failed to get pipelines for version", zap.Int("version", version), zap.Error(errors))- return nil, model.InternalError(fmt.Errorf("failed to get pipelines for given version %v", errors))+) (*PipelinesResponse, error) {+ pipelines, err := ic.getEffectivePipelinesByVersion(ctx, orgId, version)+ if err != nil {+ zap.L().Error("failed to get pipelines for version", zap.Int("version", version), zap.Error(err))+ return nil, err}var configVersion *opamptypes.AgentConfigVersion@@ -207,7 +199,7 @@ func (ic *LogParsingPipelineController) GetPipelinesByVersion(cv, err := agentConf.GetConfigVersion(ctx, orgId, opamptypes.ElementTypeLogPipelines, version)if err != nil {zap.L().Error("failed to get config for version", zap.Int("version", version), zap.Error(err))- return nil, model.WrapApiError(err, "failed to get config for given version")+ return nil, err}configVersion = cv}@@ -231,11 +223,8 @@ type PipelinesPreviewResponse struct {func (ic *LogParsingPipelineController) PreviewLogsPipelines(ctx context.Context,request *PipelinesPreviewRequest,-) (*PipelinesPreviewResponse, *model.ApiError) {- result, collectorLogs, err := SimulatePipelinesProcessing(- ctx, request.Pipelines, request.Logs,- )-+) (*PipelinesPreviewResponse, error) {+ result, collectorLogs, err := SimulatePipelinesProcessing(ctx, request.Pipelines, request.Logs)if err != nil {return nil, err}@@ -256,33 +245,27 @@ func (pc *LogParsingPipelineController) RecommendAgentConfig(orgId valuer.UUID,currentConfYaml []byte,configVersion *opamptypes.AgentConfigVersion,-) (- recommendedConfYaml []byte,- serializedSettingsUsed string,- apiErr *model.ApiError,-) {+) ([]byte, string, error) {pipelinesVersion := -1if configVersion != nil {pipelinesVersion = configVersion.Version}- pipelinesResp, apiErr := pc.GetPipelinesByVersion(+ pipelinesResp, err := pc.GetPipelinesByVersion(context.Background(), orgId, pipelinesVersion,)- if apiErr != nil {- return nil, "", apiErr+ if err != nil {+ return nil, "", err}- updatedConf, apiErr := GenerateCollectorConfigWithPipelines(- currentConfYaml, pipelinesResp.Pipelines,- )- if apiErr != nil {- return nil, "", model.WrapApiError(apiErr, "could not marshal yaml for updated conf")+ updatedConf, err := GenerateCollectorConfigWithPipelines(currentConfYaml, pipelinesResp.Pipelines)+ if err != nil {+ return nil, "", err}rawPipelineData, err := json.Marshal(pipelinesResp.Pipelines)if err != nil {- return nil, "", model.BadRequest(errors.Wrap(err, "could not serialize pipelines to JSON"))+ return nil, "", errors.WrapInternalf(err, CodeRawPipelinesMarshalFailed, "could not serialize pipelines to JSON")}return updatedConf, string(rawPipelineData), nildiff --git a/pkg/query-service/app/logparsingpipeline/db.go b/pkg/query-service/app/logparsingpipeline/db.goindex 92196cf34a..afd3675a52 100644--- a/pkg/query-service/app/logparsingpipeline/db.go+++ b/pkg/query-service/app/logparsingpipeline/db.go@@ -6,13 +6,13 @@ import ("fmt""time"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/query-service/model""github.com/SigNoz/signoz/pkg/sqlstore""github.com/SigNoz/signoz/pkg/types""github.com/SigNoz/signoz/pkg/types/authtypes""github.com/SigNoz/signoz/pkg/types/pipelinetypes""github.com/SigNoz/signoz/pkg/valuer"- "github.com/pkg/errors""go.uber.org/zap")@@ -33,24 +33,18 @@ func NewRepo(sqlStore sqlstore.SQLStore) Repo {// insertPipeline stores a given postable pipeline to databasefunc (r *Repo) insertPipeline(ctx context.Context, orgID valuer.UUID, postable *pipelinetypes.PostablePipeline,-) (*pipelinetypes.GettablePipeline, *model.ApiError) {+) (*pipelinetypes.GettablePipeline, error) {if err := postable.IsValid(); err != nil {- return nil, model.BadRequest(errors.Wrap(err,- "pipeline is not valid",- ))+ return nil, errors.WithAdditionalf(err, "pipeline is not valid")}rawConfig, err := json.Marshal(postable.Config)if err != nil {- return nil, model.BadRequest(errors.Wrap(err,- "failed to unmarshal postable pipeline config",- ))+ return nil, errors.WrapInternalf(err, errors.CodeInternal, "failed to unmarshal postable pipeline config")}filter, err := json.Marshal(postable.Filter)if err != nil {- return nil, model.BadRequest(errors.Wrap(err,- "failed to marshal postable pipeline filter",- ))+ return nil, errors.WrapInternalf(err, errors.CodeInternal, "failed to marshal postable pipeline filter")}claims, errv2 := authtypes.ClaimsFromContext(ctx)@@ -85,10 +79,9 @@ func (r *Repo) insertPipeline(_, err = r.sqlStore.BunDB().NewInsert().Model(&insertRow.StoreablePipeline).Exec(ctx)-if err != nil {zap.L().Error("error in inserting pipeline data", zap.Error(err))- return nil, model.InternalError(errors.Wrap(err, "failed to insert pipeline"))+ return nil, errors.WrapInternalf(err, errors.CodeInternal, "failed to insert pipeline")}return insertRow, nil@@ -97,8 +90,7 @@ func (r *Repo) insertPipeline(// getPipelinesByVersion returns pipelines associated with a given versionfunc (r *Repo) getPipelinesByVersion(ctx context.Context, orgID string, version int,-) ([]pipelinetypes.GettablePipeline, []error) {- var errors []error+) ([]pipelinetypes.GettablePipeline, error) {storablePipelines := []pipelinetypes.StoreablePipeline{}err := r.sqlStore.BunDB().NewSelect().Model(&storablePipelines).@@ -110,7 +102,7 @@ func (r *Repo) getPipelinesByVersion(Order("p.order_id ASC").Scan(ctx)if err != nil {- return nil, []error{fmt.Errorf("failed to get pipelines from db: %v", err)}+ return nil, errors.WrapInternalf(err, CodePipelinesGetFailed, "failed to get pipelines from db")}gettablePipelines := make([]pipelinetypes.GettablePipeline, len(storablePipelines))@@ -118,23 +110,24 @@ func (r *Repo) getPipelinesByVersion(return gettablePipelines, nil}+ var errs []errorfor i := range storablePipelines {gettablePipelines[i].StoreablePipeline = storablePipelines[i]if err := gettablePipelines[i].ParseRawConfig(); err != nil {- errors = append(errors, err)+ errs = append(errs, err)}if err := gettablePipelines[i].ParseFilter(); err != nil {- errors = append(errors, err)+ errs = append(errs, err)}}- return gettablePipelines, errors+ return gettablePipelines, errors.Join(errs...)}// GetPipelines returns pipeline and errors (if any)func (r *Repo) GetPipeline(ctx context.Context, orgID string, id string,-) (*pipelinetypes.GettablePipeline, *model.ApiError) {+) (*pipelinetypes.GettablePipeline, error) {storablePipelines := []pipelinetypes.StoreablePipeline{}err := r.sqlStore.BunDB().NewSelect().@@ -144,12 +137,12 @@ func (r *Repo) GetPipeline(Scan(ctx)if err != nil {zap.L().Error("failed to get ingestion pipeline from db", zap.Error(err))- return nil, model.InternalError(errors.Wrap(err, "failed to get ingestion pipeline from db"))+ return nil, errors.WrapInternalf(err, errors.CodeInternal, "failed to get ingestion pipeline from db")}if len(storablePipelines) == 0 {zap.L().Warn("No row found for ingestion pipeline id", zap.String("id", id))- return nil, model.NotFoundError(fmt.Errorf("no row found for ingestion pipeline id %v", id))+ return nil, errors.NewNotFoundf(errors.CodeNotFound, "no row found for ingestion pipeline id %v", id)}if len(storablePipelines) == 1 {@@ -157,20 +150,16 @@ func (r *Repo) GetPipeline(gettablePipeline.StoreablePipeline = storablePipelines[0]if err := gettablePipeline.ParseRawConfig(); err != nil {zap.L().Error("invalid pipeline config found", zap.String("id", id), zap.Error(err))- return nil, model.InternalError(- errors.Wrap(err, "found an invalid pipeline config"),- )+ return nil, err}if err := gettablePipeline.ParseFilter(); err != nil {zap.L().Error("invalid pipeline filter found", zap.String("id", id), zap.Error(err))- return nil, model.InternalError(- errors.Wrap(err, "found an invalid pipeline filter"),- )+ return nil, err}return &gettablePipeline, nil}- return nil, model.InternalError(fmt.Errorf("multiple pipelines with same id"))+ return nil, errors.NewInternalf(errors.CodeInternal, "multiple pipelines with same id")}func (r *Repo) DeletePipeline(ctx context.Context, orgID string, id string) error {diff --git a/pkg/query-service/app/logparsingpipeline/error.go b/pkg/query-service/app/logparsingpipeline/error.goindex bd127a69cc..f63fcf2227 100644--- a/pkg/query-service/app/logparsingpipeline/error.go+++ b/pkg/query-service/app/logparsingpipeline/error.go@@ -3,6 +3,8 @@ package logparsingpipelineimport "github.com/SigNoz/signoz/pkg/errors"var (- CodeInvalidOperatorType = errors.MustNewCode("operator_type_mismatch")- CodeFieldNilCheckType = errors.MustNewCode("operator_field_nil_check")+ CodeInvalidOperatorType = errors.MustNewCode("operator_type_mismatch")+ CodeFieldNilCheckType = errors.MustNewCode("operator_field_nil_check")+ CodePipelinesGetFailed = errors.MustNewCode("pipelines_get_failed")+ CodeProcessorFactoryMapFailed = errors.MustNewCode("processor_factory_map_failed"))diff --git a/pkg/query-service/app/logparsingpipeline/preview.go b/pkg/query-service/app/logparsingpipeline/preview.goindex 649c2b3d2b..dc8b829776 100644--- a/pkg/query-service/app/logparsingpipeline/preview.go+++ b/pkg/query-service/app/logparsingpipeline/preview.go@@ -9,22 +9,16 @@ import ("github.com/SigNoz/signoz-otel-collector/pkg/collectorsimulator"_ "github.com/SigNoz/signoz-otel-collector/pkg/parser/grok""github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor"+ "github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/query-service/model""github.com/SigNoz/signoz/pkg/types/pipelinetypes"- "github.com/pkg/errors""go.opentelemetry.io/collector/otelcol""go.opentelemetry.io/collector/pdata/pcommon""go.opentelemetry.io/collector/pdata/plog")-func SimulatePipelinesProcessing(- ctx context.Context,- pipelines []pipelinetypes.GettablePipeline,- logs []model.SignozLog,-) (- output []model.SignozLog, collectorWarnAndErrorLogs []string, apiErr *model.ApiError,-) {-+func SimulatePipelinesProcessing(ctx context.Context, pipelines []pipelinetypes.GettablePipeline, logs []model.SignozLog) (+ []model.SignozLog, []string, error) {if len(pipelines) < 1 {return logs, nil, nil}@@ -42,13 +36,9 @@ func SimulatePipelinesProcessing(}simulatorInputPLogs := SignozLogsToPLogs(logs)- processorFactories, err := otelcol.MakeFactoryMap(- signozlogspipelineprocessor.NewFactory(),- )+ processorFactories, err := otelcol.MakeFactoryMap(signozlogspipelineprocessor.NewFactory())if err != nil {- return nil, nil, model.InternalError(errors.Wrap(- err, "could not construct processor factory map",- ))+ return nil, nil, errors.WrapInternalf(err, CodeProcessorFactoryMapFailed, "could not construct processor factory map")}// Pipelines translate to logtransformprocessors in otel collector config.@@ -60,9 +50,9 @@ func SimulatePipelinesProcessing(timeout := time.Millisecond * time.Duration(len(pipelines)*100+100)configGenerator := func(baseConf []byte) ([]byte, error) {- updatedConf, apiErr := GenerateCollectorConfigWithPipelines(baseConf, pipelines)- if apiErr != nil {- return nil, apiErr.ToError()+ updatedConf, err := GenerateCollectorConfigWithPipelines(baseConf, pipelines)+ if err != nil {+ return nil, err}return updatedConf, nil}@@ -76,14 +66,9 @@ func SimulatePipelinesProcessing()if simulationErr != nil {if errors.Is(simulationErr, collectorsimulator.ErrInvalidConfig) {- apiErr = model.BadRequest(simulationErr)- } else {- apiErr = model.InternalError(simulationErr)+ return nil, nil, errors.WrapInvalidInputf(simulationErr, errors.CodeInvalidInput, "invalid config")}-- return nil, collectorErrs, model.WrapApiError(apiErr,- "could not simulate log pipelines processing.\nCollector errors",- )+ return nil, nil, errors.WrapInternalf(simulationErr, errors.CodeInternal, "could not simulate log pipelines processing")}outputSignozLogs := PLogsToSignozLogs(outputPLogs)@@ -98,6 +83,7 @@ func SimulatePipelinesProcessing(delete(sigLog.Attributes_int64, inputOrderAttribute)}+ collectorWarnAndErrorLogs := []string{}for _, log := range collectorErrs {// if log is empty or log comes from featuregate.go, then remove itif log == "" || strings.Contains(log, "featuregate.go") {diff --git a/pkg/query-service/app/opamp/configure_ingestionRules.go b/pkg/query-service/app/opamp/configure_ingestionRules.goindex 039fffe6db..c3153ce984 100644--- a/pkg/query-service/app/opamp/configure_ingestionRules.go+++ b/pkg/query-service/app/opamp/configure_ingestionRules.go@@ -3,25 +3,27 @@ package opampimport ("context""crypto/sha256"- "fmt"+ "github.com/SigNoz/signoz/pkg/errors"model "github.com/SigNoz/signoz/pkg/query-service/app/opamp/model""github.com/SigNoz/signoz/pkg/query-service/app/opamp/otelconfig"- coreModel "github.com/SigNoz/signoz/pkg/query-service/model""github.com/knadh/koanf/parsers/yaml""github.com/open-telemetry/opamp-go/protobufs""go.opentelemetry.io/collector/confmap""go.uber.org/zap")+var (+ CodeNoAgentsAvailable = errors.MustNewCode("no_agents_available")+ CodeOpAmpServerDown = errors.MustNewCode("opamp_server_down")+ CodeMultipleAgentsNotSupported = errors.MustNewCode("multiple_agents_not_supported")+)+// inserts or updates ingestion controller processors depending// on the signal (metrics or traces)-func UpsertControlProcessors(- ctx context.Context,- signal string,- processors map[string]interface{},- callback model.OnChangeCallback,-) (hash string, fnerr *coreModel.ApiError) {+func UpsertControlProcessors(ctx context.Context, signal string,+ processors map[string]interface{}, callback model.OnChangeCallback,+) (string, error) {// note: only processors enabled through tracesPipelinePlan will be added// to pipeline. To enable or disable processors from pipeline, call// AddToTracePipeline() or RemoveFromTracesPipeline() prior to calling@@ -31,33 +33,24 @@ func UpsertControlProcessors(if signal != string(Metrics) && signal != string(Traces) {zap.L().Error("received invalid signal int UpsertControlProcessors", zap.String("signal", signal))- fnerr = coreModel.BadRequest(fmt.Errorf(- "signal not supported in ingestion rules: %s", signal,- ))- return+ return "", errors.NewInvalidInputf(errors.CodeInvalidInput, "signal not supported in ingestion rules: %s", signal)}if opAmpServer == nil {- fnerr = coreModel.UnavailableError(fmt.Errorf(- "opamp server is down, unable to push config to agent at this moment",- ))- return+ return "", errors.NewInternalf(CodeOpAmpServerDown, "opamp server is down, unable to push config to agent at this moment")}agents := opAmpServer.agents.GetAllAgents()if len(agents) == 0 {- fnerr = coreModel.UnavailableError(fmt.Errorf("no agents available at the moment"))- return+ return "", errors.NewInternalf(CodeNoAgentsAvailable, "no agents available at the moment")}if len(agents) > 1 && signal == string(Traces) {zap.L().Debug("found multiple agents. this feature is not supported for traces pipeline (sampling rules)")- fnerr = coreModel.BadRequest(fmt.Errorf("multiple agents not supported in sampling rules"))- return+ return "", errors.NewInvalidInputf(CodeMultipleAgentsNotSupported, "multiple agents not supported in sampling rules")}-+ hash := ""for _, agent := range agents {-agenthash, err := addIngestionControlToAgent(agent, signal, processors, false)if err != nil {zap.L().Error("failed to push ingestion rules config to agent", zap.String("agentID", agent.AgentID), zap.Error(err))diff --git a/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go b/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.goindex 4b8c24228b..a78243d724 100644--- a/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go+++ b/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go@@ -5,11 +5,16 @@ import ("reflect""strings"+ "github.com/SigNoz/signoz/pkg/errors"v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"expr "github.com/antonmedv/expr""go.uber.org/zap")+var (+ CodeExprCompilationFailed = errors.MustNewCode("expr_compilation_failed")+)+var logOperatorsToExpr = map[v3.FilterOperator]string{v3.FilterOperatorEqual: "==",v3.FilterOperatorNotEqual: "!=",@@ -50,7 +55,7 @@ func Parse(filters *v3.FilterSet) (string, error) {var res []stringfor _, v := range filters.Items {if _, ok := logOperatorsToExpr[v.Operator]; !ok {- return "", fmt.Errorf("operator not supported")+ return "", errors.NewInvalidInputf(errors.CodeInvalidInput, "operator not supported: %s", v.Operator)}name := getName(v.Key)@@ -108,7 +113,7 @@ func Parse(filters *v3.FilterSet) (string, error) {q := strings.Join(res, " "+strings.ToLower(filters.Operator)+" ")_, err := expr.Compile(q)if err != nil {- return "", err+ return "", errors.WrapInternalf(err, CodeExprCompilationFailed, "failed to compile expression: %s", q)}return q, nildiff --git a/pkg/types/pipelinetypes/pipeline.go b/pkg/types/pipelinetypes/pipeline.goindex ac235846f8..2411f3d751 100644--- a/pkg/types/pipelinetypes/pipeline.go+++ b/pkg/types/pipelinetypes/pipeline.go@@ -220,7 +220,7 @@ func (p *PostablePipeline) IsValid() error {// check the filter_, err := queryBuilderToExpr.Parse(p.Filter)if err != nil {- return errors.WrapInvalidInputf(err, errors.CodeInvalidInput, "filter for pipeline %v is not correct", p.Name)+ return err}idUnique := map[string]struct{}{}@@ -403,7 +403,7 @@ func isValidOperator(op PipelineOperator) error {!isValidOtelValue(op.To) ||!isValidOtelValue(op.Field) {valueErrStr := "value should have prefix of body, attributes, resource"- return errors.NewInvalidInputf(errors.CodeInvalidInput, "%s for operator Id %s", valueErrStr, op.ID)+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "%s for operator: %s in position: %d with id: %s", valueErrStr, op.Type, op.OrderId, op.ID)}return nil}