Skip to content

Commit 4f7eb63

Browse files
authored
feat(observability-proxy): serve per-application logs and metrics (#5220)
## What this PR does Depends on #5219. This PR is stacked on that branch; the description covers only what it adds on top. Adds the per-application roots to the observability proxy, as described in the design proposals [Tenant application logs](cozystack/community#95) and [Tenant resource-consumption metrics](cozystack/community#94): ```text /apis/apps.cozystack.io/v1alpha1/namespaces/<ns>/<plural>/<name>/log/select/logsql/<endpoint> /apis/apps.cozystack.io/v1alpha1/namespaces/<ns>/<plural>/<name>/metrics/api/v1/<endpoint> ``` This lets the console show the logs and resource consumption of one application rather than of the whole namespace. What is added: - Plural-to-Kind mapping from an informer over `ApplicationDefinitions`. The Kind is looked up only after the `SubjectAccessReview` (`get <plural>/log` or `get <plural>/metrics`), so an unauthenticated caller cannot probe which plurals exist. An unknown plural answers `404`; an unsynced cache or a plural declared by two kinds answers `503`. - Logs: a second `extra_stream_filters` value with the application Kind and name, on top of the unchanged namespace filter. VictoriaLogs ANDs the two, on every endpoint including `tail`. - Metrics: the forced `extra_filters[]` becomes an OR of three branches, each still bound to the namespace: 1. series carrying the application identity labels; 2. series of the application's pods, found through `kube_pod_labels`; 3. series of the application's PVCs, found through `kube_persistentvolumeclaim_labels`. - The pod and PVC lookups cap the number of names (`--metrics-app-max-pods`, `--metrics-app-max-pvcs`); over the cap answers `422`. A failed pod or PVC lookup fails the request (`502`, or `504` on the deadline) rather than answer without the application's series, and so does a lookup that vmselect marks `isPartial`, since a storage node that did not answer leaves names out (a partial list already over the cap still answers `422`); vmselect's series-limit refusal of a lookup is passed through as `422`. A query that reads further back than `--metrics-app-lookback` (default 720h, chart value `observabilityProxy.metrics.appLookback`), or by an unknown amount, and a query whose samples lie at a time the lookup cannot cover answer `422` on the application root; this includes every query with an `@` modifier, `WITH` with a negative offset, and offsets that are not plain durations. The namespace root still serves them. `rollup_candlestick`, a backslash or a `#` comment outside a string, an offset directly followed by a minus (compound durations such as `-1h-30m` or `1h-2h`), and a subquery step that is not a plain duration are refused as well. The lookup reaches past the evaluation time by any negative offset and by two steps per subquery level. - Application routes require read access to the namespace root as well as the application subresource; a grant narrowed with `resourceNames` alone answers `403`. - The proxy's ClusterRole gains `list`/`watch` on `cozystack.io/applicationdefinitions`. No tenant RBAC change is needed: the `view` role already allows `get` on every `apps.cozystack.io` resource and subresource. - `/readyz` now also waits for the `ApplicationDefinitions` cache, so a missing CRD or RBAC rule keeps the whole proxy unready, namespace roots included. #### Data comes from the identity labels The application roots find data only through identity labels added by three PRs that are now in main: - #5215 `feat(monitoring-agents)`: export PVC labels from kube-state-metrics (PVC branch). - #5216 `feat(monitoring)`: stamp application identity on scraped series (identity branch). - #5217 `feat(monitoring-agents)`: keep application identity in container log streams (logs root). Merge after #5219. The pod branch does not depend on them, because `kube_pod_labels` already exports all pod labels. Logs and series written before those changes rolled out carry no identity and are reachable only through the namespace root. #### Security condition: a convenience filter, not an isolation boundary The application roots narrow the namespace roots; they do not isolate applications from each other. Each application route therefore requires two grants: the application subresource (`get <plural>/log` or `get <plural>/metrics`) and read access to the namespace root (`list cozystack.io/logs` or `cozystack.io/metrics` in the namespace). A grant narrowed with `resourceNames` alone is refused. Every tenant role that can read applications already has both. The application scope cannot isolate yet because: 1. The lineage webhook keeps `apps.cozystack.io/application.*` labels that a user sets on a pod or PVC that has no application owner, so such an object can claim another application's identity. 2. The webhook's `objectSelector` skips any object created with `internal.cozystack.io/managed-by-cozystack`, pods included, so forged labels on such an object are never examined. 3. The pod and PVC branches match by name over the lookup window, so an object that reuses the name of another application's recently deleted pod or PVC pulls that object's older series into scope. The proposed fix (a separate change to the lineage webhook) is to strip the identity labels when no owner resolves, and to stop skipping CREATE requests for objects carrying the managed-by label. #### Other known gaps - PVCs created from a StatefulSet's `volumeClaimTemplates` usually get no lineage labels, so their volume series are not in the application scope. - ingress-nginx series intentionally carry no application identity, so they are reachable only through the namespace root. - A request for an application that does not exist answers `200` with an empty result rather than `404`: the proxy checks authorization, not existence. Nothing leaks; whether a `404` is wanted is open for review. #### How it was tested - `go test -race` and `go vet` for the proxy packages, including a narrowed-grant test (access to application `a` only): every application path for `b` answers `403` and no request reaches the store. Name escaping in the pod and PVC branches is covered for regex metacharacters and quotes. - helm-unittest for `observability-proxy` (new RBAC rule). - Verified on a test cluster, with the three identity PRs above applied: the application logs root of a Redis instance returned only that instance's lines and none from a neighbouring pod in the same namespace; its application metrics root returned only the Redis pods' series. ### Screenshots No UI changes. ### Downstream repositories - [ ] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: Downstream: no trigger matched. Candidate: none affected, because the diff on top of #5219 is confined to the proxy's Go code and its own chart RBAC; it reads `ApplicationDefinitions` but does not change their semantics or the CRD. The security condition above may deserve a note in the design proposals in `cozystack/community`, which is not a trigger-map item. ### Release note ```release-note feat(observability-proxy): add per-application logs and metrics roots under `/apis/apps.cozystack.io/v1alpha1/namespaces/<ns>/<plural>/<name>/{log,metrics}/`, scoped by application identity labels. Data appears for logs and series collected after the application identity changes to Fluent Bit, VMAgent and kube-state-metrics are rolled out. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added a tenant-aware observability proxy for logs and metrics, with namespace and application scoping, access checks, and per-user request limits. * Enabled the proxy in the system package bundle and routed console log and metrics requests through it. * Added live log streaming and health, readiness, and metrics endpoints. * **Bug Fixes** * Invalid or excessive query parameters are rejected; requests with uncertain application-metric scope are refused rather than returning incomplete results. * **Tests** * Added end-to-end and integration coverage for tenant isolation, console routing, access controls, and log streaming. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 526f08e + 03a2edf commit 4f7eb63

22 files changed

Lines changed: 1678 additions & 50 deletions

‎cmd/observability-proxy/main.go‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
"github.com/prometheus/client_golang/prometheus/collectors"
4040
"github.com/prometheus/client_golang/prometheus/promhttp"
4141
"k8s.io/apimachinery/pkg/util/validation"
42+
"k8s.io/client-go/dynamic"
43+
"k8s.io/client-go/dynamic/dynamicinformer"
4244
"k8s.io/client-go/informers"
4345
"k8s.io/client-go/kubernetes"
4446
"k8s.io/client-go/tools/cache"
@@ -92,8 +94,15 @@ func parseFlags(args []string) (options, error) {
9294
fs.DurationVar(&o.metrics.Limits.MaxRange, "metrics-max-range", 30*24*time.Hour, "longest [start, end] and step a metrics request may use")
9395
fs.IntVar(&o.metrics.Limits.MaxPoints, "metrics-max-points", 11000, "most points per series a range query may return")
9496
fs.DurationVar(&o.metrics.Limits.MaxTimeout, "metrics-max-timeout", 30*time.Second, "timeout forwarded to vmselect; a longer client timeout is clamped; must be below --request-timeout when that is set")
97+
// Only the refusal threshold: the lookup itself spans the window the
98+
// query reads, and that estimate is a loose upper bound (every "("
99+
// counts as an implicit subquery), so the default is long enough to
100+
// serve month-long panels at a dashboard step.
101+
fs.DurationVar(&o.metrics.App.Lookback, "metrics-app-lookback", 30*24*time.Hour, "how far before the window an application metrics query may read; one reading further back, or by an unknown amount, answers 422")
102+
fs.IntVar(&o.metrics.App.MaxPods, "metrics-app-max-pods", 500, "most pods of one application in the lookup window; more answer 422")
103+
fs.IntVar(&o.metrics.App.MaxPVCs, "metrics-app-max-pvcs", 500, "most PVCs of one application in the lookup window; more answer 422")
95104
fs.IntVar(&o.limiter.MaxConcurrentPerUser, "max-concurrent-per-user", 10, "concurrent non-tail requests per user; 0 disables")
96-
fs.Float64Var(&o.limiter.RatePerUser, "rate-limit-per-user", 10, "sustained requests per second per user; 0 disables")
105+
fs.Float64Var(&o.limiter.RatePerUser, "rate-limit-per-user", 10, "sustained client requests per second per user; an application metrics request makes three store calls (pod lookup, PVC lookup, query); 0 disables")
97106
fs.IntVar(&o.limiter.RateBurst, "rate-limit-burst", 20, "request burst per user")
98107
fs.IntVar(&o.limiter.MaxTailsPerUser, "max-tails-per-user", 5, "open tails per user; 0 disables")
99108
fs.IntVar(&o.limiter.MaxTails, "max-tails", 200, "open tails in total; 0 disables")
@@ -132,6 +141,8 @@ func parseFlags(args []string) (options, error) {
132141
return o, errors.New("--metrics-shortterm-retention, --metrics-max-range and --metrics-max-timeout must be positive")
133142
case o.metrics.Limits.MaxPoints < 2:
134143
return o, errors.New("--metrics-max-points must be at least 2")
144+
case o.metrics.App.Lookback <= 0 || o.metrics.App.MaxPods < 1 || o.metrics.App.MaxPVCs < 1:
145+
return o, errors.New("--metrics-app-lookback, --metrics-app-max-pods and --metrics-app-max-pvcs must be positive")
135146
case o.logs.MaxTailResume < 0:
136147
return o, errors.New("--logs-max-tail-resume must not be negative")
137148
// The proxy's deadline starts before the request reaches vmselect, so
@@ -178,13 +189,24 @@ func run(o options) error {
178189
return fmt.Errorf("building client: %w", err)
179190
}
180191

192+
dynClient, err := dynamic.NewForConfig(restConfig)
193+
if err != nil {
194+
return fmt.Errorf("building dynamic client: %w", err)
195+
}
196+
181197
factory := informers.NewSharedInformerFactory(client, 0)
182198
namespaces := factory.Core().V1().Namespaces()
183199
lister := namespaces.Lister()
200+
appDefs := dynamicinformer.NewDynamicSharedInformerFactory(dynClient, 0).
201+
ForResource(observabilityproxy.ApplicationDefinitionsResource).Informer()
202+
if err := appDefs.AddIndexers(observabilityproxy.ApplicationPluralIndexers()); err != nil {
203+
return fmt.Errorf("indexing application definitions: %w", err)
204+
}
184205
factory.Start(ctx.Done())
206+
go appDefs.Run(ctx.Done())
185207
var ready atomic.Bool
186208
go func() {
187-
if cache.WaitForCacheSync(ctx.Done(), namespaces.Informer().HasSynced) {
209+
if cache.WaitForCacheSync(ctx.Done(), namespaces.Informer().HasSynced, appDefs.HasSynced) {
188210
ready.Store(true)
189211
}
190212
}()
@@ -198,13 +220,14 @@ func run(o options) error {
198220
Limiter: o.limiter,
199221
RequestTimeout: o.requestTimeout,
200222
TailIdleTimeout: o.tailIdleTimeout,
201-
}, observabilityproxy.NewAuthorizer(client, o.authCacheTTL), observabilityproxy.NewStoreResolver(lister, namespaces.Informer().HasSynced, o.rootTenant), reg)
223+
}, observabilityproxy.NewAuthorizer(client, o.authCacheTTL), observabilityproxy.NewStoreResolver(lister, namespaces.Informer().HasSynced, o.rootTenant),
224+
observabilityproxy.NewApplicationKinds(appDefs.GetIndexer(), appDefs.HasSynced), reg)
202225

203226
probes := http.NewServeMux()
204227
probes.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { _, _ = io.WriteString(w, "ok") })
205228
probes.HandleFunc("/readyz", func(w http.ResponseWriter, _ *http.Request) {
206229
if !ready.Load() {
207-
http.Error(w, "namespace cache not synced", http.StatusServiceUnavailable)
230+
http.Error(w, "namespace or application definition cache not synced", http.StatusServiceUnavailable)
208231
return
209232
}
210233
_, _ = io.WriteString(w, "ok")

‎cmd/observability-proxy/main_test.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func TestParseFlagsDefaults(t *testing.T) {
4040
if m.Limits.MaxRange != 30*24*time.Hour || m.Limits.MaxPoints != 11000 || m.Limits.MaxTimeout != 30*time.Second {
4141
t.Errorf("metrics limit defaults changed: %+v", m.Limits)
4242
}
43+
if m.App.Lookback != 30*24*time.Hour || m.App.MaxPods != 500 || m.App.MaxPVCs != 500 {
44+
t.Errorf("application scope defaults changed: %+v", m.App)
45+
}
4346
if m.RootTenant != o.rootTenant {
4447
t.Errorf("metrics root tenant = %q, want --root-tenant", m.RootTenant)
4548
}
@@ -63,13 +66,15 @@ func TestParseFlagsMetricsOverrides(t *testing.T) {
6366
o, err := parseFlags([]string{
6467
"--root-tenant=tenant-x", "--metrics-shortterm-store=fast", "--metrics-longterm-store=slow",
6568
"--metrics-shortterm-retention=24h", "--metrics-max-range=168h", "--metrics-max-points=500", "--metrics-max-timeout=10s",
69+
"--metrics-app-lookback=2h", "--metrics-app-max-pods=7", "--metrics-app-max-pvcs=3",
6670
})
6771
if err != nil {
6872
t.Fatal(err)
6973
}
7074
m := o.metrics
7175
if m.RootTenant != "tenant-x" || m.ShortTermStore != "fast" || m.LongTermStore != "slow" || m.ShortTermRetention != 24*time.Hour ||
72-
m.Limits.MaxRange != 168*time.Hour || m.Limits.MaxPoints != 500 || m.Limits.MaxTimeout != 10*time.Second {
76+
m.Limits.MaxRange != 168*time.Hour || m.Limits.MaxPoints != 500 || m.Limits.MaxTimeout != 10*time.Second ||
77+
m.App.Lookback != 2*time.Hour || m.App.MaxPods != 7 || m.App.MaxPVCs != 3 {
7378
t.Errorf("overrides not applied: %+v", m)
7479
}
7580
}
@@ -101,6 +106,12 @@ func TestParseFlagsInvalid(t *testing.T) {
101106
{"--metrics-max-range=0s"},
102107
{"--metrics-max-points=1"},
103108
{"--metrics-max-timeout=0s"},
109+
{"--metrics-app-lookback=-1h"},
110+
// Every query reads some time before its window, so a zero lookback
111+
// would refuse every application metrics query.
112+
{"--metrics-app-lookback=0s"},
113+
{"--metrics-app-max-pods=0"},
114+
{"--metrics-app-max-pvcs=0"},
104115
{"--unknown"},
105116
// The proxy would cut the request while vmselect is still within
106117
// the timeout it was given.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Copyright 2026 The Cozystack Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package observabilityproxy
18+
19+
import (
20+
"errors"
21+
"fmt"
22+
"slices"
23+
24+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
26+
"k8s.io/client-go/tools/cache"
27+
)
28+
29+
// ApplicationDefinitionsResource is where the plural of every application
30+
// kind is declared (api/v1alpha1/applicationdefinitions_types.go).
31+
var ApplicationDefinitionsResource = schema.GroupVersionResource{Group: "cozystack.io", Version: "v1alpha1", Resource: "applicationdefinitions"}
32+
33+
// ErrKindsNotSynced means the ApplicationDefinitions cache has not been
34+
// filled yet, so an unknown plural cannot be told from a missing one.
35+
var ErrKindsNotSynced = errors.New("application definitions not synced")
36+
37+
const pluralIndex = "plural"
38+
39+
// KindLookup maps an application plural, as it appears in paths and RBAC,
40+
// to the kind the lineage labels carry. An unknown plural is "", nil.
41+
type KindLookup interface {
42+
Kind(plural string) (string, error)
43+
}
44+
45+
// ApplicationPluralIndexers indexes ApplicationDefinitions by
46+
// spec.application.plural; the informer feeding ApplicationKinds needs it.
47+
func ApplicationPluralIndexers() cache.Indexers {
48+
return cache.Indexers{pluralIndex: func(obj any) ([]string, error) {
49+
u, ok := obj.(*unstructured.Unstructured)
50+
if !ok {
51+
return nil, nil
52+
}
53+
plural, _, _ := unstructured.NestedString(u.Object, "spec", "application", "plural")
54+
if plural == "" {
55+
return nil, nil
56+
}
57+
return []string{plural}, nil
58+
}}
59+
}
60+
61+
// ApplicationKinds is the one place the proxy maps a plural to its kind;
62+
// both application roots use it.
63+
type ApplicationKinds struct {
64+
indexer cache.Indexer
65+
hasSynced func() bool
66+
}
67+
68+
func NewApplicationKinds(indexer cache.Indexer, hasSynced func() bool) *ApplicationKinds {
69+
return &ApplicationKinds{indexer: indexer, hasSynced: hasSynced}
70+
}
71+
72+
func (k *ApplicationKinds) Kind(plural string) (string, error) {
73+
if !k.hasSynced() {
74+
return "", ErrKindsNotSynced
75+
}
76+
objs, err := k.indexer.ByIndex(pluralIndex, plural)
77+
if err != nil {
78+
return "", err
79+
}
80+
var kinds []string
81+
for _, obj := range objs {
82+
u, ok := obj.(*unstructured.Unstructured)
83+
if !ok {
84+
continue
85+
}
86+
kind, _, _ := unstructured.NestedString(u.Object, "spec", "application", "kind")
87+
if kind != "" && !slices.Contains(kinds, kind) {
88+
kinds = append(kinds, kind)
89+
}
90+
}
91+
switch len(kinds) {
92+
case 0:
93+
return "", nil
94+
case 1:
95+
return kinds[0], nil
96+
}
97+
// Picking one would scope the request to whichever definition the
98+
// cache happens to list first.
99+
slices.Sort(kinds)
100+
return "", fmt.Errorf("plural %q is declared for kinds %v", plural, kinds)
101+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2026 The Cozystack Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package observabilityproxy
18+
19+
import (
20+
"errors"
21+
"testing"
22+
23+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24+
"k8s.io/client-go/tools/cache"
25+
)
26+
27+
func appDefinition(name, kind, plural string) *unstructured.Unstructured {
28+
return &unstructured.Unstructured{Object: map[string]any{
29+
"apiVersion": "cozystack.io/v1alpha1",
30+
"kind": "ApplicationDefinition",
31+
"metadata": map[string]any{"name": name},
32+
"spec": map[string]any{"application": map[string]any{"kind": kind, "plural": plural, "singular": name}},
33+
}}
34+
}
35+
36+
func newTestKinds(t *testing.T, synced bool, defs ...*unstructured.Unstructured) *ApplicationKinds {
37+
t.Helper()
38+
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, ApplicationPluralIndexers())
39+
for _, d := range defs {
40+
if err := indexer.Add(d); err != nil {
41+
t.Fatal(err)
42+
}
43+
}
44+
return NewApplicationKinds(indexer, func() bool { return synced })
45+
}
46+
47+
func TestApplicationKinds(t *testing.T) {
48+
kinds := newTestKinds(t, true,
49+
appDefinition("postgres", "Postgres", "postgreses"),
50+
appDefinition("vm-instance", "VMInstance", "vminstances"),
51+
appDefinition("broken", "", "brokens"),
52+
)
53+
for plural, want := range map[string]string{"postgreses": "Postgres", "vminstances": "VMInstance", "postgres": "", "brokens": "", "": ""} {
54+
got, err := kinds.Kind(plural)
55+
if err != nil || got != want {
56+
t.Errorf("Kind(%q) = %q, %v; want %q", plural, got, err, want)
57+
}
58+
}
59+
}
60+
61+
func TestApplicationKindsNotSynced(t *testing.T) {
62+
kinds := newTestKinds(t, false, appDefinition("postgres", "Postgres", "postgreses"))
63+
if _, err := kinds.Kind("postgreses"); !errors.Is(err, ErrKindsNotSynced) {
64+
t.Fatalf("Kind before sync: err = %v, want ErrKindsNotSynced", err)
65+
}
66+
}
67+
68+
func TestApplicationKindsAmbiguous(t *testing.T) {
69+
kinds := newTestKinds(t, true, appDefinition("a", "Postgres", "postgreses"), appDefinition("b", "Postgresql", "postgreses"))
70+
if kind, err := kinds.Kind("postgreses"); err == nil {
71+
t.Fatalf("two kinds for one plural resolved to %q", kind)
72+
}
73+
same := newTestKinds(t, true, appDefinition("a", "Postgres", "postgreses"), appDefinition("b", "Postgres", "postgreses"))
74+
if kind, err := same.Kind("postgreses"); err != nil || kind != "Postgres" {
75+
t.Fatalf("duplicate definitions of one kind: %q, %v", kind, err)
76+
}
77+
}

0 commit comments

Comments
 (0)