mysql

package
v0.0.0-...-d7993bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

Monitoring Database

The monitoring database is a MySQL instance on Cloud SQL. It stores the error logs for each prow job failures; and the alert status for all error patterns.

Database Connection With Cloud Shell

Navigate to SQL in Google Cloud Platform. Click on the knative-monitoring instance. In the Overview tab, under Connect to this Instance section, click on Connect using Cloud Shell.

A gcloud connection command with root user will be populated in Cloud Shell. Change it to use your database user and press enter to connect to the instance.

At a minimum, it requires cloudsql.instances.get,cloudsql.instances.list, cloudsql.instances.update, resourcemanager.projects.get permissions to connect via Cloud Shell. Refer to Project Access Control for more information.

Local Database Connection

Note: You need to authenticate as an IAM user with 'Cloud SQL Client' and 'Cloud SQL Viewer' role in knative-tests to use Cloud SQL Proxy to connect to the database. Refer to Connect Admin Proxy for more info.

  1. (One-time) Setup Cloud SQL Proxy.

  2. Start the Cloud SQL Proxy on port 3307. This allows the database to be connected through localhost.

    cloud_sql_proxy --instances=knative-tests:us-central1:knative-monitoring=tcp:3307
    
  3. Connect to the database with your database user name, password and the below configuration.

    Host: 127.0.0.1
    Port: 3307
    Database: monitoring (optional)
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ErrorPattern string
	Sent         time.Time
}

Alert maps to the Alerts table Table schema: github.com/chizhg/test-infra/tools/monitoring/mysql/schema.sql

type DB

type DB struct {
	*sql.DB
}

DB holds an active database connection created in `config`

func NewDB

func NewDB(c *mysql.DBConfig) (*DB, error)

NewDB returns the DB object with an active database connection

func (*DB) AddAlert

func (db *DB) AddAlert(errorPattern string) error

AddAlert inserts a new error pattern and alert time (now) to Alerts table If the pattern already exists, update the alert time

func (*DB) AddErrorLog

func (db *DB) AddErrorLog(errPat string, errMsg string, jobName string, prNum int, blogURL string) error

AddErrorLog insert a new error to the ErrorLogs table

func (*DB) DeleteAlert

func (db *DB) DeleteAlert(errorPattern string) error

DeleteAlert deletes a row (alert) from the Alerts table

func (*DB) IsFreshAlertPattern

func (db *DB) IsFreshAlertPattern(errorPattern string, window time.Duration) (bool, error)

IsFreshAlertPattern checks the Alerts table to see if the error pattern hasn't been alerted within the time window

func (*DB) IsPatternAlerting

func (db *DB) IsPatternAlerting(errorPattern, jobPattern string, window time.Duration, aTotal, aJobs, aPRs int) (bool, error)

IsPatternAlerting checks whether the given error pattern meets the alert condition

func (*DB) ListAlerts

func (db *DB) ListAlerts() ([]*Alert, error)

ListAlerts returns all error pattern and timestamps in the Alerts table

func (*DB) ListErrorLogs

func (db *DB) ListErrorLogs(errorPattern string, window time.Duration) ([]ErrorLog, error)

ListErrorLogs returns all jobs stored in ErrorLogs table within the time window

type ErrorLog

type ErrorLog struct {
	Pattern     string
	Msg         string
	JobName     string
	PRNumber    int
	BuildLogURL string
	TimeStamp   time.Time
}

ErrorLog stores a row in the "ErrorLogs" db table Table schema: github.com/chizhg/test-infra/tools/monitoring/mysql/schema.sql

func (ErrorLog) String

func (e ErrorLog) String() string

String returns the string representation of the struct used in alert message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL