Skip to content

Commit 5766947

Browse files
authored
Merge pull request kubernetes#119437 from serathius/etcd-semantics
Fix the semantic meaning of etcd server within component statuses and metrics.
2 parents 8a053c7 + 03aad1f commit 5766947

File tree

7 files changed

+36
-42
lines changed

7 files changed

+36
-42
lines changed

pkg/registry/core/componentstatus/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ func (server *EtcdServer) DoServerCheck() (probe.Result, string, error) {
117117
if err != nil {
118118
return probe.Failure, "", err
119119
}
120-
return probe.Success, "", err
120+
return probe.Success, "ok", err
121121
}

staging/src/k8s.io/apiserver/pkg/server/storage/storage_factory.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -291,28 +291,17 @@ func Configs(storageConfig storagebackend.Config) []storagebackend.Config {
291291

292292
// Returns all storage configurations including those for group resource overrides
293293
func configs(storageConfig storagebackend.Config, grOverrides map[schema.GroupResource]groupResourceOverrides) []storagebackend.Config {
294-
locations := sets.NewString()
295-
configs := []storagebackend.Config{}
296-
for _, loc := range storageConfig.Transport.ServerList {
297-
// copy
298-
newConfig := storageConfig
299-
newConfig.Transport.ServerList = []string{loc}
300-
configs = append(configs, newConfig)
301-
locations.Insert(loc)
302-
}
294+
configs := []storagebackend.Config{storageConfig}
303295

304296
for _, override := range grOverrides {
305-
for _, loc := range override.etcdLocation {
306-
if locations.Has(loc) {
307-
continue
308-
}
309-
// copy
310-
newConfig := storageConfig
311-
override.Apply(&newConfig, &StorageCodecConfig{})
312-
newConfig.Transport.ServerList = []string{loc}
313-
configs = append(configs, newConfig)
314-
locations.Insert(loc)
297+
if len(override.etcdLocation) == 0 {
298+
continue
315299
}
300+
// copy
301+
newConfig := storageConfig
302+
override.Apply(&newConfig, &StorageCodecConfig{})
303+
newConfig.Transport.ServerList = override.etcdLocation
304+
configs = append(configs, newConfig)
316305
}
317306
return configs
318307
}

staging/src/k8s.io/apiserver/pkg/server/storage/storage_factory_test.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,33 +191,36 @@ func TestConfigs(t *testing.T) {
191191
defaultEtcdLocations := []string{"http://127.0.0.1", "http://127.0.0.2"}
192192

193193
testCases := []struct {
194-
resource schema.GroupResource
194+
resource *schema.GroupResource
195195
servers []string
196196
wantConfigs []storagebackend.Config
197197
}{
198198
{
199199
wantConfigs: []storagebackend.Config{
200-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.1"}}, Prefix: "/registry", Paging: true},
201-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.2"}}, Prefix: "/registry", Paging: true},
200+
{Transport: storagebackend.TransportConfig{ServerList: defaultEtcdLocations}, Prefix: "/registry", Paging: true},
202201
},
203202
},
204203
{
205-
resource: schema.GroupResource{Group: example.GroupName, Resource: "resource"},
204+
resource: &schema.GroupResource{Group: example.GroupName, Resource: "resource"},
205+
servers: []string{},
206+
wantConfigs: []storagebackend.Config{
207+
{Transport: storagebackend.TransportConfig{ServerList: defaultEtcdLocations}, Prefix: "/registry", Paging: true},
208+
},
209+
},
210+
{
211+
resource: &schema.GroupResource{Group: example.GroupName, Resource: "resource"},
206212
servers: []string{"http://127.0.0.1:10000"},
207213
wantConfigs: []storagebackend.Config{
208-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.1"}}, Prefix: "/registry", Paging: true},
209-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.2"}}, Prefix: "/registry", Paging: true},
214+
{Transport: storagebackend.TransportConfig{ServerList: defaultEtcdLocations}, Prefix: "/registry", Paging: true},
210215
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.1:10000"}}, Prefix: "/registry", Paging: true},
211216
},
212217
},
213218
{
214-
resource: schema.GroupResource{Group: example.GroupName, Resource: "resource"},
219+
resource: &schema.GroupResource{Group: example.GroupName, Resource: "resource"},
215220
servers: []string{"http://127.0.0.1:10000", "https://127.0.0.1", "http://127.0.0.2"},
216221
wantConfigs: []storagebackend.Config{
217-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.1"}}, Prefix: "/registry", Paging: true},
218-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.2"}}, Prefix: "/registry", Paging: true},
219-
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.1:10000"}}, Prefix: "/registry", Paging: true},
220-
{Transport: storagebackend.TransportConfig{ServerList: []string{"https://127.0.0.1"}}, Prefix: "/registry", Paging: true},
222+
{Transport: storagebackend.TransportConfig{ServerList: defaultEtcdLocations}, Prefix: "/registry", Paging: true},
223+
{Transport: storagebackend.TransportConfig{ServerList: []string{"http://127.0.0.1:10000", "https://127.0.0.1", "http://127.0.0.2"}}, Prefix: "/registry", Paging: true},
221224
},
222225
},
223226
}
@@ -230,8 +233,8 @@ func TestConfigs(t *testing.T) {
230233
},
231234
}
232235
storageFactory := NewDefaultStorageFactory(defaultConfig, "", codecs, NewDefaultResourceEncodingConfig(scheme), NewResourceConfig(), nil)
233-
if len(test.servers) > 0 {
234-
storageFactory.SetEtcdLocation(test.resource, test.servers)
236+
if test.resource != nil {
237+
storageFactory.SetEtcdLocation(*test.resource, test.servers)
235238
}
236239

237240
got := storageFactory.Configs()

staging/src/k8s.io/apiserver/pkg/storage/etcd3/metrics/metrics.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ var (
8484
},
8585
[]string{"endpoint"},
8686
)
87-
storageSizeDescription = compbasemetrics.NewDesc("apiserver_storage_size_bytes", "Size of the storage database file physically allocated in bytes.", []string{"server"}, nil, compbasemetrics.ALPHA, "")
87+
storageSizeDescription = compbasemetrics.NewDesc("apiserver_storage_size_bytes", "Size of the storage database file physically allocated in bytes.", []string{"cluster"}, nil, compbasemetrics.ALPHA, "")
8888
storageMonitor = &monitorCollector{}
8989
etcdEventsReceivedCounts = compbasemetrics.NewCounterVec(
9090
&compbasemetrics.CounterOpts{
@@ -274,21 +274,21 @@ func (c *monitorCollector) CollectWithStability(ch chan<- compbasemetrics.Metric
274274
}
275275

276276
for i, m := range monitors {
277-
server := fmt.Sprintf("etcd-%d", i)
277+
cluster := fmt.Sprintf("etcd-%d", i)
278278

279-
klog.V(4).InfoS("Start collecting storage metrics", "server", server)
279+
klog.V(4).InfoS("Start collecting storage metrics", "cluster", cluster)
280280
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
281281
metrics, err := m.Monitor(ctx)
282282
cancel()
283283
m.Close()
284284
if err != nil {
285-
klog.InfoS("Failed to get storage metrics", "server", server, "err", err)
285+
klog.InfoS("Failed to get storage metrics", "cluster", cluster, "err", err)
286286
continue
287287
}
288288

289-
metric, err := compbasemetrics.NewConstMetric(storageSizeDescription, compbasemetrics.GaugeValue, float64(metrics.Size), server)
289+
metric, err := compbasemetrics.NewConstMetric(storageSizeDescription, compbasemetrics.GaugeValue, float64(metrics.Size), cluster)
290290
if err != nil {
291-
klog.ErrorS(err, "Failed to create metric", "server", server)
291+
klog.ErrorS(err, "Failed to create metric", "cluster", cluster)
292292
}
293293
ch <- metric
294294
}

test/instrumentation/documentation/documentation-list.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,7 @@
37603760
type: Custom
37613761
stabilityLevel: ALPHA
37623762
labels:
3763-
- server
3763+
- cluster
37643764
- name: transformation_duration_seconds
37653765
subsystem: storage
37663766
namespace: apiserver

test/instrumentation/documentation/documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
932932
<td class="metric_stability_level" data-stability="alpha">ALPHA</td>
933933
<td class="metric_type" data-type="custom">Custom</td>
934934
<td class="metric_description">Size of the storage database file physically allocated in bytes.</td>
935-
<td class="metric_labels_varying"><div class="metric_label">server</div></td>
935+
<td class="metric_labels_varying"><div class="metric_label">cluster</div></td>
936936
<td class="metric_labels_constant"></td>
937937
<td class="metric_deprecated_version"></td></tr>
938938
<tr class="metric"><td class="metric_name">apiserver_storage_transformation_duration_seconds</td>

test/integration/metrics/metrics_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ func TestAPIServerProcessMetrics(t *testing.T) {
7777
}
7878

7979
func TestAPIServerStorageMetrics(t *testing.T) {
80-
s := kubeapiservertesting.StartTestServerOrDie(t, nil, nil, framework.SharedEtcd())
80+
config := framework.SharedEtcd()
81+
config.Transport.ServerList = []string{config.Transport.ServerList[0], config.Transport.ServerList[0]}
82+
s := kubeapiservertesting.StartTestServerOrDie(t, nil, nil, config)
8183
defer s.TearDownFn()
8284

8385
metrics, err := scrapeMetrics(s)

0 commit comments

Comments
 (0)