Skip to content

Commit

Permalink
[ingester] the view of the deepflow_system consists of the Server and…
Browse files Browse the repository at this point in the history
… Agent data of this organization, as well as the Server data of the default organization.
  • Loading branch information
lzf575 committed May 14, 2024
1 parent 3cb5f53 commit 9868c9c
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions server/libs/ckdb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,41 @@ func (t *Table) MakeOrgGlobalTableCreateSQL(orgID uint16) string {
// database 'xxxx_deepflow_system' adds 'deepflow_system' view pointing to the 'deepflow_system_agent' and 'deepflow_system_server' table
func (t *Table) MakeViewsCreateSQLForDeepflowSystem(orgID uint16) []string {
createViewSqls := []string{}
orgDatabase := t.OrgDatabase(orgID)
if t.Database == "deepflow_system" && t.GlobalName == "deepflow_system_server" {
// recreate table deepflow_system.deepflow_system, for upgrade
if orgID == DEFAULT_ORG_ID || orgID == INVALID_ORG_ID {
dropTable := "DROP TABLE IF EXISTS deepflow_system.deepflow_system"
createViewSqls = append(createViewSqls, dropTable)
// recreate table view xxxx_deepflow_system.deepflow_system, for upgrade
dropTable := fmt.Sprintf("DROP TABLE IF EXISTS %s.deepflow_system", orgDatabase)
createViewSqls = append(createViewSqls, dropTable)

deepflowSystemServerView := fmt.Sprintf("CREATE VIEW IF NOT EXISTS %s.`deepflow_system` AS SELECT * FROM %s.`deepflow_system_agent` UNION ALL SELECT * FROM deepflow_system.deepflow_system_server",
orgDatabase, orgDatabase)
if !IsDefaultOrgID(orgID) {
deepflowSystemServerView += fmt.Sprintf(" UNION ALL SELECT * FROM %s.deepflow_system_server", orgDatabase)
}
deepflowSystemServerView := fmt.Sprintf("CREATE VIEW IF NOT EXISTS %s.`%s` AS SELECT * FROM %s.`%s` UNION ALL SELECT * FROM deepflow_system.deepflow_system_server",
t.OrgDatabase(orgID), "deepflow_system", t.OrgDatabase(orgID), "deepflow_system_agent")
createViewSqls = append(createViewSqls, deepflowSystemServerView)
}
if t.Database == "flow_tag" && t.GlobalName == "deepflow_system_server_custom_field" {
// recreate table flow_tag.deepflow_system_custom_field, for upgrade
if orgID == DEFAULT_ORG_ID || orgID == INVALID_ORG_ID {
dropTable := "DROP TABLE IF EXISTS flow_tag.deepflow_system_custom_field"
createViewSqls = append(createViewSqls, dropTable)
// recreate table xxxx_flow_tag.deepflow_system_custom_field, for upgrade
dropTable := fmt.Sprintf("DROP TABLE IF EXISTS %s.deepflow_system_custom_field", orgDatabase)
createViewSqls = append(createViewSqls, dropTable)

flowTagFieldView := fmt.Sprintf("CREATE VIEW IF NOT EXISTS %s.`deepflow_system_custom_field` AS SELECT * FROM %s.`deepflow_system_agent_custom_field` UNION ALL SELECT * FROM flow_tag.deepflow_system_server_custom_field",
orgDatabase, orgDatabase)
if !IsDefaultOrgID(orgID) {
flowTagFieldView += fmt.Sprintf(" UNION ALL SELECT * FROM %s.deepflow_system_server_custom_field", orgDatabase)
}
flowTagFieldView := fmt.Sprintf("CREATE VIEW IF NOT EXISTS %s.`%s` AS SELECT * FROM %s.`%s` UNION ALL SELECT * FROM flow_tag.deepflow_system_server_custom_field",
OrgDatabasePrefix(orgID)+"flow_tag", "deepflow_system_custom_field", OrgDatabasePrefix(orgID)+"flow_tag", "deepflow_system_agent_custom_field")
createViewSqls = append(createViewSqls, flowTagFieldView)
}
if t.Database == "flow_tag" && t.GlobalName == "deepflow_system_server_custom_field_value" {
// recreate table flow_tag.deepflow_system_custom_field_value, for upgrade
if orgID == DEFAULT_ORG_ID || orgID == INVALID_ORG_ID {
dropTable := "DROP TABLE IF EXISTS flow_tag.deepflow_system_custom_field_value"
createViewSqls = append(createViewSqls, dropTable)
// recreate table xxxx_flow_tag.deepflow_system_custom_field_value, for upgrade
dropTable := fmt.Sprintf("DROP TABLE IF EXISTS %s.deepflow_system_custom_field_value", orgDatabase)
createViewSqls = append(createViewSqls, dropTable)

flowTagFieldValueView := fmt.Sprintf("CREATE VIEW IF NOT EXISTS %s.`deepflow_system_custom_field_value` AS SELECT * FROM %s.`deepflow_system_agent_custom_field_value` UNION ALL SELECT * FROM flow_tag.deepflow_system_server_custom_field_value",
orgDatabase, orgDatabase)
if !IsDefaultOrgID(orgID) {
flowTagFieldValueView += fmt.Sprintf(" UNION ALL SELECT * FROM %s.deepflow_system_server_custom_field_value", orgDatabase)
}
flowTagFieldValueView := fmt.Sprintf("CREATE VIEW IF NOT EXISTS %s.`%s` AS SELECT * FROM %s.`%s` UNION ALL SELECT * FROM flow_tag.deepflow_system_server_custom_field_value",
OrgDatabasePrefix(orgID)+"flow_tag", "deepflow_system_custom_field_value", OrgDatabasePrefix(orgID)+"flow_tag", "deepflow_system_agent_custom_field_value")
createViewSqls = append(createViewSqls, flowTagFieldValueView)
}
return createViewSqls
Expand Down

0 comments on commit 9868c9c

Please sign in to comment.