Skip to content

Commit

Permalink
feat(stats): Add stage's CloudProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Tomsu committed Sep 12, 2019
1 parent f545651 commit 239e691
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.netflix.spinnaker.echo.events.EchoEventListener;
import com.netflix.spinnaker.echo.model.Event;
import com.netflix.spinnaker.kork.proto.stats.Application;
import com.netflix.spinnaker.kork.proto.stats.CloudProvider;
import com.netflix.spinnaker.kork.proto.stats.Execution;
import com.netflix.spinnaker.kork.proto.stats.SpinnakerInstance;
import com.netflix.spinnaker.kork.proto.stats.Stage;
Expand Down Expand Up @@ -147,10 +148,23 @@ public void processEvent(Event event) {
}

private Stage toStage(Map stage) {
return Stage.newBuilder()
.setType(stage.getOrDefault("type", "unknown").toString())
.setStatus(Status.valueOf(stage.getOrDefault("status", "UNKNOWN").toString().toUpperCase()))
.build();
Status status =
Status.valueOf(stage.getOrDefault("status", "UNKNOWN").toString().toUpperCase());
Stage.Builder stageBuilder =
Stage.newBuilder()
.setType(stage.getOrDefault("type", "unknown").toString())
.setStatus(status);

Map<String, Object> context =
(Map<String, Object>) stage.getOrDefault("context", new HashMap<>());
if (context.containsKey("cloudProvider")) {
String cloudProvider = context.get("cloudProvider").toString();
stageBuilder.setCloudProvider(CloudProvider.newBuilder().setId(cloudProvider).build());

// TODO(ttomsu): Figure out how to detect Kubernetes "flavor" - i.e. GKE, EKS, vanilla, etc.
}

return stageBuilder.build();
}

private String hash(String clearText) {
Expand Down

0 comments on commit 239e691

Please sign in to comment.