mirror of https://github.com/linkerd/linkerd2.git
Avoid the dashboard requesting stats when not needed (#3338)
* Avoid the dashboard requesting stats when not needed Create an alternative to `urlsForResource` called `urlsForResourceNoStats` that makes use of the `skip_stats` parameter in the stats API (created in #1871) that doesn't query Prometheus when not needed. When testing using the dashboard looking at the linkerd namespace, queries per second went down from 2874 to 2756, a 4% decrease. Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
This commit is contained in:
parent
368d16f23c
commit
5d7499dc84
|
@ -3,6 +3,7 @@ package watcher
|
|||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/linkerd/linkerd2/controller/k8s"
|
||||
|
@ -439,7 +440,7 @@ func (pp *portPublisher) endpointsToAddresses(endpoints *corev1.Endpoints) PodSe
|
|||
Port: resolvedPort,
|
||||
Pod: pod,
|
||||
OwnerName: owner.Name,
|
||||
OwnerKind: owner.Kind,
|
||||
OwnerKind: strings.ToLower(owner.Kind),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class NamespaceLanding extends React.Component {
|
|||
getCurrentPromises: PropTypes.func.isRequired,
|
||||
setCurrentRequests: PropTypes.func.isRequired,
|
||||
urlsForResource: PropTypes.func.isRequired,
|
||||
urlsForResourceNoStats: PropTypes.func.isRequired,
|
||||
}).isRequired,
|
||||
classes: PropTypes.shape({}).isRequired,
|
||||
controllerNamespace: PropTypes.string.isRequired
|
||||
|
@ -87,7 +88,7 @@ class NamespaceLanding extends React.Component {
|
|||
|
||||
// TODO: make this one request
|
||||
let apiRequests = [
|
||||
this.api.fetchMetrics(this.api.urlsForResource("namespace"))
|
||||
this.api.fetchMetrics(this.api.urlsForResourceNoStats("namespace"))
|
||||
];
|
||||
if (!_isEmpty(this.state.selectedNs)) {
|
||||
apiRequests = apiRequests.concat([
|
||||
|
|
|
@ -69,7 +69,7 @@ class ServiceMesh extends React.Component {
|
|||
fetchMetrics: PropTypes.func.isRequired,
|
||||
getCurrentPromises: PropTypes.func.isRequired,
|
||||
setCurrentRequests: PropTypes.func.isRequired,
|
||||
urlsForResource: PropTypes.func.isRequired,
|
||||
urlsForResourceNoStats: PropTypes.func.isRequired,
|
||||
}).isRequired,
|
||||
controllerNamespace: PropTypes.string.isRequired,
|
||||
productName: PropTypes.string,
|
||||
|
@ -161,7 +161,7 @@ class ServiceMesh extends React.Component {
|
|||
|
||||
this.api.setCurrentRequests([
|
||||
this.api.fetchPods(this.props.controllerNamespace),
|
||||
this.api.fetchMetrics(this.api.urlsForResource("namespace"))
|
||||
this.api.fetchMetrics(this.api.urlsForResourceNoStats("namespace"))
|
||||
]);
|
||||
|
||||
this.serverPromise = Promise.all(this.api.getCurrentPromises())
|
||||
|
|
|
@ -242,7 +242,7 @@ class Tap extends React.Component {
|
|||
pendingRequests: true
|
||||
});
|
||||
|
||||
let url = this.api.urlsForResource("all");
|
||||
let url = this.api.urlsForResourceNoStats("all");
|
||||
this.api.setCurrentRequests([this.api.fetchMetrics(url)]);
|
||||
this.serverPromise = Promise.all(this.api.getCurrentPromises())
|
||||
.then(([rsp]) => {
|
||||
|
|
|
@ -92,7 +92,7 @@ class Top extends React.Component {
|
|||
pendingRequests: true
|
||||
});
|
||||
|
||||
let url = this.api.urlsForResource("all");
|
||||
let url = this.api.urlsForResourceNoStats("all");
|
||||
this.api.setCurrentRequests([this.api.fetchMetrics(url)]);
|
||||
this.serverPromise = Promise.all(this.api.getCurrentPromises())
|
||||
.then(rsp => {
|
||||
|
|
|
@ -109,7 +109,7 @@ class TopRoutes extends React.Component {
|
|||
}
|
||||
this.setState({ pendingRequests: true });
|
||||
|
||||
let allMetricsUrl = this.api.urlsForResource("all");
|
||||
let allMetricsUrl = this.api.urlsForResourceNoStats("all");
|
||||
this.api.setCurrentRequests([
|
||||
this.api.fetchServices(),
|
||||
this.api.fetchMetrics(allMetricsUrl)
|
||||
|
|
|
@ -139,6 +139,19 @@ const ApiHelpers = (pathPrefix, defaultMetricsWindow = '1m') => {
|
|||
return resourceUrl;
|
||||
};
|
||||
|
||||
const urlsForResourceNoStats = (type, namespace) => {
|
||||
// Traffic Performance Summary. This retrieves (non-Prometheus) stats for the given resource.
|
||||
let resourceUrl = '/api/tps-reports?skip_stats=true&resource_type=' + type;
|
||||
|
||||
if (_isEmpty(namespace)) {
|
||||
resourceUrl += '&all_namespaces=true';
|
||||
} else {
|
||||
resourceUrl += '&namespace=' + namespace;
|
||||
}
|
||||
|
||||
return resourceUrl;
|
||||
};
|
||||
|
||||
// maintain a list of a component's requests,
|
||||
// convenient for providing a cancel() functionality
|
||||
let currentRequests = [];
|
||||
|
@ -222,6 +235,7 @@ const ApiHelpers = (pathPrefix, defaultMetricsWindow = '1m') => {
|
|||
getValidMetricsWindows: () => Object.keys(validMetricsWindows),
|
||||
getMetricsWindowDisplayText,
|
||||
urlsForResource,
|
||||
urlsForResourceNoStats,
|
||||
PrefixedLink,
|
||||
prefixLink,
|
||||
ResourceLink,
|
||||
|
|
Loading…
Reference in New Issue