Skip to content

Commit 917514e

Browse files
committed
feat:support data visibility
1 parent b27547d commit 917514e

File tree

8 files changed

+107
-3
lines changed

8 files changed

+107
-3
lines changed

server/controller/db/mysql/migration/rawsql/init.sql

+10
Original file line numberDiff line numberDiff line change
@@ -2826,3 +2826,13 @@ CREATE TABLE IF NOT EXISTS ch_user (
28262826
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
28272827
)ENGINE=innodb DEFAULT CHARSET=utf8;
28282828
TRUNCATE TABLE ch_user;
2829+
2830+
CREATE TABLE IF NOT EXISTS ch_statistic_tag (
2831+
`db` VARCHAR(128) NOT NULL,
2832+
`table` VARCHAR(256) NOT NULL,
2833+
`type` VARCHAR(128) NOT NULL,
2834+
`name` VARCHAR(256) NOT NULL,
2835+
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
2836+
PRIMARY KEY (`db`, `table`, `type`, `name`)
2837+
)ENGINE=innodb DEFAULT CHARSET=utf8;
2838+
TRUNCATE TABLE ch_statistic_tag;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE IF NOT EXISTS ch_statistic_tag (
2+
`db` VARCHAR(128) NOT NULL,
3+
`table` VARCHAR(256) NOT NULL,
4+
`type` VARCHAR(128) NOT NULL,
5+
`name` VARCHAR(256) NOT NULL,
6+
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
7+
PRIMARY KEY (`db`, `table`, `type`, `name`)
8+
)ENGINE=innodb DEFAULT CHARSET=utf8;
9+
TRUNCATE TABLE ch_statistic_tag;
10+
11+
-- update db_version to latest, remeber update DB_VERSION_EXPECT in migrate/version.go
12+
UPDATE db_version SET version='6.6.1.13';
13+
-- modify end

server/controller/db/mysql/migration/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ package migration
1818

1919
const (
2020
DB_VERSION_TABLE = "db_version"
21-
DB_VERSION_EXPECTED = "6.6.1.12"
21+
DB_VERSION_EXPECTED = "6.6.1.13"
2222
)

server/controller/db/mysql/model/ch_model.go

