Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jstromwick committed Dec 12, 2013
2 parents bb255d6 + fba209b commit aa96862
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 105 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A plugin for monitoring Microsoft SQL Server using the New Relic platform.
1. Run a text editor **as administrator** and open the file `INSTALLDIR\NewRelic.Microsoft.SqlServer.Plugin.exe.config`.
2. Find the setting `<service licenseKey="YOUR_KEY_HERE"...>` and replace `YOUR_KEY_HERE` with your New Relic license key.
3. Configure one or more SQL Servers or Azure SQL Databases
* In the `<sqlServers>` section, add a `<sqlServer>` setting for a SQL Server.
* In the `<sqlServers>` section, add a `<sqlServer>` setting for _each_ SQL Server instance you wish to monitor.
* `name="Production Database"` The name of your server is visible on the New Relic dashboard.
* `connectionString="Server=prd.domain.com,1433;Database=master;Trusted_Connection=True;"` Any valid connection string to your database.
* In the `<azure>` section, add a `<database>` setting for _each_ Windows Azure SQL Database.
Expand Down
Binary file added build/SQL-Azure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/SQL-Server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build/versions.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<PatchVersion>10</PatchVersion>
<PatchVersion>11</PatchVersion>

<BuildQuality></BuildQuality>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Common/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.10")]
[assembly: AssemblyFileVersion("1.0.10")]
[assembly: AssemblyInformationalVersion("1.0.10")]
[assembly: AssemblyVersion("1.0.11")]
[assembly: AssemblyFileVersion("1.0.11")]
[assembly: AssemblyInformationalVersion("1.0.11")]
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<Compile Include="QueryTypes\MemoryViewTests.cs" />
<Compile Include="QueryTypes\RecompileSummaryTests.cs" />
<Compile Include="SqlEndpointTests.cs" />
<Compile Include="SqlMonitoryQueryTests.cs" />
<Compile Include="SqlMonitorQueryTests.cs" />
<Compile Include="TestHelper.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Linq;

using NewRelic.Microsoft.SqlServer.Plugin.Core;
using NewRelic.Microsoft.SqlServer.Plugin.QueryTypes;
using NewRelic.Platform.Binding.DotNET;

using NSubstitute;

using NUnit.Framework;

namespace NewRelic.Microsoft.SqlServer.Plugin
{
[TestFixture]
public class SqlMonitorQueryTests
{
protected class FakeQueryType
{
public long Long { get; set; }
public int Integer { get; set; }
public short Short { get; set; }
public byte Byte { get; set; }
public decimal Decimal { get; set; }
public string Comment { get; set; }
public DateTime EventTime { get; set; }
}

[Test]
public void Assert_only_numerics_are_returned()
{
MetricMapper[] metricMappers = MetricQuery.GetMappers(typeof (FakeQueryType));
Assert.That(metricMappers, Is.Not.Null);

// Keep these out of order to ensure we don't depend on it
var expected = new[] {"Long", "Integer", "Short", "Decimal", "Byte"};
string[] actual = metricMappers.Select(m => m.MetricName).ToArray();
Assert.That(actual, Is.EquivalentTo(expected), "Properties discovered and mapped wrong");
}

[Test]
[TestCase(MetricTransformEnum.Delta)]
[TestCase(MetricTransformEnum.Simple)]
public void Assert_query_sets_appropriate_metric_transform(MetricTransformEnum metricTransformEnum)
{
var attribute = new SqlServerQueryAttribute("FileIO.sql", "Foo/Bar") {MetricTransformEnum = metricTransformEnum};
var sqlQuery = new SqlQuery(typeof (FileIoView), attribute, Substitute.For<IDapperWrapper>(), "");

Assert.That(sqlQuery.MetricTransformEnum, Is.EqualTo(attribute.MetricTransformEnum), "SqlQuery did not set correct value from attribute for MetricTransformEnum");
}

[Test]
public void Assert_results_are_mapped_into_metrics()
{
var fakes = new[]
{
new FakeQueryType
{
Long = 42,
Integer = 27,
Short = 12,
Byte = 255,
Decimal = 407.54m,
Comment = "Utterly worthless... except for logging",
EventTime = DateTime.Now,
}
};

var sqlQuery = new SqlQuery(typeof (FakeQueryType), new SqlServerQueryAttribute("foo.sql", "Fake/"), Substitute.For<IDapperWrapper>(), "");

var componentData = new ComponentData();
sqlQuery.AddMetrics(new QueryContext(sqlQuery) {ComponentData = componentData, Results = fakes,});

var expected = new[] {"Fake/Long", "Fake/Integer", "Fake/Short", "Fake/Decimal", "Fake/Byte"};
string[] actual = componentData.Metrics.Keys.ToArray();
Assert.That(actual, Is.EquivalentTo(expected), "Properties discovered and mapped wrong");
}
}
}

This file was deleted.

7 changes: 4 additions & 3 deletions src/NewRelic.Microsoft.SqlServer.Plugin/MetricQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ public class MetricQuery : IMetricQuery
{
private readonly MetricMapper[] _metricMappers;

public MetricQuery(Type queryType, string queryName, string resultTypeName)
public MetricQuery(Type queryType, string queryName, string resultTypeName, MetricTransformEnum metricTransformEnum = MetricTransformEnum.Simple)
{
QueryType = queryType;
QueryName = queryName;
ResultTypeName = resultTypeName;
_metricMappers = GetMappers(QueryType);
MetricPattern = string.Format("Component/{0}", QueryType.Name);
MetricTransformEnum = metricTransformEnum;
}

public Type QueryType { get; private set; }

public string QueryName { get; private set; }

public MetricTransformEnum MetricTransformEnum { get; set; }
public MetricTransformEnum MetricTransformEnum { get; protected set; }

public string MetricPattern { get; protected set; }

Expand Down Expand Up @@ -52,4 +53,4 @@ internal static MetricMapper[] GetMappers(Type type)
.ToArray();
}
}
}
}
2 changes: 1 addition & 1 deletion src/NewRelic.Microsoft.SqlServer.Plugin/SqlQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SqlQuery : MetricQuery, ISqlQuery
internal QueryAttribute QueryAttribute;

public SqlQuery(Type queryType, QueryAttribute attribute, IDapperWrapper dapperWrapper, string commandText = null)
: base(queryType, attribute.QueryName, queryType.Name)
: base(queryType, attribute.QueryName, queryType.Name, attribute.MetricTransformEnum)
{
_dapperWrapper = dapperWrapper;
QueryAttribute = attribute;
Expand Down
Loading

0 comments on commit aa96862

Please sign in to comment.