-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: Move collectors pkg to internal dir #632
Conversation
Yes, I was looking at that as well, sounds good improvement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this. Happy to do the rebase in case #633 merges first.
pkg/collector/builder.go
Outdated
@@ -0,0 +1,83 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure builder.go
is the right name here. Maybe metric_family.go
instead as it is mostly concerned of groups of metrics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, should we move these to the metrics pkg instead to metric_family.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a great idea! Some of these could even be methods on the Family
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxinden which ones of the below were you thinking of binding to the Family
struct? As all of them accept []metrics.FamilyGenerator
and binding them to a single instance of the FamilyGenerator
we would still need the functions that loop through the slices.
Also was thinking of moving it to pkg/metrics/family.go
, sgty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of:
func (f *FamilyGenerator) GenerateHeader() string {
header := strings.Builder{}
header.WriteString("# HELP ")
header.WriteString(f.Name)
header.WriteByte(' ')
header.WriteString(f.Help)
header.WriteByte('\n')
header.WriteString("# TYPE ")
header.WriteString(f.Name)
header.WriteByte(' ')
header.WriteString(string(f.Type))
return header.String()
}
Keeping the looping logic in ExtractMetricFamilyHeaders
. But I can do that in a follow up.
Also was thinking of moving it to pkg/metrics/family.go, sgty?
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the looping logic in ExtractMetricFamilyHeaders.
Where would that live?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe alongside the FamilyGenerator
struct inside pkg/metrics/generator.go
?
@lilic instead of cf42c78, what do you think about: diff --git a/pkg/metrics_store/metrics_store_test.go b/pkg/metrics_store/metrics_store_test.go
index 6199d89..c750df7 100644
--- a/pkg/metrics_store/metrics_store_test.go
+++ b/pkg/metrics_store/metrics_store_test.go
@@ -9,9 +9,19 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
- "k8s.io/kube-state-metrics/pkg/metric"
)
+// Mock metricFamily instead of importing /pkg/metric to prevent cyclic
+// dependency.
+type metricFamily struct {
+ value string
+}
+
+// Implement FamilyStringer interface.
+func (f *metricFamily) String() string {
+ return f.value
+}
+
func TestObjectsSameNameDifferentNamespaces(t *testing.T) {
serviceIDS := []string{"a", "b"}
@@ -21,15 +31,11 @@ func TestObjectsSameNameDifferentNamespaces(t *testing.T) {
t.Fatal(err)
}
- metric := metric.Metric{
- Name: "kube_service_info",
- LabelKeys: []string{"uid"},
- LabelValues: []string{string(o.GetUID())},
- Value: 1,
+ metricFamily := metricFamily{
+ fmt.Sprintf("kube_service_info{uid=\"%v\"} 1", string(o.GetUID())),
}
- metricFamily := metric.Family{&metric}
- return []FamilyStringer{metricFamily}
+ return []FamilyStringer{&metricFamily}
}
ms := NewMetricsStore([]string{"Information about service."}, genFunc) This would only alter test code but keep interfaces close to the caller side. |
I am curious where would this happen?
Makes sense! |
I am a bit confused. In regards to the merge conflicts, those are due to #636. In case rebasing is not that easy I am happy to help out. Sorry for the inconvenience. |
Sorry, I thought the initial comment was referring that can happen in my patch. All good 👍 |
No worries! Wasn't too bad after all :) |
@mxinden I addressed the comment above and rebased to current master, can you have another look, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fe41f0d
to
4832763
Compare
This makes the rest of the packages useful to be used in a standalone library without importing the kube-state-metrics specific collectors. * Rename collectors -> collector package * Rename metrics -> metric package * Add metricFamily mocking in tests to prevent cyclic dependency.
/approve |
/approve doesn't include lgtm /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brancz, LiliC, mxinden The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Could it be related to this PR if unable to |
@ikaldus You need to do |
I'm not sure, how I ended up with that github.com, but you are right... |
Rename the existing functions that are used in collectors to collector
pkg.
What this PR does / why we need it:
Expose helper functions that can be used outside of kube-state-metrics and move collector package
collectors
to internal package. Theinternal
directory is in the root of the project, this is so we can call this in themain.go
file, import of a path containing the element “internal” is disallowed if the importing code is outside the tree rooted at the parent of the “internal” directory.This is what we need from kube-state-metrics, but if @wanghaoran1988 needs something more, I can adjust things. Also open for naming discussions, etc. :)
cc @mxinden @brancz
Which issue(s) this PR fixes:
Fixes #579