Add UserAgent tagging to DS-1.0.x (#337)

* Integrate changes for tagging telemetry messages with user agent
* Update string in appsettings
This commit is contained in:
Jill Bender 2019-01-16 14:38:49 -08:00 коммит произвёл GitHub
Родитель 6f0d073713
Коммит 65020212c1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -381,6 +381,7 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services
private IDeviceClientWrapper GetDeviceSdkClient(Device device, IoTHubProtocol protocol)
{
var connectionString = $"HostName={device.IoTHubHostName};DeviceId={device.Id};SharedAccessKey={device.AuthPrimaryKey}";
var userAgent = this.config.UserAgent;
IDeviceClientWrapper sdkClient;
switch (protocol)
@ -389,21 +390,21 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services
this.log.Debug("Creating AMQP device client",
() => new { device.Id, device.IoTHubHostName });
sdkClient = this.deviceClient.CreateFromConnectionString(connectionString, TransportType.Amqp_Tcp_Only);
sdkClient = this.deviceClient.CreateFromConnectionString(connectionString, TransportType.Amqp_Tcp_Only, userAgent);
break;
case IoTHubProtocol.MQTT:
this.log.Debug("Creating MQTT device client",
() => new { device.Id, device.IoTHubHostName });
sdkClient = this.deviceClient.CreateFromConnectionString(connectionString, TransportType.Mqtt_Tcp_Only);
sdkClient = this.deviceClient.CreateFromConnectionString(connectionString, TransportType.Mqtt_Tcp_Only, userAgent);
break;
case IoTHubProtocol.HTTP:
this.log.Debug("Creating HTTP device client",
() => new { device.Id, device.IoTHubHostName });
sdkClient = this.deviceClient.CreateFromConnectionString(connectionString, TransportType.Http1);
sdkClient = this.deviceClient.CreateFromConnectionString(connectionString, TransportType.Http1, userAgent);
break;
default:

Просмотреть файл

@ -10,7 +10,7 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.IotHub
public interface IDeviceClientWrapper
{
uint OperationTimeoutInMilliseconds { get; set; }
IDeviceClientWrapper CreateFromConnectionString(string connectionString, TransportType transportType);
IDeviceClientWrapper CreateFromConnectionString(string connectionString, TransportType transportType, string userAgent);
Task OpenAsync();
Task CloseAsync();
Task UpdateReportedPropertiesAsync(TwinCollection reportedProperties);
@ -34,9 +34,11 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.IotHub
set => this.internalClient.OperationTimeoutInMilliseconds = value;
}
public IDeviceClientWrapper CreateFromConnectionString(string connectionString, TransportType transportType)
public IDeviceClientWrapper CreateFromConnectionString(string connectionString, TransportType transportType, string userAgent)
{
var sdkClient = Azure.Devices.Client.DeviceClient.CreateFromConnectionString(connectionString, transportType);
sdkClient.ProductInfo = userAgent;
return this.WrapSdkClient(sdkClient);
}

Просмотреть файл

@ -14,6 +14,7 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Runtime
string StorageAdapterApiUrl { get; }
int StorageAdapterApiTimeout { get; }
bool TwinReadWriteEnabled { get; }
string UserAgent { get; }
}
// TODO: test Windows/Linux folder separator
@ -61,6 +62,8 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Runtime
public bool TwinReadWriteEnabled { get; set; }
public string UserAgent { get; set; }
private string NormalizePath(string path)
{
return path

Просмотреть файл

@ -47,6 +47,7 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Runtime
private const string IOTHUB_CONNSTRING_KEY = APPLICATION_KEY + "iothub_connstring";
private const string IOTHUB_SDK_DEVICE_CLIENT_TIMEOUT_KEY = APPLICATION_KEY + "iothub_sdk_device_client_timeout";
private const string TWIN_READ_WRITE_ENABLED_KEY = APPLICATION_KEY + "twin_read_write_enabled";
private const string USER_AGENT_KEY = APPLICATION_KEY + "user_agent";
private const string IOTHUB_LIMITS_KEY = APPLICATION_KEY + "RateLimits:";
private const string CONNECTIONS_FREQUENCY_LIMIT_KEY = IOTHUB_LIMITS_KEY + "device_connections_per_second";
@ -195,7 +196,8 @@ namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Runtime
IoTHubSdkDeviceClientTimeout = configData.GetOptionalUInt(IOTHUB_SDK_DEVICE_CLIENT_TIMEOUT_KEY),
StorageAdapterApiUrl = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true)
TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true),
UserAgent = configData.GetString(USER_AGENT_KEY)
};
}

Просмотреть файл

@ -23,6 +23,8 @@ iothub_data_folder = ./data/iothub/
# and open connections.
twin_read_write_enabled = "${?PCS_TWIN_READ_WRITE_ENABLED}"
# The user-agent string is used to identify the application to the Azure IoT Hub
user_agent = "RemoteMonitoring"
[StorageAdapterService]
# URL where the storage adapter is available, e.g. http://localhost:9022/v1 on local dev environments