+8
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,11 @@ type ChUser struct {
680680
Name string `gorm:"column:name;type:varchar(256)" json:"NAME"`
681681
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime:now,type:timestamp" json:"UPDATED_AT"`
682682
}
683+
684+
type ChStatisticTag struct {
685+
Name string `gorm:"primaryKey;column:name;type:varchar(256)" json:"NAME"`
686+
Db string `gorm:"primaryKey;column:db;type:varchar(128)" json:"DB"`
687+
Table string `gorm:"primaryKey;column:table;type:varchar(256)" json:"TABLE"`
688+
Type string `gorm:"primaryKey;column:type;type:varchar(128)" json:"TYPE"`
689+
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime:now,type:timestamp" json:"UPDATED_AT"`
690+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2024 Yunshan Networks
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package tagrecorder
18+
19+
import (
20+
"github.com/deepflowio/deepflow/server/controller/db/mysql"
21+
mysqlmodel "github.com/deepflowio/deepflow/server/controller/db/mysql/model"
22+
)
23+
24+
type ChStatisticTag struct {
25+
UpdaterComponent[mysqlmodel.ChStatisticTag, StatisticTagKey]
26+
}
27+
28+
func NewChStatisticTag() *ChStatisticTag {
29+
updater := &ChStatisticTag{
30+
newUpdaterComponent[mysqlmodel.ChStatisticTag, StatisticTagKey](
31+
RESOURCE_TYPE_STATISTIC_TAG,
32+
),
33+
}
34+
updater.updaterDG = updater
35+
return updater
36+
}
37+
38+
func (r *ChStatisticTag) generateNewData(db *mysql.DB) (map[StatisticTagKey]mysqlmodel.ChStatisticTag, bool) {
39+
40+
return nil, false
41+
}
42+
43+
func (r *ChStatisticTag) generateKey(dbItem mysqlmodel.ChStatisticTag) StatisticTagKey {
44+
return StatisticTagKey{Db: dbItem.Db, Table: dbItem.Table, Type: dbItem.Type, Name: dbItem.Name}
45+
}
46+
47+
func (r *ChStatisticTag) generateUpdateInfo(oldItem, newItem mysqlmodel.ChStatisticTag) (map[string]interface{}, bool) {
48+
49+
return nil, false
50+
}

server/controller/tagrecorder/const.go

+17
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ const (
119119
RESOURCE_TYPE_CH_LABEL_NAME = "ch_prometheus_label_name"
120120
RESOURCE_TYPE_CH_METRIC_NAME = "ch_prometheus_metric_name"
121121
RESOURCE_TYPE_CH_PROMETHEUS_TARGET_LABEL_LAYOUT = "ch_prometheus_target_label_layout"
122+
123+
RESOURCE_TYPE_STATISTIC_TAG = "ch_statistic_tag"
122124
)
123125

124126
const (
@@ -192,6 +194,8 @@ const (
192194

193195
CH_APP_LABEL_LIVE_VIEW = "app_label_live_view"
194196
CH_TARGET_LABEL_LIVE_VIEW = "target_label_live_view"
197+
198+
CH_STATISTIC_TAG = "statistic_tag"
195199
)
196200

197201
const (
@@ -880,6 +884,17 @@ const (
880884
SQL_SOURCE_MYSQL +
881885
SQL_LIFETIME +
882886
SQL_LAYOUT_FLAT
887+
CREATE_STATISTIC_TAG_SQL = SQL_CREATE_DICT +
888+
"(\n" +
889+
" `db` String,\n" +
890+
" `table` String,\n" +
891+
" `type` String,\n" +
892+
" `name` String\n" +
893+
")\n" +
894+
"PRIMARY KEY db, table, type, name\n" +
895+
SQL_SOURCE_MYSQL +
896+
SQL_LIFETIME +
897+
SQL_LAYOUT_FLAT
883898
)
884899

885900
const (
@@ -989,6 +1004,8 @@ var CREATE_SQL_MAP = map[string]string{
9891004

9901005
CH_APP_LABEL_LIVE_VIEW: CREATE_APP_LABEL_LIVE_VIEW_SQL,
9911006
CH_TARGET_LABEL_LIVE_VIEW: CREATE_TARGET_LABEL_LIVE_VIEW_SQL,
1007+
1008+
CH_STATISTIC_TAG: CREATE_STATISTIC_TAG_SQL,
9921009
}
9931010

9941011
var VTAP_TYPE_TO_DEVICE_TYPE = map[int]int{

server/controller/tagrecorder/constraint.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type MySQLChModel interface {
3131
mysqlmodel.ChDevice | mysqlmodel.ChIPRelation | mysqlmodel.ChPodGroup | mysqlmodel.ChNetwork | mysqlmodel.ChPod | mysqlmodel.ChPodCluster |
3232
mysqlmodel.ChPodNode | mysqlmodel.ChPodNamespace | mysqlmodel.ChTapType | mysqlmodel.ChVTap | mysqlmodel.ChPodK8sLabels | mysqlmodel.ChNodeType | mysqlmodel.ChGProcess | mysqlmodel.ChPodK8sAnnotation | mysqlmodel.ChPodK8sAnnotations |
3333
mysqlmodel.ChPodServiceK8sAnnotation | mysqlmodel.ChPodServiceK8sAnnotations |
34-
mysqlmodel.ChPodK8sEnv | mysqlmodel.ChPodK8sEnvs | mysqlmodel.ChPodService | mysqlmodel.ChChost | mysqlmodel.ChPolicy | mysqlmodel.ChNpbTunnel
34+
mysqlmodel.ChPodK8sEnv | mysqlmodel.ChPodK8sEnvs | mysqlmodel.ChPodService | mysqlmodel.ChChost | mysqlmodel.ChPolicy | mysqlmodel.ChNpbTunnel | mysqlmodel.ChStatisticTag
3535
}
3636

3737
// ch资源的组合key
3838
type ChModelKey interface {
3939
PrometheusTargetLabelKey | PrometheusAPPLabelKey | OSAPPTagKey | OSAPPTagsKey | CloudTagsKey | CloudTagKey | IntEnumTagKey | StringEnumTagKey | VtapPortKey | IPResourceKey | K8sLabelKey | PortIDKey | PortIPKey | PortDeviceKey | IDKey | DeviceKey |
4040
IPRelationKey | TapTypeKey | K8sLabelsKey | NodeTypeKey | K8sAnnotationKey | K8sAnnotationsKey |
41-
K8sEnvKey | K8sEnvsKey | PolicyKey
41+
K8sEnvKey | K8sEnvsKey | PolicyKey | StatisticTagKey
4242
}

server/controller/tagrecorder/key.go

+6
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ type PolicyKey struct {
138138
ACLGID int
139139
TunnelType int
140140
}
141+
type StatisticTagKey struct {
142+
Db string
143+
Table string
144+
Type string
145+
Name string
146+
}

0 commit comments

Comments
 (0)