Skip to content

Commit

Permalink
feat(kubernetes): Add support for excluding event loading on manifest… (
Browse files Browse the repository at this point in the history
#3796)

* feat(kubernetes): Add support for excluding event loading on manifests retrieval

* Address review comments.
  • Loading branch information
mtweten authored and ezimanyi committed Jun 20, 2019
1 parent fb933c0 commit 79698ac
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum Sort {
SIZE
}

T getManifest(String account, String location, String name);
T getManifest(String account, String location, String name, boolean includeEvents);

List<T> getClusterAndSortAscending(
String account, String location, String kind, String app, String cluster, Sort sort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class NoopManifestProvider implements ManifestProvider<Manifest> {
@Override
public Manifest getManifest(String account, String location, String name) {
public Manifest getManifest(String account, String location, String name, boolean includeEvents) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public KubernetesV2LiveManifestProvider(
}

@Override
public KubernetesV2Manifest getManifest(String account, String location, String name) {
public KubernetesV2Manifest getManifest(
String account, String location, String name, boolean includeEvents) {
if (!isAccountRelevant(account)) {
return null;
}
Expand Down Expand Up @@ -84,7 +85,10 @@ public KubernetesV2Manifest getManifest(String account, String location, String
String namespace = manifest.getNamespace();
KubernetesKind kind = manifest.getKind();

List<KubernetesManifest> events = credentials.eventsFor(kind, namespace, parsedName.getRight());
List<KubernetesManifest> events =
includeEvents
? credentials.eventsFor(kind, namespace, parsedName.getRight())
: Collections.emptyList();

List<KubernetesPodMetric.ContainerMetric> metrics = Collections.emptyList();
if (kind == KubernetesKind.POD && credentials.isMetrics()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public KubernetesV2ManifestProvider(
}

@Override
public KubernetesV2Manifest getManifest(String account, String location, String name) {
public KubernetesV2Manifest getManifest(
String account, String location, String name, boolean includeEvents) {
if (!isAccountRelevant(account)) {
return null;
}
Expand Down Expand Up @@ -93,7 +94,7 @@ public KubernetesV2Manifest getManifest(String account, String location, String

CacheData data = dataOptional.get();

return fromCacheData(data, account);
return fromCacheData(data, account, includeEvents);
}

@Override
Expand All @@ -115,8 +116,8 @@ public List<KubernetesV2Manifest> getClusterAndSortAscending(
.map(
cd ->
fromCacheData(
cd,
account)) // todo(lwander) perf improvement by checking namespace
cd, account, false)) // todo(lwander) perf improvement by checking
// namespace
// before converting
.filter(Objects::nonNull)
.filter(m -> m.getLocation().equals(location))
Expand All @@ -127,19 +128,24 @@ public List<KubernetesV2Manifest> getClusterAndSortAscending(
.orElse(new ArrayList<>());
}

private KubernetesV2Manifest fromCacheData(CacheData data, String account) {
private KubernetesV2Manifest fromCacheData(
CacheData data, String account, boolean includeEvents) {
KubernetesManifest manifest = KubernetesCacheDataConverter.getManifest(data);
String namespace = manifest.getNamespace();
KubernetesKind kind = manifest.getKind();
String key = data.getId();

List<KubernetesManifest> events =
cacheUtils
.getTransitiveRelationship(
kind.toString(), Collections.singletonList(key), KubernetesKind.EVENT.toString())
.stream()
.map(KubernetesCacheDataConverter::getManifest)
.collect(Collectors.toList());
includeEvents
? cacheUtils
.getTransitiveRelationship(
kind.toString(),
Collections.singletonList(key),
KubernetesKind.EVENT.toString())
.stream()
.map(KubernetesCacheDataConverter::getManifest)
.collect(Collectors.toList())
: Collections.emptyList();

String metricKey = Keys.metric(kind, account, namespace, manifest.getName());
List<KubernetesPodMetric.ContainerMetric> metrics =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void cancelJob(String account, String location, String id) {
private V1Job getKubernetesJob(String account, String location, String id) {
List<Manifest> manifests =
manifestProviderList.stream()
.map(p -> p.getManifest(account, location, id))
.map(p -> p.getManifest(account, location, id, false))
.filter(m -> m != null)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
Expand All @@ -52,22 +53,32 @@ public ManifestController(List<ManifestProvider> manifestProviders, RequestQueue
@PreAuthorize("hasPermission(#account, 'ACCOUNT', 'READ')")
@PostAuthorize("hasPermission(returnObject?.moniker?.app, 'APPLICATION', 'READ')")
@RequestMapping(value = "/{account:.+}/_/{name:.+}", method = RequestMethod.GET)
Manifest getForAccountAndName(@PathVariable String account, @PathVariable String name) {
return getForAccountLocationAndName(account, "", name);
Manifest getForAccountAndName(
@PathVariable String account,
@PathVariable String name,
@RequestParam(value = "includeEvents", required = false, defaultValue = "true")
boolean includeEvents) {
return getForAccountLocationAndName(account, "", name, includeEvents);
}

@PreAuthorize("hasPermission(#account, 'ACCOUNT', 'READ')")
@PostAuthorize("hasPermission(returnObject?.moniker?.app, 'APPLICATION', 'READ')")
@RequestMapping(value = "/{account:.+}/{location:.+}/{name:.+}", method = RequestMethod.GET)
Manifest getForAccountLocationAndName(
@PathVariable String account, @PathVariable String location, @PathVariable String name) {
@PathVariable String account,
@PathVariable String location,
@PathVariable String name,
@RequestParam(value = "includeEvents", required = false, defaultValue = "true")
boolean includeEvents) {

List<Manifest> manifests =
manifestProviders.stream()
.map(
provider -> {
try {
return requestQueue.execute(
account, () -> provider.getManifest(account, location, name));
account,
() -> provider.getManifest(account, location, name, includeEvents));
} catch (Throwable t) {
log.warn("Failed to read manifest ", t);
return null;
Expand All @@ -89,8 +100,12 @@ Manifest getForAccountLocationAndName(
}

@RequestMapping(value = "/{account:.+}/{name:.+}", method = RequestMethod.GET)
Manifest getForAccountLocationAndName(@PathVariable String account, @PathVariable String name) {
return getForAccountLocationAndName(account, "", name);
Manifest getForAccountLocationAndName(
@PathVariable String account,
@PathVariable String name,
@RequestParam(value = "includeEvents", required = false, defaultValue = "true")
boolean includeEvents) {
return getForAccountLocationAndName(account, "", name, includeEvents);
}

@RequestMapping(
Expand Down

0 comments on commit 79698ac

Please sign in to comment.