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:
Alejandro Pedraza 2019-08-29 05:52:44 -05:00 committed by GitHub
parent 368d16f23c
commit 5d7499dc84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package watcher
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"strings"
"sync" "sync"
"github.com/linkerd/linkerd2/controller/k8s" "github.com/linkerd/linkerd2/controller/k8s"
@ -439,7 +440,7 @@ func (pp *portPublisher) endpointsToAddresses(endpoints *corev1.Endpoints) PodSe
Port: resolvedPort, Port: resolvedPort,
Pod: pod, Pod: pod,
OwnerName: owner.Name, OwnerName: owner.Name,
OwnerKind: owner.Kind, OwnerKind: strings.ToLower(owner.Kind),
} }
} }
} }

View File

@ -38,6 +38,7 @@ class NamespaceLanding extends React.Component {
getCurrentPromises: PropTypes.func.isRequired, getCurrentPromises: PropTypes.func.isRequired,
setCurrentRequests: PropTypes.func.isRequired, setCurrentRequests: PropTypes.func.isRequired,
urlsForResource: PropTypes.func.isRequired, urlsForResource: PropTypes.func.isRequired,
urlsForResourceNoStats: PropTypes.func.isRequired,
}).isRequired, }).isRequired,
classes: PropTypes.shape({}).isRequired, classes: PropTypes.shape({}).isRequired,
controllerNamespace: PropTypes.string.isRequired controllerNamespace: PropTypes.string.isRequired
@ -87,7 +88,7 @@ class NamespaceLanding extends React.Component {
// TODO: make this one request // TODO: make this one request
let apiRequests = [ let apiRequests = [
this.api.fetchMetrics(this.api.urlsForResource("namespace")) this.api.fetchMetrics(this.api.urlsForResourceNoStats("namespace"))
]; ];
if (!_isEmpty(this.state.selectedNs)) { if (!_isEmpty(this.state.selectedNs)) {
apiRequests = apiRequests.concat([ apiRequests = apiRequests.concat([

View File

@ -69,7 +69,7 @@ class ServiceMesh extends React.Component {
fetchMetrics: PropTypes.func.isRequired, fetchMetrics: PropTypes.func.isRequired,
getCurrentPromises: PropTypes.func.isRequired, getCurrentPromises: PropTypes.func.isRequired,
setCurrentRequests: PropTypes.func.isRequired, setCurrentRequests: PropTypes.func.isRequired,
urlsForResource: PropTypes.func.isRequired, urlsForResourceNoStats: PropTypes.func.isRequired,
}).isRequired, }).isRequired,
controllerNamespace: PropTypes.string.isRequired, controllerNamespace: PropTypes.string.isRequired,
productName: PropTypes.string, productName: PropTypes.string,
@ -161,7 +161,7 @@ class ServiceMesh extends React.Component {
this.api.setCurrentRequests([ this.api.setCurrentRequests([
this.api.fetchPods(this.props.controllerNamespace), 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()) this.serverPromise = Promise.all(this.api.getCurrentPromises())

View File

@ -242,7 +242,7 @@ class Tap extends React.Component {
pendingRequests: true pendingRequests: true
}); });
let url = this.api.urlsForResource("all"); let url = this.api.urlsForResourceNoStats("all");
this.api.setCurrentRequests([this.api.fetchMetrics(url)]); this.api.setCurrentRequests([this.api.fetchMetrics(url)]);
this.serverPromise = Promise.all(this.api.getCurrentPromises()) this.serverPromise = Promise.all(this.api.getCurrentPromises())
.then(([rsp]) => { .then(([rsp]) => {

View File

@ -92,7 +92,7 @@ class Top extends React.Component {
pendingRequests: true pendingRequests: true
}); });
let url = this.api.urlsForResource("all"); let url = this.api.urlsForResourceNoStats("all");
this.api.setCurrentRequests([this.api.fetchMetrics(url)]); this.api.setCurrentRequests([this.api.fetchMetrics(url)]);
this.serverPromise = Promise.all(this.api.getCurrentPromises()) this.serverPromise = Promise.all(this.api.getCurrentPromises())
.then(rsp => { .then(rsp => {

View File

@ -109,7 +109,7 @@ class TopRoutes extends React.Component {
} }
this.setState({ pendingRequests: true }); this.setState({ pendingRequests: true });
let allMetricsUrl = this.api.urlsForResource("all"); let allMetricsUrl = this.api.urlsForResourceNoStats("all");
this.api.setCurrentRequests([ this.api.setCurrentRequests([
this.api.fetchServices(), this.api.fetchServices(),
this.api.fetchMetrics(allMetricsUrl) this.api.fetchMetrics(allMetricsUrl)

View File

@ -139,6 +139,19 @@ const ApiHelpers = (pathPrefix, defaultMetricsWindow = '1m') => {
return resourceUrl; 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, // maintain a list of a component's requests,
// convenient for providing a cancel() functionality // convenient for providing a cancel() functionality
let currentRequests = []; let currentRequests = [];
@ -222,6 +235,7 @@ const ApiHelpers = (pathPrefix, defaultMetricsWindow = '1m') => {
getValidMetricsWindows: () => Object.keys(validMetricsWindows), getValidMetricsWindows: () => Object.keys(validMetricsWindows),
getMetricsWindowDisplayText, getMetricsWindowDisplayText,
urlsForResource, urlsForResource,
urlsForResourceNoStats,
PrefixedLink, PrefixedLink,
prefixLink, prefixLink,
ResourceLink, ResourceLink,