Created
August 26, 2022 15:29
-
-
Save bogdangaliceanu/ea703a8f31dc9e541e115f478b9e1708 to your computer and use it in GitHub Desktop.
Amazon Neptune Autoscaling - GremlinStatusProvider
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
public interface IGremlinStatusProvider : IDisposable | |
{ | |
Task<GremlinStatus> Get(string address, int port); | |
} | |
// returns the status of an instance, as described in https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-api-status.html | |
public class GremlinStatusProvider : IGremlinStatusProvider | |
{ | |
private readonly HttpClient httpClient; | |
public GremlinStatusProvider(HttpClient httpClient) | |
{ | |
this.httpClient = httpClient; | |
} | |
public void Dispose() | |
{ | |
httpClient.Dispose(); | |
} | |
public async Task<GremlinStatus> Get(string address, int port) | |
{ | |
var json = await httpClient.GetStringAsync(new Uri($"https://{address}:{port}/gremlin/status?includeWaiting=true")); | |
return JsonConvert.DeserializeObject<GremlinStatus>(json); | |
} | |
} | |
public sealed record GremlinStatus | |
{ | |
[JsonProperty("acceptedQueryCount")] | |
public int AcceptedQueryCount { get; init; } | |
[JsonProperty("runningQueryCount")] | |
public int RunningQueryCount { get; init; } | |
[JsonProperty("queries")] | |
public ImmutableArray<GremlinQuery> Queries { get; init; } = ImmutableArray<GremlinQuery>.Empty; | |
} | |
public sealed record GremlinQuery | |
{ | |
[JsonProperty("queryId")] | |
public Guid QueryId { get; init; } | |
[JsonProperty("queryString")] | |
public string QueryString { get; init; } | |
[JsonProperty("queryEvalStats")] | |
public GremlinQueryEvalStats QueryEvalStats { get; init; } | |
} | |
public sealed record GremlinQueryEvalStats | |
{ | |
[JsonProperty("waited")] | |
public int Waited { get; init; } | |
[JsonProperty("elapsed")] | |
public int Elapsed { get; init; } | |
[JsonProperty("cancelled")] | |
public bool Cancelled { get; init; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment