Skip to content

Commit

Permalink
Add CosmosDb support - new (#1342)
Browse files Browse the repository at this point in the history
* Add CosmosDb support + tests

Prior PR: #1239

* Create test_resources.tf
  • Loading branch information
gregkalapos authored Jun 18, 2021
1 parent 2368354 commit 243b7f8
Show file tree
Hide file tree
Showing 14 changed files with 994 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ElasticApmAgent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.Azure.Storage",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.Azure.Storage.Tests", "test\Elastic.Apm.Azure.Storage.Tests\Elastic.Apm.Azure.Storage.Tests.csproj", "{37BD6194-A47B-4D17-BB9A-642E8909DED9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.Azure.CosmosDb", "src\Elastic.Apm.Azure.CosmosDb\Elastic.Apm.Azure.CosmosDb.csproj", "{FC0276AB-9063-4DB9-9078-DCEF1F1091A9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.Azure.CosmosDb.Tests", "test\Elastic.Apm.Azure.CosmosDb.Tests\Elastic.Apm.Azure.CosmosDb.Tests.csproj", "{0EEA16C4-C7DF-4D90-94C2-009417D765AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -363,6 +367,14 @@ Global
{FB07C133-C353-4061-A308-B9A6EF48AB7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB07C133-C353-4061-A308-B9A6EF48AB7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB07C133-C353-4061-A308-B9A6EF48AB7E}.Release|Any CPU.Build.0 = Release|Any CPU
{FC0276AB-9063-4DB9-9078-DCEF1F1091A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC0276AB-9063-4DB9-9078-DCEF1F1091A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC0276AB-9063-4DB9-9078-DCEF1F1091A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC0276AB-9063-4DB9-9078-DCEF1F1091A9}.Release|Any CPU.Build.0 = Release|Any CPU
{0EEA16C4-C7DF-4D90-94C2-009417D765AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EEA16C4-C7DF-4D90-94C2-009417D765AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EEA16C4-C7DF-4D90-94C2-009417D765AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EEA16C4-C7DF-4D90-94C2-009417D765AC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -421,6 +433,8 @@ Global
{37BD6194-A47B-4D17-BB9A-642E8909DED9} = {267A241E-571F-458F-B04C-B6C4DE79E735}
{11C16D17-C0D0-48C3-B3A6-E9248C515976} = {3734A52F-2222-454B-BF58-1BA5C1F29D77}
{FB07C133-C353-4061-A308-B9A6EF48AB7E} = {267A241E-571F-458F-B04C-B6C4DE79E735}
{FC0276AB-9063-4DB9-9078-DCEF1F1091A9} = {3734A52F-2222-454B-BF58-1BA5C1F29D77}
{0EEA16C4-C7DF-4D90-94C2-009417D765AC} = {267A241E-571F-458F-B04C-B6C4DE79E735}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {69E02FD9-C9DE-412C-AB6B-5B8BECC6BFA5}
Expand Down
83 changes: 83 additions & 0 deletions build/terraform/azure/cosmosdb/test_resources.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.46.0"
}
}
}

provider "azurerm" {
features {}
}

# configuration is sourced from the following environment variables:
# ARM_CLIENT_ID
# ARM_CLIENT_SECRET
# ARM_SUBSCRIPTION_ID
# ARM_TENANT_ID
#
# See https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret
# for creating a Service Principal and Client Secret
data "azurerm_client_config" "current" {
}

variable "resource_group" {
type = string
description = "The name of the resource group to create"
}

variable "location" {
type = string
description = "The Azure location in which to deploy resources"
default = "westus"
}

variable "cosmos_db_account_name" {
type = string
description = "The name of the cosmos db account to create"
}

resource "azurerm_resource_group" "cosmos_db_resource_group" {
name = var.resource_group
location = var.location
}

resource "azurerm_cosmosdb_account" "cosmos_db_account" {
name = var.cosmos_db_account_name
location = azurerm_resource_group.cosmos_db_resource_group.location
resource_group_name = azurerm_resource_group.cosmos_db_resource_group.name
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_automatic_failover = false

capabilities {
name = "EnableAggregationPipeline"
}

capabilities {
name = "mongoEnableDocLevelTTL"
}

capabilities {
name = "MongoDBv3.4"
}

consistency_policy {
consistency_level = "Strong"
}

geo_location {
location = azurerm_resource_group.cosmos_db_resource_group.location
failover_priority = 0
}
}

output "endpoint" {
value = azurerm_cosmosdb_account.cosmos_db_account.endpoint
}

output "primary_master_key" {
value = azurerm_cosmosdb_account.cosmos_db_account.primary_master_key
sensitive = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to Elasticsearch B.V under
// one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Diagnostics;
using Elastic.Apm.DiagnosticSource;

namespace Elastic.Apm.Azure.CosmosDb
{
/// <summary>
/// Subscribes to HTTP requests from Microsoft.Azure.Cosmos, Microsoft.Azure.DocumentDb, and Microsoft.Azure.DocumentDb.Core.
/// </summary>
public class AzureCosmosDbDiagnosticsSubscriber : IDiagnosticsSubscriber
{
/// <summary>
/// Subscribes to HTTP requests
/// </summary>
public IDisposable Subscribe(IApmAgent agent)
{
if (agent is ApmAgent realAgent)
{
realAgent.HttpTraceConfiguration.AddTracer(new AzureCosmosDbTracer());

if (!realAgent.HttpTraceConfiguration.Subscribed)
realAgent.Subscribe(new HttpDiagnosticsSubscriber(false));
}

return EmptyDisposable.Instance;
}
}
}
Loading

0 comments on commit 243b7f8

Please sign in to comment.