Skip to content

Commit

Permalink
PMM-12624 add context to transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Dec 22, 2023
1 parent 0341533 commit 59641d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 0 additions & 2 deletions api/inventory/v1/agents.proto
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,6 @@ message AddProxySQLExporterParams {
bool expose_exporter = 13;
}

// TODO: remove AddProxySQLExporterResponse

message ChangeProxySQLExporterRequest {
string agent_id = 1 [(validate.rules).string.min_len = 1];
ChangeCommonAgentParams common = 2;
Expand Down
32 changes: 16 additions & 16 deletions managed/services/inventory/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (as *AgentsService) changeAgent(agentID string, common *inventoryv1.ChangeC
//nolint:unparam
func (as *AgentsService) List(ctx context.Context, filters models.AgentFilters) ([]inventoryv1.Agent, error) {
var res []inventoryv1.Agent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
got := 0
if filters.PMMAgentID != "" {
got++
Expand Down Expand Up @@ -151,7 +151,7 @@ func (as *AgentsService) List(ctx context.Context, filters models.AgentFilters)
// Get selects a single Agent by ID.
func (as *AgentsService) Get(ctx context.Context, id string) (inventoryv1.Agent, error) { //nolint:ireturn,unparam
var res inventoryv1.Agent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
row, err := models.FindAgentByID(tx.Querier, id)
if err != nil {
return err
Expand Down Expand Up @@ -183,7 +183,7 @@ func (as *AgentsService) Logs(ctx context.Context, id string, limit uint32) ([]s
//nolint:unparam
func (as *AgentsService) AddPMMAgent(ctx context.Context, req *inventoryv1.AddPMMAgentRequest) (*inventoryv1.PMMAgent, error) {
var res *inventoryv1.PMMAgent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
row, err := models.CreatePMMAgent(tx.Querier, req.RunsOnNodeId, req.CustomLabels)
if err != nil {
return err
Expand Down Expand Up @@ -240,7 +240,7 @@ func (as *AgentsService) ChangeNodeExporter(ctx context.Context, req *inventoryv
func (as *AgentsService) AddMySQLdExporter(ctx context.Context, p *inventoryv1.AddMySQLdExporterParams) (*inventoryv1.MySQLdExporter, int32, error) { //nolint:unparam
var row *models.Agent
var res *inventoryv1.MySQLdExporter
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: p.PmmAgentId,
ServiceID: p.ServiceId,
Expand Down Expand Up @@ -307,7 +307,7 @@ func (as *AgentsService) ChangeMySQLdExporter(ctx context.Context, req *inventor
// AddMongoDBExporter inserts mongodb_exporter Agent with given parameters.
func (as *AgentsService) AddMongoDBExporter(ctx context.Context, p *inventoryv1.AddMongoDBExporterParams) (*inventoryv1.MongoDBExporter, error) {
var res *inventoryv1.MongoDBExporter
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: p.PmmAgentId,
ServiceID: p.ServiceId,
Expand Down Expand Up @@ -374,7 +374,7 @@ func (as *AgentsService) ChangeMongoDBExporter(ctx context.Context, req *invento
//nolint:lll
func (as *AgentsService) AddQANMySQLPerfSchemaAgent(ctx context.Context, req *inventoryv1.AddQANMySQLPerfSchemaAgentRequest) (*inventoryv1.QANMySQLPerfSchemaAgent, error) {
var res *inventoryv1.QANMySQLPerfSchemaAgent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: req.ServiceId,
Expand Down Expand Up @@ -434,7 +434,7 @@ func (as *AgentsService) ChangeQANMySQLPerfSchemaAgent(ctx context.Context, req
// AddQANMySQLSlowlogAgent adds MySQL Slowlog QAN Agent.
func (as *AgentsService) AddQANMySQLSlowlogAgent(ctx context.Context, req *inventoryv1.AddQANMySQLSlowlogAgentRequest) (*inventoryv1.QANMySQLSlowlogAgent, error) {
var res *inventoryv1.QANMySQLSlowlogAgent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
// tweak according to API docs
maxSlowlogFileSize := req.MaxSlowlogFileSize
if maxSlowlogFileSize < 0 {
Expand Down Expand Up @@ -501,7 +501,7 @@ func (as *AgentsService) ChangeQANMySQLSlowlogAgent(ctx context.Context, req *in
// AddPostgresExporter inserts postgres_exporter Agent with given parameters.
func (as *AgentsService) AddPostgresExporter(ctx context.Context, p *inventoryv1.AddPostgresExporterParams) (*inventoryv1.PostgresExporter, error) {
var res *inventoryv1.PostgresExporter
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: p.PmmAgentId,
ServiceID: p.ServiceId,
Expand Down Expand Up @@ -569,7 +569,7 @@ func (as *AgentsService) ChangePostgresExporter(ctx context.Context, req *invent
func (as *AgentsService) AddQANMongoDBProfilerAgent(ctx context.Context, req *inventoryv1.AddQANMongoDBProfilerAgentRequest) (*inventoryv1.QANMongoDBProfilerAgent, error) {
var res *inventoryv1.QANMongoDBProfilerAgent

e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: req.ServiceId,
Expand Down Expand Up @@ -630,7 +630,7 @@ func (as *AgentsService) ChangeQANMongoDBProfilerAgent(ctx context.Context, req
// AddProxySQLExporter inserts proxysql_exporter Agent with given parameters.
func (as *AgentsService) AddProxySQLExporter(ctx context.Context, p *inventoryv1.AddProxySQLExporterParams) (*inventoryv1.ProxySQLExporter, error) {
var res *inventoryv1.ProxySQLExporter
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: p.PmmAgentId,
ServiceID: p.ServiceId,
Expand Down Expand Up @@ -696,7 +696,7 @@ func (as *AgentsService) ChangeProxySQLExporter(ctx context.Context, req *invent
//nolint:lll
func (as *AgentsService) AddQANPostgreSQLPgStatementsAgent(ctx context.Context, req *inventoryv1.AddQANPostgreSQLPgStatementsAgentRequest) (*inventoryv1.QANPostgreSQLPgStatementsAgent, error) {
var res *inventoryv1.QANPostgreSQLPgStatementsAgent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: req.ServiceId,
Expand Down Expand Up @@ -757,7 +757,7 @@ func (as *AgentsService) ChangeQANPostgreSQLPgStatementsAgent(ctx context.Contex
//nolint:lll
func (as *AgentsService) AddQANPostgreSQLPgStatMonitorAgent(ctx context.Context, req *inventoryv1.AddQANPostgreSQLPgStatMonitorAgentRequest) (*inventoryv1.QANPostgreSQLPgStatMonitorAgent, error) {
var res *inventoryv1.QANPostgreSQLPgStatMonitorAgent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: req.ServiceId,
Expand Down Expand Up @@ -817,7 +817,7 @@ func (as *AgentsService) ChangeQANPostgreSQLPgStatMonitorAgent(ctx context.Conte
// AddRDSExporter inserts rds_exporter Agent with given parameters.
func (as *AgentsService) AddRDSExporter(ctx context.Context, p *inventoryv1.AddRDSExporterParams) (*inventoryv1.RDSExporter, error) {
var res *inventoryv1.RDSExporter
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: p.PmmAgentId,
NodeID: p.NodeId,
Expand Down Expand Up @@ -872,7 +872,7 @@ func (as *AgentsService) AddExternalExporter(ctx context.Context, p *inventoryv1
res *inventoryv1.ExternalExporter
PMMAgentID *string
)
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateExternalExporterParams{
RunsOnNodeID: p.RunsOnNodeId,
ServiceID: p.ServiceId,
Expand Down Expand Up @@ -929,7 +929,7 @@ func (as *AgentsService) ChangeExternalExporter(req *inventoryv1.ChangeExternalE
func (as *AgentsService) AddAzureDatabaseExporter(ctx context.Context, p *inventoryv1.AddAzureDatabaseExporterParams) (*inventoryv1.AzureDatabaseExporter, error) {
var res *inventoryv1.AzureDatabaseExporter

e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
params := &models.CreateAgentParams{
PMMAgentID: p.PmmAgentId,
NodeID: p.NodeId,
Expand Down Expand Up @@ -976,7 +976,7 @@ func (as *AgentsService) ChangeAzureDatabaseExporter(
// Remove removes Agent, and sends state update to pmm-agent, or kicks it.
func (as *AgentsService) Remove(ctx context.Context, id string, force bool) error {
var removedAgent *models.Agent
e := as.db.InTransaction(func(tx *reform.TX) error {
e := as.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
var err error
mode := models.RemoveRestrict
if force {
Expand Down

0 comments on commit 59641d9

Please sign in to comment.