Documentation ¶
Index ¶
- Variables
- func Conn() *sql.DB
- func DisplayConfig()
- func ExecuteQuery(db *sql.DB, sql string)
- func HasErr(msg string, err error) bool
- func MarshalJSON(data interface{}) string
- func OverrideConfig(strArgs map[string]*string, intArgs map[string]*int, boolArgs map[string]*bool)
- func Ping(db *sql.DB)
- func SetDatabaseUID(name string) uuid.UUID
- func ShaQuery(query string) string
- func UnmarshalJSON(data []byte, v interface{})
- func UuidFromString(uid string) uuid.UUID
- func UuidString(query string) string
- func UuidV5(str string) uuid.UUID
- type CreateStatement
- type CreateStatements
- type CreateStatementsInQueries
- type Database
- type Databases
- type Owner
- type Owners
- type OwnersImport
- type OwnersImports
- type OwnersTables
- type OwnersTablesCollection
- type ProcessedFile
- type Queries
- func (q *Queries) Analyze(w QueryWorker) bool
- func (q *Queries) CountInDB() int
- func (q *Queries) ExtractStats()
- func (q *Queries) LogAggregateOfErrors()
- func (q *Queries) Process() bool
- func (q *Queries) Upsert()
- func (q *Queries) UpsertColumnsInQueries()
- func (q *Queries) UpsertCreateStatements()
- func (q *Queries) UpsertCreateStatementsInQueries()
- func (q *Queries) UpsertQueryByHours()
- func (q *Queries) UpsertQueryUsers()
- func (q *Queries) UpsertTableJoinsInQueries()
- func (q *Queries) UpsertTables()
- func (q *Queries) UpsertTablesInQueries()
- type Query
- type QueryByHour
- type QueryUser
- type QueryWorker
- type Source
- type Sources
- type Table
- type Tables
Constants ¶
This section is empty.
Variables ¶
var ( Env = "dev" DBHost = "localhost" DBPort = "5432" DBUser = "postgres" DBPassword = "" DBName = "lantern" )
Default config values. These can be overwritten by the params passed in.
var UuidNamespace = uuid.MustParse("018e1b50-ee98-73f2-9839-420223323163")
UuidNamespace is the namespace for the uuid. There are 4 predefined namespaces, but you can also create your own.
Functions ¶
func DisplayConfig ¶
func DisplayConfig()
func ExecuteQuery ¶
func MarshalJSON ¶
func MarshalJSON(data interface{}) string
func OverrideConfig ¶
func SetDatabaseUID ¶
func UnmarshalJSON ¶
func UnmarshalJSON(data []byte, v interface{})
func UuidFromString ¶
func UuidString ¶
Types ¶
type CreateStatement ¶
type CreateStatement struct { UID uuid.UUID `json:"uid,omitempty"` Scope string `json:"scope,omitempty"` IsUnique bool `json:"is_unique,omitempty"` UsedConcurrently bool `json:"used_concurrently,omitempty"` IsTemp bool `json:"is_temp,omitempty"` IsUnlogged bool `json:"is_unlogged,omitempty"` ObjectType string `json:"object_type,omitempty"` IfNotExists bool `json:"if_not_exists,omitempty"` Name string `json:"name,omitempty"` OnCommit string `json:"on_commit,omitempty"` Operator string `json:"operator,omitempty"` Expression string `json:"expression,omitempty"` WhereClause string `json:"where_clause,omitempty"` }
func (*CreateStatement) SetUID ¶
func (c *CreateStatement) SetUID()
type CreateStatements ¶
type CreateStatements struct {
CreateStatements map[string]*CreateStatement `json:"create_statements,omitempty"`
}
func NewCreateStatements ¶
func NewCreateStatements() *CreateStatements
func (*CreateStatements) Add ¶
func (c *CreateStatements) Add(cs *CreateStatement) *CreateStatement
func (*CreateStatements) SetAll ¶
func (c *CreateStatements) SetAll(db *sql.DB)
type Databases ¶
type Databases struct { Source string `json:"source,omitempty"` Databases map[string]*Database `json:"databases,omitempty"` // the key is the UUIDv5 sha of the database }
func NewDatabases ¶
func (*Databases) AddDatabase ¶
type Owner ¶
type OwnersImport ¶
type OwnersImports ¶
type OwnersImports struct { Data []OwnersImport `json:"data,omitempty"` Database string `json:"database,omitempty"` }
func NewOwnersImports ¶
func NewOwnersImports() *OwnersImports
func (*OwnersImports) Import ¶
func (o *OwnersImports) Import(data []byte) error
func (*OwnersImports) Unmarshal ¶
func (o *OwnersImports) Unmarshal(data []byte) error
type OwnersTables ¶
type OwnersTables struct { UID uuid.UUID `json:"uid,omitempty"` // unique UUID of the row OwnerUID uuid.UUID `json:"owner_uid,omitempty"` // the UUID of the owner TableUID uuid.UUID `json:"table_uid,omitempty"` // the UUID of the table }
func (*OwnersTables) SetUID ¶
func (o *OwnersTables) SetUID()
type OwnersTablesCollection ¶
type OwnersTablesCollection struct {
OwnersTables map[string]*OwnersTables `json:"owners_tables,omitempty"`
}
func NewOwnersTablesCollection ¶
func NewOwnersTablesCollection() *OwnersTablesCollection
NewOwnersTablesCollection creates a new OwnersTablesCollection struct
func (*OwnersTablesCollection) Add ¶
func (o *OwnersTablesCollection) Add(own *OwnersTables) *OwnersTables
Add adds a new OwnersTables to the collection
func (*OwnersTablesCollection) CountInDB ¶
func (o *OwnersTablesCollection) CountInDB(db *sql.DB) int64
CountInDB returns the number of rows in the owners_tables table
func (*OwnersTablesCollection) Upsert ¶
func (o *OwnersTablesCollection) Upsert(db *sql.DB)
Upsert inserts or updates the rows in the owners_tables table
type ProcessedFile ¶
type ProcessedFile struct { UID uuid.UUID `json:"uid,omitempty"` FileName string `json:"file_name,omitempty"` ProcessedAt time.Time `json:"processed_at,omitempty"` }
func NewProcessedFile ¶
func NewProcessedFile(fileName string) *ProcessedFile
func (*ProcessedFile) HasBeenProcessed ¶
func (p *ProcessedFile) HasBeenProcessed(db *sql.DB) bool
func (*ProcessedFile) Processed ¶
func (p *ProcessedFile) Processed(db *sql.DB)
type Queries ¶
type Queries struct { Source string `json:"source,omitempty"` Queries map[string]*Query `json:"queries,omitempty"` FunctionsInQueries map[string]*extractor.FunctionsInQueries `json:"functions_in_queries,omitempty"` ColumnsInQueries map[string]*extractor.ColumnsInQueries `json:"columns_in_queries,omitempty"` TablesInQueries map[string]*extractor.TablesInQueries `json:"tables_in_queries,omitempty"` TableJoinsInQueries map[string]*extractor.TableJoinsInQueries `json:"table_joins_in_queries,omitempty"` Tables map[string]*extractor.Tables `json:"tables,omitempty"` CreateStatementsInQueries map[string]*CreateStatementsInQueries `json:"create_statements_in_queries,omitempty"` CreateStatements map[string]*CreateStatement `json:"create_statements,omitempty"` Errors map[string]int `json:"errors,omitempty"` }
func (*Queries) Analyze ¶
func (q *Queries) Analyze(w QueryWorker) bool
Analyze processes a query and returns a bool whether or not the query was parsed successfully This ends up calling addQuery which adds the query to the Queries struct Then the Queries struct is cached as a JSON file
func (*Queries) ExtractStats ¶
func (q *Queries) ExtractStats()
func (*Queries) LogAggregateOfErrors ¶
func (q *Queries) LogAggregateOfErrors()
func (*Queries) UpsertColumnsInQueries ¶
func (q *Queries) UpsertColumnsInQueries()
func (*Queries) UpsertCreateStatements ¶
func (q *Queries) UpsertCreateStatements()
func (*Queries) UpsertCreateStatementsInQueries ¶
func (q *Queries) UpsertCreateStatementsInQueries()
func (*Queries) UpsertQueryByHours ¶
func (q *Queries) UpsertQueryByHours()
func (*Queries) UpsertQueryUsers ¶
func (q *Queries) UpsertQueryUsers()
func (*Queries) UpsertTableJoinsInQueries ¶
func (q *Queries) UpsertTableJoinsInQueries()
func (*Queries) UpsertTables ¶
func (q *Queries) UpsertTables()
func (*Queries) UpsertTablesInQueries ¶
func (q *Queries) UpsertTablesInQueries()
type Query ¶
type Query struct { UID uuid.UUID `json:"uid,omitempty"` // unique sha of the query DatabaseUID uuid.UUID `json:"database_uid,omitempty"` // the dataset the query belongs to SourceUID uuid.UUID `json:"source_uid,omitempty"` // the source the query belongs to QueryByHours map[string]*QueryByHour `json:"query_by_hours,omitempty"` // query stats per hour Command token.TokenType `json:"command,omitempty"` // the type of query MaskedQuery string `json:"masked_query,omitempty"` // the query with parameters masked UnmaskedQuery string `json:"unmasked_query,omitempty"` // the query with parameters unmasked SourceQuery string `json:"source,omitempty"` // the original query from the source }
func (*Query) MarshalJSON ¶
func (*Query) Process ¶
func (q *Query) Process(w QueryWorker, qs *Queries) bool
Process processes a query and returns a bool whether or not the query was parsed successfully
func (*Query) UnmarshalJSON ¶
type QueryByHour ¶
type QueryByHour struct { UID uuid.UUID `json:"uid,omitempty"` // unique sha of the query plus the time QueryUID uuid.UUID `json:"query_uid,omitempty"` // unique sha of the query QueriedDate string `json:"queried_date,omitempty"` // the date the query was executed QueriedHour int `json:"queried_hour,omitempty"` // the hour the query was executed TotalCount int64 `json:"total_count,omitempty"` // the number of times the query was executed TotalDurationUs int64 `json:"total_duration_us,omitempty"` // the total duration of all executions of the query in microseconds TotalQueriesInTransaction int64 `json:"total_queries_in_transaction,omitempty"` // the sum total number of queries each time this query was executed in a transaction Users map[string]*QueryUser `json:"users,omitempty"` // the users who executed the query }
type QueryWorker ¶
type QueryWorker struct { TimestampByHour time.Time Databases *Databases Source *Source SourceUID uuid.UUID Database string DatabaseUID uuid.UUID UserName string Input string // Original query. This may contain many queries TransactionQueryCount int64 // Number of queries in a transaction DurationUs int64 // Duration of the query in microseconds MustExtract bool Command token.TokenType Masked string // Masked query. This is the query with all values replaced with ? Unmasked string // Unmasked query. This is the query with all values left alone }
This is an interim struct with additional Query meta data. The struct is passed around and built up instead of passing around a ton of individual variables. This is used both initially when compiling a list of queries and then individually when processing each query
type Source ¶
type Sources ¶
type Sources struct {
Sources map[string]*Source `json:"sources,omitempty"` // the key is the sha of the database
}
func NewSources ¶
func NewSources() *Sources
type Table ¶
type Table struct { UID uuid.UUID `json:"uid,omitempty"` // unique UUID of the table DatabaseUID uuid.UUID `json:"database_uid,omitempty"` // the UUID of the database -- TODO: make this a many to many Schema string `json:"schema_name,omitempty"` // the schema of the table Name string `json:"table_name,omitempty"` // the name of the table Description string `json:"table_description,omitempty"` // a description of the table EstimatedRowCount int64 `json:"estimated_row_count,omitempty"` // the estimated number of rows in the table ColumnCount int64 `json:"column_count,omitempty"` // the number of columns in the table IndexCount int64 `json:"index_count,omitempty"` // the number of indexes on the table IndexSizeBytes int64 `json:"index_size_bytes,omitempty"` // the size of the indexes on the table DataSizeBytes int64 `json:"data_size_bytes,omitempty"` // the size of the data in the table TableType string `json:"table_type,omitempty"` // the type of table (e.g. view, table, materialized view) CreatedAt time.Time `json:"created_at,omitempty"` // when the table was created UpdatedAt time.Time `json:"updated_at,omitempty"` // when the table was last updated }
func (*Table) MarshalJSON ¶
func (*Table) UnmarshalJSON ¶
Source Files ¶
- analyze_columns_in_queries.go
- analyze_create_statements.go
- analyze_table_joins_in_queries.go
- analyze_tables.go
- analyze_tables_in_queries.go
- create_statement.go
- create_statements.go
- create_statements_in_queries.go
- databases.go
- db_config.go
- extracted_data.go
- json_helpers.go
- owner.go
- owners.go
- owners_import.go
- owners_tables.go
- owners_tables_collection.go
- processed_files.go
- queries.go
- query.go
- query_by_hour.go
- query_user.go
- sha.go
- source.go
- sources.go
- table.go
- tables.go