public KeyVault(KeyVaultOptions options, IProxyService proxyService, ILogService log) { _options = options; _proxyService = proxyService; _log = log; _helpers = new AzureHelpers(_options, log); }
public override bool OnStart() { _subscriptionClient = AzureHelpers.GetSubscriptionClient("scaleevents", "WeightToTableStorage", ReceiveMode.PeekLock); _table = AzureHelpers.GetTable("ScaleLog"); _isStopped = false; return(base.OnStart()); }
public override bool OnStart() { _subscriptionClient = AzureHelpers.GetSubscriptionClient("scaleevents", "SaveToBlobStorage", ReceiveMode.PeekLock); _blob = AzureHelpers.GetBlob("coffee", "state"); _isStopped = false; return(base.OnStart()); }
public Azure(AzureOptions options, LookupClientProvider dnsClient, ProxyService proxyService, ILogService log, ISettingsService settings) : base(dnsClient, log, settings) { _options = options; _proxyService = proxyService; _recordSets = new Dictionary <string, Dictionary <string, RecordSet> >(); _helpers = new AzureHelpers(_options, log); }
public AzureServiceBusEventDispatcherReceiver(string connectionString, IEventDispatcher innerEventDispatcher, IEventStore eventStore, string topicName, string subscriptionName) { _innerEventDispatcher = innerEventDispatcher; _eventStore = eventStore; AzureHelpers.EnsureTopicExists(connectionString, topicName); AzureHelpers.EnsureSubscriptionExists(connectionString, topicName, subscriptionName); _subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName); _workerThread = new Thread(DoWork); }
public void btnClickHere_Click_1(object sender, RoutedEventArgs e) { AzureHelpers.SendRecieveMessageAsync(); try { lvWeatherList.ItemsSource = lvWeatherList; } catch { } }
public async Task InitializeAsync() { if (this.initialized) { return; } this.table = await AzureHelpers.GetStorageTableAsync("eventstats").ConfigureAwait(false); this.queue = await AzureHelpers.GetStorageQueueAsync("eventstats").ConfigureAwait(false); this.initialized = true; }
public static async Task Run( [TimerTrigger("0 * * * * *")] TimerInfo myTimer, [OrchestrationClient] DurableOrchestrationClient client, [Microsoft.Azure.WebJobs.Table("MetricDatas", "Metrics", "001")] MetricData data, IAsyncCollector <MetricData> table, ILogger log) { log.LogMetricsCollector($"Executed at: {DateTime.Now:yyyy-MM-dd HH:mm:ss}"); var t = await client.GetStatusAsync(InstanceId); var content = JsonConvert.DeserializeObject <Content>(data.Content); if (IsStarted) { log.LogMetricsCollector("Get active message."); var currentActiveMessageCount = AzureHelpers.GetCurrentMetrics(); log.LogMetricsCollector($"Current message count: {currentActiveMessageCount}"); log.LogMetricsCollector($"Calculate current part metrics."); var currentDayActiveMessageCount = currentActiveMessageCount - content.MessageCount; content.MessageCount = currentActiveMessageCount; content.AddData(currentActiveMessageCount); var @event = new MetricCollected(currentDayActiveMessageCount); data.Content = JsonConvert.SerializeObject(content); await table.AddAsync(data); log.LogMetricsCollector($"Raise event to scaling function."); await client.RaiseEventAsync(InstanceId, nameof(MetricCollected), @event); log.LogMetricsCollector("Done."); } else { AutoregresiveParam = EnvironmentHelpers.GetIntegerEnvironmentParameter(nameof(MasterPerformMetricsCollector.AutoregresiveParam)); IntegrationParam = EnvironmentHelpers.GetIntegerEnvironmentParameter(nameof(MasterPerformMetricsCollector.IntegrationParam)); MoveAverrageParam = EnvironmentHelpers.GetIntegerEnvironmentParameter(nameof(MasterPerformMetricsCollector.MoveAverrageParam)); Period = EnvironmentHelpers.GetIntegerEnvironmentParameter(nameof(MasterPerformMetricsCollector.Period)); Q = EnvironmentHelpers.GetIntegerEnvironmentParameter(nameof(MasterPerformMetricsCollector.Q)); var costForPeriod = EnvironmentHelpers.GetDoubleEnvironmentParameter("CostForPeriod"); CostOfOneMachine = EnvironmentHelpers.GetIntegerEnvironmentParameter(nameof(MasterPerformMetricsCollector.CostOfOneMachine)); log.LogMetricsCollector($"Start first forecasting."); IsStarted = true; InstanceId = await client.StartNewAsync(nameof(ScalingFunction), new ScalingState(content.Data, costForPeriod)); } }
public static void Scaler( [ActivityTrigger] DurableActivityContext context, ILogger log) { var action = context.GetInput <ScaleAction>(); var capacity = action.CapacityPlanCount < 2 ? 1 : action.CapacityPlanCount; log.LogScaler($"New capacity: {capacity}"); log.LogScaler($"Executed at: {DateTime.Now}"); var resourceName = Environment.GetEnvironmentVariable("appServicePlanName"); log.LogScaler($"Executed for {resourceName} App Service"); var azure = AzureHelpers.GetAzureConnection(); log.LogScaler("Successfully authenticated to azure"); var plan = azure.AppServices .AppServicePlans .List() .First(p => string.Equals(p.Name.ToLower(), resourceName.ToLower())); if (plan.Capacity == capacity) { log.LogScaler($"App service plan capacity: {plan.Capacity} is equal to new capacity: {capacity}. Ending function."); } else { log.LogScaler($"Switching {resourceName} from {plan.Capacity} to {capacity}"); plan.Update() .WithCapacity(capacity) .Apply(); log.LogScaler($"App Service Capacity: {resourceName} updated."); } }
public override void Configure(IFunctionsHostBuilder builder) { // Write startupcode here. builder.Services.AddSingleton <IHttpClient, HttpClientWrapper>(); builder.Services.AddSingleton <IAdlsClient, AdlsClientWrapper>(); string settings = null; string settingsPath = Environment.GetEnvironmentVariable("SettingsPath"); if (string.IsNullOrWhiteSpace(settingsPath)) { settingsPath = "Settings.json"; } try { settings = AzureHelpers.GetBlobContentAsync("github-settings", settingsPath).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception) { } builder.Services.AddSingleton(new GitHubConfigManager(settings)); builder.Services.AddSingleton <IQueueProcessorFactory, CustomQueueProcessorFactory>(); }
public async Task Onboard([QueueTrigger("onboarding")] string queueItem, ExecutionContext executionContext, ILogger logger) { DateTime functionStartDate = DateTime.UtcNow; string sessionId = Guid.NewGuid().ToString(); JsonSerializerSettings serializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.None }; OnboardingInput onboardingInput = JsonConvert.DeserializeObject <OnboardingInput>(queueItem, serializerSettings); Repository repositoryDetails = onboardingInput.ToRepository(); FunctionContextWriter <FunctionContext> contextWriter = new FunctionContextWriter <FunctionContext>(); string identifier = $"Onboarding"; FunctionContext context = new FunctionContext() { CollectorType = CollectorType.Onboarding.ToString(), FunctionStartDate = functionStartDate, SessionId = sessionId, InvocationId = executionContext.InvocationId.ToString(), }; StatsTracker statsTracker = null; string outputPaths = string.Empty; bool success = false; ITelemetryClient telemetryClient = new GitHubApplicationInsightsTelemetryClient(this.telemetryClient, context, logger); try { telemetryClient.TrackEvent("SessionStart", GetRepositoryCollectorSessionStartEventProperties(context, identifier, repositoryDetails)); ICache <OnboardingTableEntity> onboardingCache = new AzureTableCache <OnboardingTableEntity>(telemetryClient, "onboarding"); await onboardingCache.InitializeAsync().ConfigureAwait(false); ICache <RateLimitTableEntity> rateLimiterCache = new AzureTableCache <RateLimitTableEntity>(telemetryClient, "ratelimiter"); await rateLimiterCache.InitializeAsync().ConfigureAwait(false); IRateLimiter rateLimiter = new GitHubRateLimiter(this.configManager.UsesGitHubAuth(context.CollectorType) ? onboardingInput.OrganizationLogin : "******", rateLimiterCache, this.httpClient, telemetryClient, maxUsageBeforeDelayStarts: 50.0, this.apiDomain); ICache <ConditionalRequestTableEntity> requestsCache = new AzureTableCache <ConditionalRequestTableEntity>(telemetryClient, "requests"); await requestsCache.InitializeAsync().ConfigureAwait(false); GitHubHttpClient httpClient = new GitHubHttpClient(this.httpClient, rateLimiter, requestsCache, telemetryClient); IAuthentication authentication = this.configManager.GetAuthentication(CollectorType.Onboarding, httpClient, onboardingInput.OrganizationLogin, this.apiDomain); CloudQueue onboardingCloudQueue = await AzureHelpers.GetStorageQueueAsync("onboarding").ConfigureAwait(false); IQueue onboardingQueue = new CloudQueueWrapper(onboardingCloudQueue); StorageManager storageManager; List <IRecordWriter> recordWriters; using (storageManager = this.configManager.GetStorageManager(context.CollectorType, telemetryClient)) { recordWriters = storageManager.InitializeRecordWriters(identifier, context, contextWriter, this.adlsClient.AdlsClient); IRecordStatsTracker recordStatsTracker = null; foreach (IRecordWriter recordWriter in recordWriters) { recordWriter.SetOutputPathPrefix($"{repositoryDetails.OrganizationId}/{repositoryDetails.RepositoryId}"); if (recordStatsTracker == null) { recordStatsTracker = recordWriter; } } statsTracker = new StatsTracker(telemetryClient, httpClient, recordStatsTracker, StatsTrackerRefreshFrequency); OnboardingProcessor processor = new OnboardingProcessor(authentication, recordWriters, httpClient, onboardingCache, onboardingQueue, telemetryClient, this.apiDomain); await processor.ProcessAsync(onboardingInput).ConfigureAwait(false); } await storageManager.FinalizeRecordWritersAsync().ConfigureAwait(false); outputPaths = RecordWriterExtensions.GetOutputPaths(recordWriters); success = true; } catch (Exception exception) when(!(exception is FatalException)) { telemetryClient.TrackException(exception, "Onboard failed."); throw exception; } finally { SendSessionEndEvent(telemetryClient, context.FunctionStartDate, outputPaths, GetRepositoryCollectorSessionStartEventProperties(context, identifier, repositoryDetails), success); statsTracker?.Stop(); } }
public void value() { Assert.Equal(28, AzureHelpers.ParseNth("events.00028")); }
public void bad_throws() { Assert.Throws <ArgumentException>(() => AzureHelpers.ParseNth("events.00FF0")); }
public void compact_throws() { Assert.Throws <ArgumentException>(() => AzureHelpers.ParseNth("events.00000.compact")); }
private async Task ExecuteTrafficCollector(ExecutionContext executionContext, ILogger logger) { DateTime functionStartDate = DateTime.UtcNow; string sessionId = Guid.NewGuid().ToString(); string identifier = "TrafficTimer"; CloudQueue trafficCloudQueue = await AzureHelpers.GetStorageQueueAsync("traffic").ConfigureAwait(false); IQueue trafficQueue = new CloudQueueWrapper(trafficCloudQueue); FunctionContext context = new FunctionContext() { CollectorType = CollectorType.TrafficTimer.ToString(), FunctionStartDate = functionStartDate, SessionId = sessionId, InvocationId = executionContext.InvocationId.ToString(), }; StatsTracker statsTracker = null; bool success = false; ITelemetryClient telemetryClient = new GitHubApplicationInsightsTelemetryClient(this.telemetryClient, context, logger); try { telemetryClient.TrackEvent("SessionStart", GetCollectorCommonSessionStartEventProperties(context, identifier)); ICache <RateLimitTableEntity> rateLimiterCache = new AzureTableCache <RateLimitTableEntity>(telemetryClient, "ratelimiter"); await rateLimiterCache.InitializeAsync().ConfigureAwait(false); ICache <ConditionalRequestTableEntity> requestsCache = new AzureTableCache <ConditionalRequestTableEntity>(telemetryClient, "requests"); await requestsCache.InitializeAsync().ConfigureAwait(false); string organizations = await AzureHelpers.GetBlobContentAsync("github-settings", "organizations.json").ConfigureAwait(false); JArray organizationsArray = JArray.Parse(organizations); foreach (JToken organizationToken in organizationsArray) { JObject organization = (JObject)organizationToken; string organizationLogin = organization.SelectToken("$.OrganizationLogin").Value <string>(); long organizationId = organization.SelectToken("$.OrganizationId").Value <long>(); IRateLimiter rateLimiter = new GitHubRateLimiter(this.configManager.UsesGitHubAuth(context.CollectorType) ? organizationLogin : "******", rateLimiterCache, this.httpClient, telemetryClient, maxUsageBeforeDelayStarts: 80.0, this.apiDomain); GitHubHttpClient httpClient = new GitHubHttpClient(this.httpClient, rateLimiter, requestsCache, telemetryClient); statsTracker = new StatsTracker(telemetryClient, httpClient, StatsTrackerRefreshFrequency); IAuthentication authentication = this.configManager.GetAuthentication(CollectorType.TrafficTimer, httpClient, organizationLogin, this.apiDomain); CollectorBase <GitHubCollectionNode> collector = new GitHubCollector(httpClient, authentication, telemetryClient, new List <IRecordWriter>()); GitHubCollectionNode repositoriesNode = new GitHubCollectionNode() { RecordType = DataContract.RepositoryInstanceRecordType, ApiName = DataContract.RepositoriesApiName, GetInitialUrl = additionalMetadata => OnboardingProcessor.InitialRepositoriesUrl(organizationLogin, this.apiDomain), ProcessRecordAsync = async record => { string repositoryName = record.SelectToken("$.name").Value <string>(); long repositoryId = record.SelectToken("$.id").Value <long>(); Repository repository = new Repository(organizationId, repositoryId, organizationLogin, repositoryName); await trafficQueue.PutObjectAsJsonStringAsync(repository, TimeSpan.MaxValue).ConfigureAwait(false); return(new List <RecordWithContext>()); }, }; await collector.ProcessAsync(repositoriesNode).ConfigureAwait(false); } success = true; } catch (Exception exception) when(!(exception is FatalException)) { telemetryClient.TrackException(exception, "TrafficTimer failed."); throw exception; } finally { SendSessionEndEvent(telemetryClient, context.FunctionStartDate, outputPaths: string.Empty, GetCollectorCommonSessionStartEventProperties(context, identifier), success); statsTracker?.Stop(); } }
public AzureServiceBusEventDispatcherSender(string connectionString, string topicName) { AzureHelpers.EnsureTopicExists(connectionString, topicName); _topicClient = TopicClient.CreateFromConnectionString(connectionString, topicName); }
public void zero() { Assert.Equal(0, AzureHelpers.ParseNth("events.00000")); }