Skip to content

Instantly share code, notes, and snippets.

@bogdangaliceanu
Created August 26, 2022 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdangaliceanu/ea703a8f31dc9e541e115f478b9e1708 to your computer and use it in GitHub Desktop.
Save bogdangaliceanu/ea703a8f31dc9e541e115f478b9e1708 to your computer and use it in GitHub Desktop.
Amazon Neptune Autoscaling - GremlinStatusProvider
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