-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented Datasource through Cue template rendering
- Loading branch information
1 parent
5af25bf
commit 39a85f6
Showing
23 changed files
with
416 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
config/crd/bases/monitor.kubeblocks.io_metricsexportersinks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package monitor | ||
|
||
import ( | ||
"cuelang.org/go/cue" | ||
"embed" | ||
intctrlutil "github.com/apecloud/kubeblocks/internal/controllerutil" | ||
"github.com/leaanthony/debme" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var ( | ||
//go:embed cue/* | ||
cueTemplates embed.FS | ||
cacheCtx = map[string]interface{}{} | ||
) | ||
|
||
func getCacheCUETplValue(key string, valueCreator func() (*intctrlutil.CUETpl, error)) (*intctrlutil.CUETpl, error) { | ||
vIf, ok := cacheCtx[key] | ||
if ok { | ||
return vIf.(*intctrlutil.CUETpl), nil | ||
} | ||
v, err := valueCreator() | ||
if err != nil { | ||
return nil, err | ||
} | ||
cacheCtx[key] = v | ||
return v, err | ||
} | ||
|
||
func buildFromCUEForOTel(tplName string, fillMap map[string]any, lookupKey string) ([]byte, error) { | ||
cueFS, _ := debme.FS(cueTemplates, "cue") | ||
cueTpl, err := getCacheCUETplValue(tplName, func() (*intctrlutil.CUETpl, error) { | ||
return intctrlutil.NewCUETplFromBytes(cueFS.ReadFile(tplName)) | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cueValue := intctrlutil.NewCUEBuilder(*cueTpl) | ||
|
||
for k, v := range fillMap { | ||
if err := cueValue.FillObj(k, v); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
value := cueValue.Value.LookupPath(cue.ParsePath(lookupKey)) | ||
bytes, err := value.MarshalJSON() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var jsonObj interface{} | ||
if err := yaml.Unmarshal(bytes, &jsonObj); err != nil { | ||
return nil, err | ||
} | ||
yamlBytes, err := yaml.Marshal(jsonObj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return yamlBytes, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package monitor | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
yamlv2 "gopkg.in/yaml.v2" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var _ = Describe("monitor_controller", func() { | ||
|
||
It("should generate config correctly from config yaml", func() { | ||
Eventually(func(g Gomega) { | ||
valMap := map[string]any{ | ||
"meta.transport": "http", | ||
//"meta.allow_native_password": false, | ||
//"meta.endpoint": "http://", | ||
"meta.password": "labels[\"pass\"]", | ||
} | ||
tplName := "test.cue" | ||
bytes, err := buildFromCUEForOTel(tplName, valMap, "output") | ||
node := yaml.Node{} | ||
err = node.Encode(bytes) | ||
|
||
Expect(err).ShouldNot(HaveOccurred()) | ||
slice := yamlv2.MapSlice{} | ||
err = yamlv2.Unmarshal(bytes, &slice) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(bytes).ShouldNot(BeNil()) | ||
|
||
}).Should(Succeed()) | ||
}) | ||
|
||
It("should generate config correctly from config yaml", func() { | ||
Eventually(func(g Gomega) { | ||
|
||
}).Should(Succeed()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
parameters: { | ||
endpoint: "" | ||
} | ||
|
||
output: | ||
loki: | ||
endpoint: parameters.endpoint | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
controllers/monitor/config/cue/extension/apecloud_engine_observer.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
parameters: { | ||
pod_observer: *"apecloud_k8s_observer" | string | ||
container_observer: *"runtime_container" | string | ||
scraper_config_file: *"/opt/oteld/etc/scraper.yaml" | string | ||
} | ||
|
||
|
||
|
||
output: | ||
apecloud_engine_observer: { | ||
pod_observer: parameters.pod_observer | ||
container_observer: parameters.container_observer | ||
scraper_config_file: parameters.scraper_config_file | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
controllers/monitor/config/cue/extension/runtime_container.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
parameters: { | ||
enable: *true | bool | ||
container_runtime_type: *"containerd" | string | ||
} | ||
|
||
|
||
output: | ||
runtime_contaienr: { | ||
enable: parameters.enable | ||
container_runtime_type: parameters.container_runtime_type | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
output: { | ||
"filelog/mysql/error": { | ||
type: | ||
include: [ "/data/mysql/log/mysqld-error.log"] | ||
include_file_name: false | ||
start_at: "beginning" | ||
} | ||
|
||
"filelog/mysql/slow":{ | ||
type: "slow" | ||
include:[ "/data/mysql/log/mysqld-slowquery.log"] | ||
include_file_name: false | ||
start_at: "beginning" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
controllers/monitor/config/cue/receiver/metrics/apecloudkubeletstats.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
parameters: { | ||
auth_type: *"service_account" | string | ||
collection_interval: *"10s" | string | ||
endpoint: *"http://localhost:10255" | string | ||
} | ||
|
||
output: | ||
apecloudkubeletstats: { | ||
auth_type: parameters.auth_type | ||
collection_interval: parameters.collection_interval | ||
endpoint: parameters.endpoint | ||
extra_metadata_labels: | ||
- k8s.volume.type | ||
- kubeblocks | ||
metric_groups: | ||
- container | ||
- pod | ||
- volume | ||
} | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
controllers/monitor/config/cue/receiver/metrics/apecloudmysql.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
parameters: { | ||
username: *"${env:MYSQL_USER}" | string | ||
password: *"${env:MYSQL_PASSWORD}" | string | ||
allow_native_passwords: *true | bool | ||
transport: *"tcp" | string | ||
collection_interval: *"${env:COLLECTION_INTERVAL}" | string | ||
} | ||
|
||
|
||
|
||
output: | ||
apecloudmysql: { | ||
username: parameters.username | ||
password: parameters.password | ||
allow_native_passwords: parameters.allow_native_passwords | ||
transport: parameters.transport | ||
collection_interval: parameters.collection_interval | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
controllers/monitor/config/cue/receiver/metrics/apecloudnode.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
parameters: { | ||
collection_interval: *"15s" | string | ||
} | ||
|
||
|
||
output: | ||
apecloudnode: { | ||
collection_interval: parameters.collection_interval | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
controllers/monitor/config/cue/receiver/metrics/k8s_cluster.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
parameters: { | ||
collection_interval: *"15s" | string | ||
} | ||
|
||
|
||
output: | ||
k8s_cluster: { | ||
collection_interval: parameters.collection_interval | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#meta: { | ||
endpoint: *"test" | string | ||
username: *"labels[\"conn_username\"]" | string | ||
password: *"labels[\"conn_password\"]" | string | ||
collection_interval: *"15s" | string | ||
transport: *"tcp" | string | ||
} | ||
|
||
output: | ||
apecloudmysql: { | ||
endpoint: parameter.endpoint | ||
username: parameter.username | ||
password: parameter.password | ||
collection_interval: parameter.collection_interval | ||
transport: parameter.transport | ||
} | ||
|
||
parameter: #meta |
Oops, something went wrong.