Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support use local file or directory as config for monitor components #712

Merged
merged 41 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3c791cb
Support config file for alertmanager
lucklove Aug 24, 2020
aaa706a
Support rules directory for prometheus
lucklove Aug 24, 2020
c3dbf3e
Support config file for grafana
lucklove Aug 25, 2020
8e20e58
Tidy go.mod
lucklove Aug 25, 2020
52f62f6
Fix check
lucklove Aug 25, 2020
4407113
Add unit test for grafana init dashboards
lucklove Aug 25, 2020
dedca50
Add Integration Testing
lucklove Aug 25, 2020
819810b
make tidy
lucklove Aug 26, 2020
32d0689
Remove useless file
lucklove Aug 26, 2020
2b6dfff
typo
lucklove Aug 26, 2020
a8a01dc
Debug test
lucklove Aug 26, 2020
ef364e8
Adjust prometheus default config place
lucklove Aug 26, 2020
7e9f5e1
Merge remote-tracking branch 'upstream/master' into config-file
lucklove Aug 26, 2020
3a6f25e
debug
lucklove Aug 26, 2020
ca67340
Fix
lucklove Aug 26, 2020
4b37e56
Fix test
lucklove Aug 26, 2020
f6ec11d
Fix test
lucklove Aug 26, 2020
3706e17
Fix test
lucklove Aug 26, 2020
452a961
Debug
lucklove Aug 26, 2020
45c59fb
Simplify test
lucklove Aug 26, 2020
7e3fb7e
Fix bash
lucklove Aug 26, 2020
c3c3cc8
Update pkg/cluster/spec/instance.go
lucklove Aug 27, 2020
c0ba5e8
Address comment
lucklove Aug 27, 2020
09adfbb
Merge branch 'master' into config-file
lucklove Aug 27, 2020
55cb207
Update pkg/cluster/spec/alertmanager.go
lucklove Aug 27, 2020
8f9f361
Add licence
lucklove Aug 27, 2020
356c473
Merge branch 'config-file' of https://github.com/lucklove/tiup into c…
lucklove Aug 27, 2020
df46c0a
Relative path detect
lucklove Aug 27, 2020
c9a9b8e
Fix skip field
lucklove Aug 27, 2020
e19625d
Add test
lucklove Aug 27, 2020
8504d70
Adjust style
lucklove Aug 27, 2020
aafafb0
Update components/dm/spec/grafana.go
lucklove Aug 27, 2020
179e9d8
Update pkg/cluster/spec/grafana.go
lucklove Aug 27, 2020
230866c
Update components/dm/spec/prometheus.go
lucklove Aug 27, 2020
40ab2c0
Fix check
lucklove Aug 27, 2020
f70046b
Merge branch 'config-file' of https://github.com/lucklove/tiup into c…
lucklove Aug 27, 2020
1636708
Merge branch 'master' into config-file
july2993 Aug 27, 2020
b8123c8
Fix test
lucklove Aug 27, 2020
df03bd5
Fix style
lucklove Aug 27, 2020
c717bf2
Filter files
lucklove Aug 27, 2020
478d3a3
Fix
lucklove Aug 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/dm/spec/topology_dm.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,11 @@ func (topo *Topology) Validate() error {
return err
}

return topo.dirConflictsDetect()
if err := topo.dirConflictsDetect(); err != nil {
return err
}

return spec.RelativePathDetect(topo)
}

// BaseTopo implements Topology interface.
Expand Down
6 changes: 4 additions & 2 deletions pkg/cluster/spec/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ func (i *BaseInstance) TransferLocalConfigDir(e executor.Executor, local, remote
}

for _, f := range files {
lucklove marked this conversation as resolved.
Show resolved Hide resolved
if err := i.TransferLocalConfigFile(e, path.Join(local, f.Name()), path.Join(remote, f.Name())); err != nil {
return errors.Annotatef(err, "transfer local config %s failed", path.Join(local, f.Name()))
localPath := path.Join(local, f.Name())
remotePath := path.Join(remote, f.Name())
if err := i.TransferLocalConfigFile(e, localPath, remotePath); err != nil {
return errors.Annotatef(err, "transfer local config (%s -> %s) failed", localPath, remotePath)
}
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ func (i *MonitorInstance) initRules(e executor.Executor, spec PrometheusSpec, pa
if err := i.TransferLocalConfigDir(e, spec.RuleDir, path.Join(paths.Deploy, "conf")); err != nil {
return errors.Annotate(err, "transfer prometheus rules failed")
}
} else { // Use the default ones
cmd := fmt.Sprintf("cp %[1]s/bin/prometheus/*.rules.yml %[1]s/conf/", paths.Deploy)
if _, _, err := e.Execute(cmd, false); err != nil {
return errors.Annotatef(err, "execute command failed: %s", err)
}
return nil
}

// Use the default ones
cmd := fmt.Sprintf("cp %[1]s/bin/prometheus/*.rules.yml %[1]s/conf/", paths.Deploy)
if _, _, err := e.Execute(cmd, false); err != nil {
return errors.Annotatef(err, "execute command failed: %s", err)
}

return nil
Expand Down
42 changes: 41 additions & 1 deletion pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,5 +674,45 @@ func (s *Specification) Validate() error {
return err
}

return s.validateTiSparkSpec()
if err := s.validateTiSparkSpec(); err != nil {
return err
}

return RelativePathDetect(s)
}

// RelativePathDetect detect if some specific path is relative path and report error
func RelativePathDetect(topo interface{}) error {
lucklove marked this conversation as resolved.
Show resolved Hide resolved
pathTypes := []string{
"ConfigFilePath",
"RuleDir",
"DashboardDir",
}

topoSpec := reflect.ValueOf(topo).Elem()

for i := 0; i < topoSpec.NumField(); i++ {
if isSkipField(topoSpec.Field(i)) {
continue
}

compSpecs := topoSpec.Field(i)
for index := 0; index < compSpecs.Len(); index++ {
compSpec := compSpecs.Index(index)

// Relateve path detect
for _, field := range pathTypes {
if j, found := findField(compSpec, field); found {
// `yaml:"xxxx,omitempty"`
fieldName := strings.Split(compSpec.Type().Field(j).Tag.Get("yaml"), ",")[0]
localPath := compSpec.Field(j).String()
if localPath != "" && !strings.HasPrefix(localPath, "/") {
return fmt.Errorf("relative path is not allowed for field %s: %s", fieldName, localPath)
}
}
}
}
}

return nil
}