Skip to content

Commit

Permalink
fix: include exception in log message when eager connection fails; up…
Browse files Browse the repository at this point in the history
…date env vars to MOMENTO_API_KEY

Prior to this commit, if we failed to eagerly connect, we were not logging any information about
the reason. This commit adds the exception to the log. Tested by disabling my network connection
and verified it includes all the relevant info.

Also updates places in example code where we were still using MOMENTO_AUTH_TOKEN for env var names,
now that we have standardized on MOMENTO_API_KEY.
  • Loading branch information
cprice404 committed Feb 23, 2024
1 parent a625c93 commit bf94e5a
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/DictionaryExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class Driver
{
private static readonly string AUTH_TOKEN_ENV_VAR = "MOMENTO_AUTH_TOKEN";
private static readonly string AUTH_TOKEN_ENV_VAR = "MOMENTO_API_KEY";
private static readonly string CACHE_NAME_ENV_VAR = "MOMENTO_CACHE_NAME";
private static readonly ILogger _logger;
private static readonly ILoggerFactory _loggerFactory;
Expand Down
2 changes: 1 addition & 1 deletion examples/DisposableTokens/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static class Program

static Program()
{
authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY");
client = new AuthClient(AuthConfigurations.Default.Latest(), authProvider);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/DisposableTokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This example program demonstrates how to generate disposable Momento auth tokens

# Usage

The program assumes that your Momento auth token is available in the `MOMENTO_AUTH_TOKEN` environment variable:
The program assumes that your Momento auth token is available in the `MOMENTO_API_KEY` environment variable:

```bash
MOMENTO_AUTH_TOKEN=<YOUR_AUTH_TOKEN> dotnet run
MOMENTO_API_KEY=<YOUR_AUTH_TOKEN> dotnet run
```

The example generates a disposable expiring auth token using the enumerated permissions and expiry defined in the program and prints its attributes to the console.
8 changes: 4 additions & 4 deletions examples/DocExampleApis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public static async Task Main(string[] args)
{
var config = Configurations.Laptop.V1();
var client = new CacheClient(config,
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN"),
new EnvMomentoTokenProvider("MOMENTO_API_KEY"),
TimeSpan.FromSeconds(10));
IAuthClient authClient = new AuthClient(
AuthConfigurations.Default.Latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
new EnvMomentoTokenProvider("MOMENTO_API_KEY")
);
ITopicClient topicClient = new TopicClient(
TopicConfigurations.Laptop.latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
new EnvMomentoTokenProvider("MOMENTO_API_KEY")
);

await Example_API_CreateCache(client);
Expand Down Expand Up @@ -240,7 +240,7 @@ public static async Task Example_API_InstantiateTopicClient()
{
new TopicClient(
TopicConfigurations.Laptop.latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
new EnvMomentoTokenProvider("MOMENTO_API_KEY")
);
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
Expand Down
4 changes: 2 additions & 2 deletions examples/MomentoApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Momento.Sdk.Exceptions;
using Momento.Sdk.Responses;

ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY");

TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60);

Expand Down Expand Up @@ -128,7 +128,7 @@ public static async Task DeleteCacheExample(ICacheClient client) {
/// </summary>
public static void EagerConnectionExample()
{
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY");
TimeSpan defaultTtl = TimeSpan.FromSeconds(60);
var config = Configurations.Laptop.V1();
var eagerConnectionConfig = config.WithTransportStrategy(config.TransportStrategy.WithEagerConnectionTimeout(TimeSpan.FromSeconds(10)));
Expand Down
4 changes: 2 additions & 2 deletions examples/MomentoApplication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ functionality, including:
Run the following from within the `examples` directory:

```bash
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run --project MomentoApplication
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run --project MomentoApplication
```

Within the `MomentoAppication` directory you can run:

```bash
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run
```

## Error Handling
Expand Down
2 changes: 1 addition & 1 deletion examples/MomentoFSharpApplication/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open System

let CACHE_NAME = "cache"
let DEFAULT_TTL = TimeSpan.FromSeconds(60.0)
let authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
let authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY")

let exerciseCache() = (
printfn "Howdy"
Expand Down
2 changes: 1 addition & 1 deletion examples/MomentoLoadGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public CsharpLoadGenerator(IConfiguration momentoClientConfig, CsharpLoadGenerat

public async Task Run()
{
var authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
var authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY");

using (ICacheClient momento = new CacheClient(
_momentoClientConfig,
Expand Down
6 changes: 3 additions & 3 deletions examples/MomentoLoadGen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ To run the load generator (from the `examples` directory):

```bash
# Run example load generator
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run --project MomentoLoadGen
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run --project MomentoLoadGen
```

Within the `MomentoLoadGen` directory you can run:

```bash
# Run example load generator
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run
```

If you make modifications to the code, remember to do a clean otherwise
the program might not run.

```bash
dotnet clean
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run
```
18 changes: 10 additions & 8 deletions examples/MomentoUsage/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
using Momento.Sdk.Config;
using Momento.Sdk.Responses;

ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY");
const string CACHE_NAME = "cache";
const string KEY = "MyKey";
const string VALUE = "MyData";
TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60);

using (ICacheClient client = new CacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL))
var config = Configurations.Laptop.V1();
config = config.WithTransportStrategy(config.TransportStrategy.WithEagerConnectionTimeout(TimeSpan.FromSeconds(10)));
using (ICacheClient client = new CacheClient(config, authProvider, DEFAULT_TTL))
{
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
if (createCacheResponse is CreateCacheResponse.Error createError)
{
Console.WriteLine($"Error creating cache: {createError.Message}. Exiting.");
Environment.Exit(1);
}
// var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
// if (createCacheResponse is CreateCacheResponse.Error createError)
// {
// Console.WriteLine($"Error creating cache: {createError.Message}. Exiting.");
// Environment.Exit(1);
// }

Console.WriteLine($"Setting key: {KEY} with value: {VALUE}");
var setResponse = await client.SetAsync(CACHE_NAME, KEY, VALUE);
Expand Down
4 changes: 2 additions & 2 deletions examples/MomentoUsage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ the client's full capabilities, take a look at the more advanced [MomentoApplic
Run the following from within the `examples` directory:

```bash
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run --project MomentoUsage
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run --project MomentoUsage
```

Within the `MomentoUsage` directory you can run:

```bash
MOMENTO_AUTH_TOKEN=<YOUR AUTH TOKEN> dotnet run
MOMENTO_API_KEY=<YOUR AUTH TOKEN> dotnet run
```

## Error Handling
Expand Down
2 changes: 1 addition & 1 deletion examples/TopicExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TopicExample;

public class Driver
{
private const string AuthTokenEnvVar = "MOMENTO_AUTH_TOKEN";
private const string AuthTokenEnvVar = "MOMENTO_API_KEY";
private const string CacheNameEnvVar = "MOMENTO_CACHE_NAME";
private const string TopicName = "example-topic";
private static readonly ILogger Logger;
Expand Down
2 changes: 1 addition & 1 deletion src/Momento.Sdk/Internal/DataGrpcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ internal DataGrpcManager(IConfiguration config, string authToken, string endpoin
pingClient.Ping(new _PingRequest(),
new CallOptions(deadline: DateTime.UtcNow.Add(eagerConnectionTimeout)));
}
catch (RpcException)
catch (RpcException ex)

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (ubuntu-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (ubuntu-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (ubuntu-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (ubuntu-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net6.0)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net461)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net461)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net461)

The variable 'ex' is declared but never used

Check warning on line 313 in src/Momento.Sdk/Internal/DataGrpcManager.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net461)

The variable 'ex' is declared but never used
{
_logger.LogWarning("Failed to eagerly connect to the server; continuing with execution in case failure is recoverable later.");
}
Expand Down

0 comments on commit bf94e5a

Please sign in to comment.