Skip to content

Commit

Permalink
Merge branch 'v3' into v3-api-breaking-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed May 31, 2024
2 parents fbb6463 + 77b31a6 commit 483ba4d
Show file tree
Hide file tree
Showing 51 changed files with 11,089 additions and 2,356 deletions.
2 changes: 1 addition & 1 deletion agent/agents/mysql/perfschema/perfschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func getPerfschemaHistorySize(q reform.Querier, l *logrus.Entry) uint {
// New creates new PerfSchema QAN service.
func New(params *Params, l *logrus.Entry) (*PerfSchema, error) {
if params.TextFiles != nil {
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files)
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files, params.TLSSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/agents/mysql/slowlog/slowlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type slowLogInfo struct {
// New creates new SlowLog QAN service.
func New(params *Params, l *logrus.Entry) (*SlowLog, error) {
if params.TextFiles != nil {
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files)
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files, params.TLSSkipVerify)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions agent/connectionchecker/connection_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func (cc *ConnectionChecker) sqlPing(ctx context.Context, db *sql.DB) error {
return err
}

func (cc *ConnectionChecker) checkMySQLConnection(ctx context.Context, dsn string, files *agentv1.TextFiles, tlsSkipVerify bool, id uint32) *agentv1.CheckConnectionResponse { //nolint:lll,unparam,revive
func (cc *ConnectionChecker) checkMySQLConnection(ctx context.Context, dsn string, files *agentv1.TextFiles, tlsSkipVerify bool, id uint32) *agentv1.CheckConnectionResponse { //nolint:lll
var res agentv1.CheckConnectionResponse
var err error

if files != nil {
err = tlshelpers.RegisterMySQLCerts(files.Files)
err = tlshelpers.RegisterMySQLCerts(files.Files, tlsSkipVerify)
if err != nil {
cc.l.Debugf("checkMySQLConnection: failed to register cert: %s", err)
res.Error = err.Error()
Expand Down
4 changes: 2 additions & 2 deletions agent/runner/actions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func jsonRows(columns []string, dataRows [][]interface{}) ([]byte, error) {
}

// mysqlOpen returns *sql.DB for given MySQL DSN.
func mysqlOpen(dsn string, tlsFiles *agentv1.TextFiles) (*sql.DB, error) {
func mysqlOpen(dsn string, tlsFiles *agentv1.TextFiles, tlsSkipVerify bool) (*sql.DB, error) {
if tlsFiles != nil {
err := tlshelpers.RegisterMySQLCerts(tlsFiles.Files)
err := tlshelpers.RegisterMySQLCerts(tlsFiles.Files, tlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/runner/actions/mysql_explain_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (a *mysqlExplainAction) Run(ctx context.Context) ([]byte, error) {
// query has a copy of the original params.Query field if the query is a SELECT or the equivalent
// SELECT after converting DML queries.
query, changedToSelect := dmlToSelect(a.params.Query)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles, a.params.TlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/runner/actions/mysql_query_select_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (a *mysqlQuerySelectAction) DSN() string {

// Run runs an Action and returns output and error.
func (a *mysqlQuerySelectAction) Run(ctx context.Context) ([]byte, error) {
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles, a.params.TlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/runner/actions/mysql_query_show_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (a *mysqlQueryShowAction) DSN() string {

// Run runs an Action and returns output and error.
func (a *mysqlQueryShowAction) Run(ctx context.Context) ([]byte, error) {
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles, a.params.TlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/runner/actions/mysql_show_create_table_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (a *mysqlShowCreateTableAction) DSN() string {

// Run runs an Action and returns output and error.
func (a *mysqlShowCreateTableAction) Run(ctx context.Context) ([]byte, error) {
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles, a.params.TlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/runner/actions/mysql_show_index_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (a *mysqlShowIndexAction) DSN() string {

// Run runs an Action and returns output and error.
func (a *mysqlShowIndexAction) Run(ctx context.Context) ([]byte, error) {
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles, a.params.TlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/runner/actions/mysql_show_table_status_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (a *mysqlShowTableStatusAction) DSN() string {

// Run runs an Action and returns output and error.
func (a *mysqlShowTableStatusAction) Run(ctx context.Context) ([]byte, error) {
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles)
db, err := mysqlOpen(a.params.Dsn, a.params.TlsFiles, a.params.TlsSkipVerify)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions agent/serviceinfobroker/service_info_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (sib *ServiceInfoBroker) GetInfoFromService(ctx context.Context, msg *agent

switch msg.Type {
case inventoryv1.ServiceType_SERVICE_TYPE_MYSQL_SERVICE:
return sib.getMySQLInfo(ctx, msg.Dsn, msg.TextFiles, id)
return sib.getMySQLInfo(ctx, msg.Dsn, msg.TextFiles, msg.TlsSkipVerify, id)
case inventoryv1.ServiceType_SERVICE_TYPE_MONGODB_SERVICE:
return sib.getMongoDBInfo(ctx, msg.Dsn, msg.TextFiles, id)
case inventoryv1.ServiceType_SERVICE_TYPE_POSTGRESQL_SERVICE:
Expand All @@ -84,12 +84,12 @@ func (sib *ServiceInfoBroker) GetInfoFromService(ctx context.Context, msg *agent
}
}

func (sib *ServiceInfoBroker) getMySQLInfo(ctx context.Context, dsn string, files *agentv1.TextFiles, id uint32) *agentv1.ServiceInfoResponse {
func (sib *ServiceInfoBroker) getMySQLInfo(ctx context.Context, dsn string, files *agentv1.TextFiles, tlsSkipVerify bool, id uint32) *agentv1.ServiceInfoResponse {
var res agentv1.ServiceInfoResponse
var err error

if files != nil {
err = tlshelpers.RegisterMySQLCerts(files.Files)
err = tlshelpers.RegisterMySQLCerts(files.Files, tlsSkipVerify)
if err != nil {
sib.l.Debugf("getMySQLInfo: failed to register cert: %s", err)
res.Error = err.Error()
Expand Down
9 changes: 5 additions & 4 deletions agent/tlshelpers/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// RegisterMySQLCerts is used for register TLS config before sql.Open is called.
func RegisterMySQLCerts(files map[string]string) error {
func RegisterMySQLCerts(files map[string]string, tlsSkipVerify bool) error {
if files == nil {
return nil
}
Expand All @@ -36,9 +36,10 @@ func RegisterMySQLCerts(files map[string]string) error {
}

if ok := ca.AppendCertsFromPEM([]byte(files["tlsCa"])); ok {
err = mysql.RegisterTLSConfig("custom", &tls.Config{ //nolint:gosec
RootCAs: ca,
Certificates: []tls.Certificate{cert},
err = mysql.RegisterTLSConfig("custom", &tls.Config{
RootCAs: ca,
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: tlsSkipVerify, // #nosec G402
})
if err != nil {
return errors.Wrap(err, "register MySQL CA cert failed")
Expand Down
160 changes: 160 additions & 0 deletions api-tests/inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,3 +1340,163 @@ func TestPGStatMonitorQanAgent(t *testing.T) {
}
})
}

func TestMetricsResolutionsChange(t *testing.T) {
t.Parallel()

genericNodeID := pmmapitests.AddGenericNode(t, pmmapitests.TestString(t, "")).NodeID
require.NotEmpty(t, genericNodeID)
defer pmmapitests.RemoveNodes(t, genericNodeID)

node := pmmapitests.AddRemoteNode(t, pmmapitests.TestString(t, "Remote node for Node exporter"))
nodeID := node.Remote.NodeID
defer pmmapitests.RemoveNodes(t, nodeID)

service := addPostgreSQLService(t, services.AddPostgreSQLServiceBody{
NodeID: genericNodeID,
Address: "localhost",
Port: 5432,
ServiceName: pmmapitests.TestString(t, "PostgreSQL Service for PostgresExporter test"),
})
serviceID := service.Postgresql.ServiceID
defer pmmapitests.RemoveServices(t, serviceID)

pmmAgent := pmmapitests.AddPMMAgent(t, nodeID)
pmmAgentID := pmmAgent.PMMAgent.AgentID
defer pmmapitests.RemoveAgents(t, pmmAgentID)

PostgresExporter := addPostgresExporter(t, agents.AddPostgresExporterBody{
ServiceID: serviceID,
Username: "username",
Password: "password",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},

SkipConnectionCheck: true,
})
agentID := PostgresExporter.PostgresExporter.AgentID
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.Agents.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.GetAgentOK{
Payload: &agents.GetAgentOKBody{
PostgresExporter: &agents.GetAgentOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
},
},
}, getAgentRes)

// Change metrics resolutions
changePostgresExporterOK, err := client.Default.Agents.ChangePostgresExporter(&agents.ChangePostgresExporterParams{
Body: agents.ChangePostgresExporterBody{
AgentID: agentID,
Common: &agents.ChangePostgresExporterParamsBodyCommon{
MetricsResolutions: &agents.ChangePostgresExporterParamsBodyCommonMetricsResolutions{
Hr: "600s",
Mr: "300s",
Lr: "100s",
},
},
},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.ChangePostgresExporterOK{
Payload: &agents.ChangePostgresExporterOKBody{
PostgresExporter: &agents.ChangePostgresExporterOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
MetricsResolutions: &agents.ChangePostgresExporterOKBodyPostgresExporterMetricsResolutions{
Hr: "600s",
Mr: "300s",
Lr: "100s",
},
},
},
}, changePostgresExporterOK)

// Reset part of metrics resolutions
changePostgresExporterOK, err = client.Default.Agents.ChangePostgresExporter(&agents.ChangePostgresExporterParams{
Body: agents.ChangePostgresExporterBody{
AgentID: agentID,
Common: &agents.ChangePostgresExporterParamsBodyCommon{
MetricsResolutions: &agents.ChangePostgresExporterParamsBodyCommonMetricsResolutions{
Hr: "600s",
Mr: "300s",
Lr: "0s",
},
},
},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.ChangePostgresExporterOK{
Payload: &agents.ChangePostgresExporterOKBody{
PostgresExporter: &agents.ChangePostgresExporterOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
MetricsResolutions: &agents.ChangePostgresExporterOKBodyPostgresExporterMetricsResolutions{
Hr: "600s",
Mr: "300s",
},
},
},
}, changePostgresExporterOK)

// Change part of metrics resolutions
changePostgresExporterOK, err = client.Default.Agents.ChangePostgresExporter(&agents.ChangePostgresExporterParams{
Body: agents.ChangePostgresExporterBody{
AgentID: agentID,
Common: &agents.ChangePostgresExporterParamsBodyCommon{
MetricsResolutions: &agents.ChangePostgresExporterParamsBodyCommonMetricsResolutions{
Hr: "500s",
},
},
},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.ChangePostgresExporterOK{
Payload: &agents.ChangePostgresExporterOKBody{
PostgresExporter: &agents.ChangePostgresExporterOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
MetricsResolutions: &agents.ChangePostgresExporterOKBodyPostgresExporterMetricsResolutions{
Hr: "500s",
Mr: "300s",
},
},
},
}, changePostgresExporterOK)
}
Loading

0 comments on commit 483ba4d

Please sign in to comment.