internal static string BuildOperationMoniker(string verb, List <KeyValuePair <string, string> > resourcePath) { var operation = HttpParsingHelper.BuildOperationMoniker(verb, resourcePath); // Do not generate asterisk for docs path if (resourcePath.Count > 1 && resourcePath[1].Key == "docs" && DocumentOperationNotMonikerActions.Contains(resourcePath[1].Value)) { operation = operation.Remove(operation.Length - 1) + resourcePath[1].Value; } return(operation); }
/// <summary> /// Tries parsing given dependency telemetry item. /// </summary> /// <param name="httpDependency">Dependency item to parse. It is expected to be of HTTP type.</param> /// <returns><code>true</code> if successfully parsed dependency.</returns> internal static bool TryParse(ref DependencyTelemetry httpDependency) { string name = httpDependency.Name; string host = httpDependency.Target; string url = httpDependency.Data; if (name == null || host == null || url == null) { return(false); } if (!HttpParsingHelper.EndsWithAny(host, DocumentDbHostSuffixes)) { return(false); } //// //// DocumentDB REST API: https://docs.microsoft.com/en-us/rest/api/documentdb/ //// string verb; string nameWithoutVerb; // try to parse out the verb HttpParsingHelper.ExtractVerb(name, out verb, out nameWithoutVerb, DocumentDbSupportedVerbs); List <KeyValuePair <string, string> > resourcePath = HttpParsingHelper.ParseResourcePath(nameWithoutVerb); // populate properties foreach (var resource in resourcePath) { if (resource.Value != null) { string propertyName = GetPropertyNameForResource(resource.Key); if (propertyName != null) { httpDependency.Properties[propertyName] = resource.Value; } } } string operation = HttpParsingHelper.BuildOperationMoniker(verb, resourcePath); string operationName = GetOperationName(httpDependency, operation); httpDependency.Type = RemoteDependencyConstants.AzureDocumentDb; httpDependency.Name = string.IsNullOrEmpty(operationName) ? httpDependency.Target : operationName; return(true); }
private void DocumentDbHttpParserConvertsValidDependencies( string operation, string verb, string url, Dictionary <string, string> properties, string resultCode) { Uri parsedUrl = new Uri(url); // Parse with verb var d = new DependencyTelemetry( dependencyTypeName: RemoteDependencyConstants.HTTP, target: parsedUrl.Host, dependencyName: verb + " " + parsedUrl.AbsolutePath, data: parsedUrl.OriginalString) { ResultCode = resultCode ?? "200" }; bool success = DocumentDbHttpParser.TryParse(ref d); Assert.IsTrue(success, operation); Assert.AreEqual(RemoteDependencyConstants.AzureDocumentDb, d.Type, operation); Assert.AreEqual(parsedUrl.Host, d.Target, operation); Assert.AreEqual(operation, d.Name, operation); if (properties != null) { foreach (var property in properties) { string value = null; Assert.IsTrue(d.Properties.TryGetValue(property.Key, out value), operation); Assert.AreEqual(property.Value, value, operation); } } // Parse without verb d = new DependencyTelemetry( dependencyTypeName: RemoteDependencyConstants.HTTP, target: parsedUrl.Host, dependencyName: parsedUrl.AbsolutePath, data: parsedUrl.OriginalString) { ResultCode = resultCode ?? "200" }; success = DocumentDbHttpParser.TryParse(ref d); Assert.IsTrue(success, operation); Assert.AreEqual(RemoteDependencyConstants.AzureDocumentDb, d.Type, operation); Assert.AreEqual(parsedUrl.Host, d.Target, operation); string moniker = HttpParsingHelper.BuildOperationMoniker(null, HttpParsingHelper.ParseResourcePath(parsedUrl.AbsolutePath)); Assert.AreEqual(moniker, d.Name, operation); if (properties != null) { foreach (var property in properties) { string value = null; Assert.IsTrue(d.Properties.TryGetValue(property.Key, out value), operation); Assert.AreEqual(property.Value, value, operation); } } }
private static void ValidateBuildOperationMoniker(string verb, string url, string expectedMoniker) { var resourcePath = HttpParsingHelper.ParseResourcePath(url); Assert.AreEqual(expectedMoniker, HttpParsingHelper.BuildOperationMoniker(verb, resourcePath)); }