Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
Signed-off-by: jyz0309 <[email protected]>
  • Loading branch information
jyz0309 committed Jan 6, 2025
1 parent 8080467 commit 563dbe7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ tsdb mock
tsdb run [<flags>]
Run the tsdb server.
example:
timelite tsdb run --config-path="./storage/conf" --storage-path="./storage/tsdb" --host="0.0.0.0:9090"
timelite tsdb run --config-file="config.json" --storage-path="./storage/tsdb" --host="0.0.0.0:9090"
```
20 changes: 10 additions & 10 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ func GetPromConfig(host string) *config.Config {
return promConf
}

func InitConfig(configPath, storagePath, host string) error {
if configPath != "" {
if _, err := os.Stat(configPath); !os.IsNotExist(err) {
func InitConfig(configFile, storagePath, host string) error {
if configFile != "" {
if _, err := os.Stat(configFile); !os.IsNotExist(err) {
// read config from file
err := GetConfig(configPath)
err := GetConfig(configFile)
if err != nil {
// if file not exist, create it
return err
}
}
}

dashboardPath := filepath.Join(filepath.Dir(configPath), "dashboards")
dashboardPath := filepath.Join(filepath.Dir(configFile), "dashboards")
logPath := filepath.Join(storagePath, "log")

promConf := GetPromConfig(host)
Expand All @@ -105,13 +105,13 @@ func InitConfig(configPath, storagePath, host string) error {
PromConfig: promConf,
Host: host,
}
return SaveConfig(configPath)
return SaveConfig(configFile)

}

func SaveConfig(configPath string) error {
if _, err := os.Stat(filepath.Dir(configPath)); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(configPath), 0755)
func SaveConfig(configFile string) error {
if _, err := os.Stat(filepath.Dir(configFile)); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(configFile), 0755)
if err != nil {
return fmt.Errorf("failed to mkdir config dir: %v", err)
}
Expand All @@ -120,5 +120,5 @@ func SaveConfig(configPath string) error {
if err != nil {
return err
}
return os.WriteFile(configPath, bytes, 0644)
return os.WriteFile(configFile, bytes, 0644)
}
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
storagePath := runTSDBCmd.Flag("storage-path", "The path to store the tsdb data.").Default("./storage/tsdb").
String()

configPath := runTSDBCmd.Flag("config-path", "The path to store the tsdb data.").Default("./storage/conf").String()
configFile := runTSDBCmd.Flag("config-file", "The config file path.").Default("./storage/conf").String()

parseCmd := kingpin.MustParse(app.Parse(os.Args[1:]))

Expand All @@ -50,9 +50,9 @@ func main() {
case tsdbMockCmd.FullCommand():
util.PromTestServer()
case runTSDBCmd.FullCommand():
prepareTSDBEnv(*configPath, *storagePath, *host)
prepareTSDBEnv(*configFile, *storagePath, *host)
// save config
conf.SaveConfig(filepath.Join(*configPath, "config.json"))
conf.SaveConfig(*configFile)

engine, err := engine.NewEngine(conf.DefaultConfig.StoragePath, conf.DefaultConfig.LogPath)
if err != nil {
Expand All @@ -65,8 +65,8 @@ func main() {
}
}

func prepareTSDBEnv(configPath, storagePath, host string) {
err := conf.InitConfig(configPath, storagePath, host)
func prepareTSDBEnv(configFile, storagePath, host string) {
err := conf.InitConfig(configFile, storagePath, host)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 563dbe7

Please sign in to comment.