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
Revert "fix: "In Progress" stuck agent config (#10476)" (#10633)
Piyush Singariyac8fcc480225f
diff --git a/pkg/query-service/agentConf/db.go b/pkg/query-service/agentConf/db.goindex 5299d66bbc..22e0774ee0 100644--- a/pkg/query-service/agentConf/db.go+++ b/pkg/query-service/agentConf/db.go@@ -115,6 +115,7 @@ func (r *Repo) GetLatestVersion(func (r *Repo) insertConfig(ctx context.Context, orgId valuer.UUID, userId valuer.UUID, c *opamptypes.AgentConfigVersion, elements []string,) error {+if c.ElementType.StringValue() == "" {return errors.NewInvalidInputf(CodeElementTypeRequired, "element type is required for creating agent config version")}@@ -228,25 +229,6 @@ func (r *Repo) updateDeployStatus(ctx context.Context,return nil}-// GetDeployStatusByHash returns the DeployStatus for the given config hash-// (stored with orgId prefix). Returns DeployStatusUnknown when no matching row exists.-func (r *Repo) GetDeployStatusByHash(ctx context.Context, orgId valuer.UUID, configHash string) (opamptypes.DeployStatus, error) {- var version opamptypes.AgentConfigVersion- err := r.store.BunDB().NewSelect().- Model(&version).- ColumnExpr("deploy_status").- Where("hash = ?", configHash).- Where("org_id = ?", orgId).- Scan(ctx)- if err != nil {- if errors.Is(err, sql.ErrNoRows) {- return opamptypes.DeployStatusUnknown, nil- }- return opamptypes.DeployStatusUnknown, errors.WrapInternalf(err, errors.CodeInternal, "failed to query deploy status by hash")- }- return version.DeployStatus, nil-}-func (r *Repo) updateDeployStatusByHash(ctx context.Context, orgId valuer.UUID, confighash string, status string, result string,) error {diff --git a/pkg/query-service/agentConf/manager.go b/pkg/query-service/agentConf/manager.goindex d923751e0a..9d5db2a8d8 100644--- a/pkg/query-service/agentConf/manager.go+++ b/pkg/query-service/agentConf/manager.go@@ -180,12 +180,6 @@ func (m *Manager) ReportConfigDeploymentStatus(}}-// Implements model.AgentConfigProvider-func (m *Manager) GetDeployStatusByHash(ctx context.Context, orgId valuer.UUID, configHash string) (opamptypes.DeployStatus, error) {- return m.Repo.GetDeployStatusByHash(ctx, orgId, configHash)-}--func GetLatestVersion(ctx context.Context, orgId valuer.UUID, elementType opamptypes.ElementType,) (*opamptypes.AgentConfigVersion, error) {diff --git a/pkg/query-service/app/opamp/config_provider.go b/pkg/query-service/app/opamp/config_provider.goindex 921256c386..b73d94a2c5 100644--- a/pkg/query-service/app/opamp/config_provider.go+++ b/pkg/query-service/app/opamp/config_provider.go@@ -1,8 +1,6 @@package opamp-import (- "github.com/SigNoz/signoz/pkg/query-service/app/opamp/model"-)+import "github.com/SigNoz/signoz/pkg/query-service/app/opamp/model"// Interface for a source of otel collector config recommendations.type AgentConfigProvider interface {diff --git a/pkg/query-service/app/opamp/mocks.go b/pkg/query-service/app/opamp/mocks.goindex 4d6093d1b3..b017f726ff 100644--- a/pkg/query-service/app/opamp/mocks.go+++ b/pkg/query-service/app/opamp/mocks.go@@ -5,7 +5,6 @@ import ("log""net"- "github.com/SigNoz/signoz/pkg/types/opamptypes""github.com/SigNoz/signoz/pkg/valuer""github.com/google/uuid""github.com/knadh/koanf"@@ -128,11 +127,6 @@ func (ta *MockAgentConfigProvider) HasReportedDeploymentStatus(orgID valuer.UUIDreturn exists}-// AgentConfigProvider interface-func (ta *MockAgentConfigProvider) GetDeployStatusByHash(_ context.Context, _ valuer.UUID, _ string) (opamptypes.DeployStatus, error) {- return opamptypes.DeployStatusUnknown, nil-}-// AgentConfigProvider interfacefunc (ta *MockAgentConfigProvider) SubscribeToConfigUpdates(callback func()) func() {subscriberId := uuid.NewString()diff --git a/pkg/query-service/app/opamp/model/agent.go b/pkg/query-service/app/opamp/model/agent.goindex 28cc1dcdeb..2ee705831d 100644--- a/pkg/query-service/app/opamp/model/agent.go+++ b/pkg/query-service/app/opamp/model/agent.go@@ -111,99 +111,90 @@ func ExtractLbFlag(agentDescr *protobufs.AgentDescription) bool {return false}-// agentDescriptionChanged returns true when the agent sends updated properties-// (e.g. capability flag, version) mid-connection, signalling the server to-// recompute and push a new RemoteConfig.-//-// On reconnect this always returns false: handleFirstStatus pre-copies-// AgentDescription into agent.Status so no diff is detected, avoiding a-// redundant config recompute.-func (agent *Agent) agentDescriptionChanged(newStatus *protobufs.AgentToServer) bool {- // nil AgentDescription means no change per OpAMP protocol.- if newStatus.AgentDescription == nil {- return false- }- if proto.Equal(agent.Status.AgentDescription, newStatus.AgentDescription) {- return false- }- agent.CanLB = ExtractLbFlag(newStatus.AgentDescription)- return true-}+func (agent *Agent) updateAgentDescription(newStatus *protobufs.AgentToServer) (agentDescrChanged bool) {+ prevStatus := agent.Status-// updateRemoteConfigStatus updates the stored RemoteConfigStatus and notifies-// subscribers if the status has changed relative to what we have stored.-func (agent *Agent) updateRemoteConfigStatus(newStatus *protobufs.AgentToServer) {- if newStatus.RemoteConfigStatus == nil ||- proto.Equal(agent.Status.RemoteConfigStatus, newStatus.RemoteConfigStatus) {- return- }+ if agent.Status == nil {+ // First time this Agent reports a status, remember it.+ agent.Status = newStatus+ agentDescrChanged = true+ } else {+ // Not a new Agent. Update the Status.+ agent.Status.SequenceNum = newStatus.SequenceNum++ // Check what's changed in the AgentDescription.+ if newStatus.AgentDescription != nil {+ // If the AgentDescription field is set it means the Agent tells us+ // something is changed in the field since the last status report+ // (or this is the first report).+ // Make full comparison of previous and new descriptions to see if it+ // really is different.+ if prevStatus != nil && proto.Equal(prevStatus.AgentDescription, newStatus.AgentDescription) {+ // Agent description didn't change.+ agentDescrChanged = false+ } else {+ // Yes, the description is different, update it.+ agent.Status.AgentDescription = newStatus.AgentDescription+ agentDescrChanged = true+ }+ } else {+ // AgentDescription field is not set, which means description didn't change.+ agentDescrChanged = false+ }- // todo: need to address multiple agent scenario here- // for now, the first response will be sent back to the UI- hash := string(newStatus.RemoteConfigStatus.LastRemoteConfigHash)- switch newStatus.RemoteConfigStatus.Status {- case protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLIED:- onConfigSuccess(agent.OrgID, agent.AgentID, hash)- case protobufs.RemoteConfigStatuses_RemoteConfigStatuses_FAILED:- onConfigFailure(agent.OrgID, agent.AgentID, hash, newStatus.RemoteConfigStatus.ErrorMessage)- }-}+ // Update remote config status if it is included and is different from what we have.+ if newStatus.RemoteConfigStatus != nil &&+ !proto.Equal(agent.Status.RemoteConfigStatus, newStatus.RemoteConfigStatus) {+ agent.Status.RemoteConfigStatus = newStatus.RemoteConfigStatus-// handleFirstStatus initializes agent.Status on the first message received from-// this agent instance. It is a no-op for all subsequent messages.-func (agent *Agent) handleFirstStatus(newStatus *protobufs.AgentToServer, configProvider AgentConfigProvider) {- if agent.Status != nil {- return- }+ // todo: need to address multiple agent scenario here+ // for now, the first response will be sent back to the UI+ if agent.Status.RemoteConfigStatus.Status == protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLIED {+ onConfigSuccess(agent.OrgID, agent.AgentID, string(agent.Status.RemoteConfigStatus.LastRemoteConfigHash))+ }- // Initialize with a clean slate.- agent.Status = &protobufs.AgentToServer{- RemoteConfigStatus: &protobufs.RemoteConfigStatus{- Status: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_UNSET,- },+ if agent.Status.RemoteConfigStatus.Status == protobufs.RemoteConfigStatuses_RemoteConfigStatuses_FAILED {+ onConfigFailure(agent.OrgID, agent.AgentID, string(agent.Status.RemoteConfigStatus.LastRemoteConfigHash), agent.Status.RemoteConfigStatus.ErrorMessage)+ }+ }}- if newStatus.RemoteConfigStatus == nil ||- newStatus.RemoteConfigStatus.Status == protobufs.RemoteConfigStatuses_RemoteConfigStatuses_UNSET {- // Agent just started fresh — no prior deployment to reconcile with the DB.- return+ if agentDescrChanged {+ agent.CanLB = ExtractLbFlag(newStatus.AgentDescription)}- // Since the server's connection is restarted;- // copy the agent description; so no change is detected by agentDescriptionChanged- agent.Status.AgentDescription = newStatus.AgentDescription+ return agentDescrChanged+}- // Server reconnected while the agent was already running.- // Reconcile deployment status with DB; DB is the source of truth.- // If DB says in_progress but agent now reports APPLIED/FAILED,- // updateRemoteConfigStatus will detect the transition and notify subscribers.- rawHash := string(newStatus.RemoteConfigStatus.LastRemoteConfigHash)- deployStatus, err := configProvider.GetDeployStatusByHash(context.Background(), agent.OrgID, agent.OrgID.String()+rawHash)- if err != nil {+func (agent *Agent) updateHealth(newStatus *protobufs.AgentToServer) {+ if newStatus.Health == nil {return}- agent.Status.RemoteConfigStatus.Status = opamptypes.DeployStatusToProtoStatus[deployStatus]+ agent.Status.Health = newStatus.Health- // If the deployment is still in-flight, rehydrate the subscriber so that- // updateRemoteConfigStatus can fire onConfigSuccess/onConfigFailure when- // the agent next reports a terminal status.- if deployStatus != opamptypes.Deployed && deployStatus != opamptypes.DeployFailed {- ListenToConfigUpdate(agent.OrgID, agent.AgentID, rawHash, configProvider.ReportConfigDeploymentStatus)+ if agent.Status != nil && agent.Status.Health != nil && agent.Status.Health.Healthy {+ agent.TimeAuditable.UpdatedAt = time.Unix(0, int64(agent.Status.Health.StartTimeUnixNano)).UTC()}}-func (agent *Agent) updateStatusField(newStatus *protobufs.AgentToServer, configProvider AgentConfigProvider) bool {- agent.handleFirstStatus(newStatus, configProvider)- agentDescrChanged := agent.agentDescriptionChanged(newStatus)- // record healthy timestamp- if newStatus.Health != nil && newStatus.Health.Healthy {- agent.TimeAuditable.UpdatedAt = time.Unix(0, int64(newStatus.Health.StartTimeUnixNano)).UTC()+func (agent *Agent) updateRemoteConfigStatus(newStatus *protobufs.AgentToServer) {+ // Update remote config status if it is included and is different from what we have.+ if newStatus.RemoteConfigStatus != nil {+ agent.Status.RemoteConfigStatus = newStatus.RemoteConfigStatus}- // notify subscribers first; this will update the status in the DB+}++func (agent *Agent) updateStatusField(newStatus *protobufs.AgentToServer) (agentDescrChanged bool) {+ if agent.Status == nil {+ // First time this Agent reports a status, remember it.+ agent.Status = newStatus+ agentDescrChanged = true+ }++ agentDescrChanged = agent.updateAgentDescription(newStatus) || agentDescrChangedagent.updateRemoteConfigStatus(newStatus)- // update local reference in last.- agent.Status = newStatus+ agent.updateHealth(newStatus)return agentDescrChanged}@@ -246,7 +237,7 @@ func (agent *Agent) processStatusUpdate(// current status is not up-to-date.lostPreviousUpdate := (agent.Status == nil) || (agent.Status != nil && agent.Status.SequenceNum+1 != newStatus.SequenceNum)- agentDescrChanged := agent.updateStatusField(newStatus, configProvider)+ agentDescrChanged := agent.updateStatusField(newStatus)// Check if any fields were omitted in the status report.effectiveConfigOmitted := newStatus.EffectiveConfig == nil &&diff --git a/pkg/query-service/app/opamp/model/config.go b/pkg/query-service/app/opamp/model/config.goindex f155f21f30..fddc1e80d8 100644--- a/pkg/query-service/app/opamp/model/config.go+++ b/pkg/query-service/app/opamp/model/config.go@@ -1,11 +1,6 @@package model-import (- "context"-- "github.com/SigNoz/signoz/pkg/types/opamptypes"- "github.com/SigNoz/signoz/pkg/valuer"-)+import "github.com/SigNoz/signoz/pkg/valuer"// Interface for source of otel collector config recommendations.type AgentConfigProvider interface {@@ -25,10 +20,4 @@ type AgentConfigProvider interface {configId string,err error,)-- // GetDeployStatusByHash returns the DeployStatus for the given config hash- // (with orgId prefix as stored in the DB). Returns DeployStatusUnknown when- // no matching row exists. Used by the agent's first-connect handler to- // determine whether the reported RemoteConfigStatus resolves a pending deployment.- GetDeployStatusByHash(ctx context.Context, orgId valuer.UUID, configHash string) (opamptypes.DeployStatus, error)}diff --git a/pkg/query-service/app/opamp/model/coordinator.go b/pkg/query-service/app/opamp/model/coordinator.goindex d78818e474..8c9ab346e5 100644--- a/pkg/query-service/app/opamp/model/coordinator.go+++ b/pkg/query-service/app/opamp/model/coordinator.go@@ -66,7 +66,6 @@ func ListenToConfigUpdate(orgId valuer.UUID, agentId string, hash string, ss OnCdefer coordinator.mutex.Unlock()key := getSubscriberKey(orgId, hash)-if subs, ok := coordinator.subscribers[key]; ok {subs = append(subs, ss)coordinator.subscribers[key] = subsdiff --git a/pkg/types/opamptypes/agent.go b/pkg/types/opamptypes/agent.goindex 80e70cf8e5..8d61bceacc 100644--- a/pkg/types/opamptypes/agent.go+++ b/pkg/types/opamptypes/agent.go@@ -6,7 +6,6 @@ import ("github.com/SigNoz/signoz/pkg/sqlstore""github.com/SigNoz/signoz/pkg/types""github.com/SigNoz/signoz/pkg/valuer"- "github.com/open-telemetry/opamp-go/protobufs""github.com/uptrace/bun")@@ -18,15 +17,6 @@ const (AgentStatusDisconnected)-var DeployStatusToProtoStatus = map[DeployStatus]protobufs.RemoteConfigStatuses{- PendingDeploy: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_UNSET,- Deploying: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLYING,- Deployed: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLIED,- DeployInitiated: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLYING,- DeployFailed: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_FAILED,- DeployStatusUnknown: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_UNSET,-}-type StorableAgent struct {bun.BaseModel `bun:"table:agent"`@@ -40,6 +30,16 @@ type StorableAgent struct {Config string `bun:"config,type:text,notnull"`}+func NewStorableAgent(store sqlstore.SQLStore, orgID valuer.UUID, agentID string, status AgentStatus) StorableAgent {+ return StorableAgent{+ OrgID: orgID,+ Identifiable: types.Identifiable{ID: valuer.GenerateUUID()},+ AgentID: agentID,+ TimeAuditable: types.TimeAuditable{CreatedAt: time.Now(), UpdatedAt: time.Now()},+ Status: status,+ }+}+type ElementType struct{ valuer.String }var (@@ -49,6 +49,24 @@ var (ElementTypeLbExporter = ElementType{valuer.NewString("lb_exporter")})+// NewElementType creates a new ElementType from a string value.+// Returns the corresponding ElementType constant if the string matches,+// otherwise returns an empty ElementType.+func NewElementType(value string) ElementType {+ switch valuer.NewString(value) {+ case ElementTypeSamplingRules.String:+ return ElementTypeSamplingRules+ case ElementTypeDropRules.String:+ return ElementTypeDropRules+ case ElementTypeLogPipelines.String:+ return ElementTypeLogPipelines+ case ElementTypeLbExporter.String:+ return ElementTypeLbExporter+ default:+ return ElementType{valuer.NewString("")}+ }+}+type DeployStatus struct{ valuer.String }var (@@ -80,26 +98,6 @@ type AgentConfigVersion struct {Config string `json:"config" bun:"config,type:text"`}-type AgentConfigElement struct {- bun.BaseModel `bun:"table:agent_config_element"`-- types.Identifiable- types.TimeAuditable- ElementID string `bun:"element_id,type:text,notnull,unique:element_type_version_idx"`- ElementType string `bun:"element_type,type:text,notnull,unique:element_type_version_idx"`- VersionID valuer.UUID `bun:"version_id,type:text,notnull,unique:element_type_version_idx"`-}--func NewStorableAgent(store sqlstore.SQLStore, orgID valuer.UUID, agentID string, status AgentStatus) StorableAgent {- return StorableAgent{- OrgID: orgID,- Identifiable: types.Identifiable{ID: valuer.GenerateUUID()},- AgentID: agentID,- TimeAuditable: types.TimeAuditable{CreatedAt: time.Now(), UpdatedAt: time.Now()},- Status: status,- }-}-func NewAgentConfigVersion(orgId valuer.UUID, userId valuer.UUID, elementType ElementType) *AgentConfigVersion {return &AgentConfigVersion{TimeAuditable: types.TimeAuditable{@@ -120,20 +118,12 @@ func (a *AgentConfigVersion) IncrementVersion(lastVersion int) {a.Version = lastVersion + 1}-// NewElementType creates a new ElementType from a string value.-// Returns the corresponding ElementType constant if the string matches,-// otherwise returns an empty ElementType.-func NewElementType(value string) ElementType {- switch valuer.NewString(value) {- case ElementTypeSamplingRules.String:- return ElementTypeSamplingRules- case ElementTypeDropRules.String:- return ElementTypeDropRules- case ElementTypeLogPipelines.String:- return ElementTypeLogPipelines- case ElementTypeLbExporter.String:- return ElementTypeLbExporter- default:- return ElementType{valuer.NewString("")}- }+type AgentConfigElement struct {+ bun.BaseModel `bun:"table:agent_config_element"`++ types.Identifiable+ types.TimeAuditable+ ElementID string `bun:"element_id,type:text,notnull,unique:element_type_version_idx"`+ ElementType string `bun:"element_type,type:text,notnull,unique:element_type_version_idx"`+ VersionID valuer.UUID `bun:"version_id,type:text,notnull,unique:element_type_version_idx"`}