Skip to content

Commit

Permalink
feat: include system cluster rollup setting in App Settings API response
Browse files Browse the repository at this point in the history
  • Loading branch information
silenceqi committed Jan 21, 2025
1 parent eb3715b commit 19edb4e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"infini.sh/framework/core/api"
"infini.sh/framework/core/host"
model2 "infini.sh/framework/core/model"
"infini.sh/framework/core/util"
elastic2 "infini.sh/framework/modules/elastic"
_ "time/tzdata"

Expand Down Expand Up @@ -185,6 +186,29 @@ func main() {
}
return err
})
api.RegisterAppSetting("system_cluster", func() interface{} {
client := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
ver := client.GetVersion()
if ver.Distribution != elastic.Easysearch {
return map[string]interface{}{
"rollup_enabled": false,
}
}
settings, err := client.GetClusterSettings(nil)
if err != nil {
log.Errorf("failed to get cluster settings with system cluster: %v", err)
return nil
}

rollupEnabled, _ := util.GetMapValueByKeys([]string{"persistent", "rollup", "search", "enabled"}, settings)
rollupEnabledValue := false
if v, ok := rollupEnabled.(string); ok && v == "true" {
rollupEnabledValue = true
}
return map[string]interface{}{
"rollup_enabled": rollupEnabledValue,
}
})
}

if !global.Env().SetupRequired() {
Expand Down

0 comments on commit 19edb4e

Please sign in to comment.