MCPcopy Index your code
hub / github.com/cortexproject/cortex / runtimeConfigHandler

Function runtimeConfigHandler

pkg/cortex/runtime_config.go:132–176  ·  view source on GitHub ↗
(runtimeCfgManager *runtimeconfig.Manager, defaultLimits validation.Limits)

Source from the content-addressed store, hash-verified

130}
131
132func runtimeConfigHandler(runtimeCfgManager *runtimeconfig.Manager, defaultLimits validation.Limits) http.HandlerFunc {
133 return func(w http.ResponseWriter, r *http.Request) {
134 cfg, ok := runtimeCfgManager.GetConfig().(*RuntimeConfigValues)
135 if !ok || cfg == nil {
136 util.WriteTextResponse(w, "runtime config file doesn't exist")
137 return
138 }
139
140 var output any
141 switch r.URL.Query().Get("mode") {
142 case "diff":
143 // Default runtime config is just empty struct, but to make diff work,
144 // we set defaultLimits for every tenant that exists in runtime config.
145 defaultCfg := RuntimeConfigValues{}
146 defaultCfg.TenantLimits = map[string]*validation.Limits{}
147 for k, v := range cfg.TenantLimits {
148 if v != nil {
149 defaultCfg.TenantLimits[k] = &defaultLimits
150 }
151 }
152
153 cfgYaml, err := util.YAMLMarshalUnmarshal(cfg)
154 if err != nil {
155 http.Error(w, err.Error(), http.StatusInternalServerError)
156 return
157 }
158
159 defaultCfgYaml, err := util.YAMLMarshalUnmarshal(defaultCfg)
160 if err != nil {
161 http.Error(w, err.Error(), http.StatusInternalServerError)
162 return
163 }
164
165 output, err = util.DiffConfig(defaultCfgYaml, cfgYaml)
166 if err != nil {
167 http.Error(w, err.Error(), http.StatusInternalServerError)
168 return
169 }
170
171 default:
172 output = cfg
173 }
174 util.WriteYAMLResponse(w, output)
175 }
176}

Callers 1

initRuntimeConfigMethod · 0.85

Calls 8

WriteTextResponseFunction · 0.92
YAMLMarshalUnmarshalFunction · 0.92
DiffConfigFunction · 0.92
WriteYAMLResponseFunction · 0.92
GetConfigMethod · 0.65
GetMethod · 0.65
QueryMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected