This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
forked from spinnaker/clouddriver
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider/dcos): Adding proxy for marathon-client to make use of …
…spectator. (spinnaker#1960)
- Loading branch information
Trevin Teacutter
authored and
Michael Tweten
committed
Nov 10, 2017
1 parent
51b96ca
commit 7ccc85b
Showing
5 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...r-dcos/src/main/groovy/com/netflix/spinnaker/clouddriver/dcos/DcosSpectatorHandler.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.netflix.spinnaker.clouddriver.dcos | ||
|
||
import com.netflix.spectator.api.Clock | ||
import com.netflix.spectator.api.Registry | ||
import mesosphere.dcos.client.DCOS | ||
import mesosphere.dcos.client.DCOSException | ||
|
||
import java.lang.reflect.InvocationHandler | ||
import java.lang.reflect.Method | ||
import java.util.concurrent.TimeUnit | ||
|
||
class DcosSpectatorHandler implements InvocationHandler { | ||
private final DCOS dcosClient | ||
private final Registry registry | ||
private final Clock clock | ||
private final String accountName | ||
private final String regionName | ||
|
||
DcosSpectatorHandler(DCOS dcosClient, String accountName, String regionName, Registry registry) { | ||
this.dcosClient = dcosClient | ||
this.accountName = accountName | ||
this.regionName = regionName | ||
this.clock = registry.clock() | ||
this.registry = registry | ||
} | ||
|
||
@Override | ||
Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
Object result = null | ||
Throwable failure = null | ||
long startTime = clock.monotonicTime() | ||
|
||
try { | ||
result = method.invoke(dcosClient, args) | ||
} catch (DCOSException e) { | ||
failure = e.cause | ||
} catch (Exception e) { | ||
failure = e | ||
} finally { | ||
Map<String, String> tags = new HashMap<>() | ||
|
||
tags.put("method", method.name) | ||
tags.put("account", accountName) | ||
tags.put("region", regionName) | ||
|
||
if (failure == null) { | ||
tags.put("success", "true") | ||
} else { | ||
tags.put("success", "false") | ||
tags.put("reason", failure.getClass().getSimpleName() + ": " + failure.getMessage()) | ||
} | ||
|
||
registry.timer(registry.createId("dcos.api", tags)) | ||
.record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS) | ||
} | ||
|
||
if (failure != null) { | ||
throw new Throwable(method.name, failure) | ||
} else { | ||
return result | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters