mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Simplify some code and comments.
Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
This commit is contained in:
parent
46683dd67d
commit
2be543e65a
|
@ -182,7 +182,7 @@ func convertToEndpoints(o interface{}) (*apiv1.Endpoints, error) {
|
|||
}
|
||||
|
||||
func endpointsSource(ep *apiv1.Endpoints) string {
|
||||
return "endpoints/" + ep.ObjectMeta.Namespace + "/" + ep.ObjectMeta.Name
|
||||
return endpointsSourceFromNamespaceAndName(ep.Namespace, ep.Name)
|
||||
}
|
||||
|
||||
func endpointsSourceFromNamespaceAndName(namespace, name string) string {
|
||||
|
|
|
@ -122,7 +122,7 @@ func convertToIngress(o interface{}) (*v1beta1.Ingress, error) {
|
|||
}
|
||||
|
||||
func ingressSource(s *v1beta1.Ingress) string {
|
||||
return "ingress/" + s.Namespace + "/" + s.Name
|
||||
return ingressSourceFromNamespaceAndName(s.Namespace, s.Name)
|
||||
}
|
||||
|
||||
func ingressSourceFromNamespaceAndName(namespace, name string) string {
|
||||
|
|
|
@ -155,7 +155,6 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy of discovery.Discoverer to avoid import cycle.
|
||||
// This is only for internal use.
|
||||
type discoverer interface {
|
||||
Run(ctx context.Context, up chan<- []*targetgroup.Group)
|
||||
|
|
|
@ -117,7 +117,7 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
|
|||
// Run discoverer and start a goroutine to read results.
|
||||
go d.discovery.Run(ctx, ch)
|
||||
resChan := make(chan map[string]*targetgroup.Group)
|
||||
go readResultWithoutTimeout(t, ch, d.expectedMaxItems, time.Second, resChan)
|
||||
go readResultWithTimeout(t, ch, d.expectedMaxItems, time.Second, resChan)
|
||||
|
||||
dd, ok := d.discovery.(hasSynced)
|
||||
if !ok {
|
||||
|
@ -139,9 +139,9 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// readResultWithoutTimeout reads all targegroups from channel with timeout.
|
||||
// readResultWithTimeout reads all targegroups from channel with timeout.
|
||||
// It merges targegroups by source and sends the result to result channel.
|
||||
func readResultWithoutTimeout(t *testing.T, ch <-chan []*targetgroup.Group, max int, timeout time.Duration, resChan chan<- map[string]*targetgroup.Group) {
|
||||
func readResultWithTimeout(t *testing.T, ch <-chan []*targetgroup.Group, max int, timeout time.Duration, resChan chan<- map[string]*targetgroup.Group) {
|
||||
allTgs := make([][]*targetgroup.Group, 0)
|
||||
|
||||
Loop:
|
||||
|
|
|
@ -38,8 +38,6 @@ type Node struct {
|
|||
queue *workqueue.Type
|
||||
}
|
||||
|
||||
var _ discoverer = &Node{}
|
||||
|
||||
// NewNode returns a new node discovery.
|
||||
func NewNode(l log.Logger, inf cache.SharedInformer) *Node {
|
||||
if l == nil {
|
||||
|
@ -130,7 +128,7 @@ func convertToNode(o interface{}) (*apiv1.Node, error) {
|
|||
}
|
||||
|
||||
func nodeSource(n *apiv1.Node) string {
|
||||
return "node/" + n.Name
|
||||
return nodeSourceFromName(n.Name)
|
||||
}
|
||||
|
||||
func nodeSourceFromName(name string) string {
|
||||
|
|
|
@ -215,7 +215,7 @@ func (p *Pod) buildPod(pod *apiv1.Pod) *targetgroup.Group {
|
|||
}
|
||||
|
||||
func podSource(pod *apiv1.Pod) string {
|
||||
return "pod/" + pod.Namespace + "/" + pod.Name
|
||||
return podSourceFromNamespaceAndName(pod.Namespace, pod.Name)
|
||||
}
|
||||
|
||||
func podSourceFromNamespaceAndName(namespace, name string) string {
|
||||
|
|
|
@ -127,7 +127,7 @@ func convertToService(o interface{}) (*apiv1.Service, error) {
|
|||
}
|
||||
|
||||
func serviceSource(s *apiv1.Service) string {
|
||||
return "svc/" + s.Namespace + "/" + s.Name
|
||||
return serviceSourceFromNamespaceAndName(s.Namespace, s.Name)
|
||||
}
|
||||
|
||||
func serviceSourceFromNamespaceAndName(namespace, name string) string {
|
||||
|
|
Loading…
Reference in a new issue