Ejemplo n.º 1
0
        public void ToKustoExpression_PrometheusQueryShouldReturnValidKustoQuery(string name,
                                                                                 LabelMatcher.Types.Type type, string val, string expected)
        {
            // Arrange
            // Act
            var kql = KustoManipulations.ToKustoExpression(name, type, val);

            // Assert
            CollectionAssert.AreEqual(expected, kql);
        }
Ejemplo n.º 2
0
        public static string ToKustoExpression(string name, LabelMatcher.Types.Type type, string value)
        {
            var keyMap = new Dictionary <string, string>()
            {
                { "__name__", "Name" },
                { "job", "Job" },
                { "instance", "Instance" }
            };

            var resultName = keyMap.ContainsKey(name) ? keyMap[name] : $"tostring(Labels.{name})";

            const string queryTemplate = "( {0} {1} '{2}' )";

            return(type switch
            {
                LabelMatcher.Types.Type.Eq => string.Format(queryTemplate, resultName, "==", value),
                LabelMatcher.Types.Type.Neq => string.Format(queryTemplate, resultName, "!=", value),
                LabelMatcher.Types.Type.Re => string.Format(queryTemplate, resultName, "matches regex", value),
                LabelMatcher.Types.Type.Nre => string.Format(queryTemplate, resultName, "!contains", value),
                _ => string.Empty
            });
Ejemplo n.º 3
0
        private static String GenerateValueExpression(string name, LabelMatcher.Types.Type type, string value)
        {
            switch (type)
            {
            case LabelMatcher.Types.Type.Eq:
                return($"tostring(label.{name}) == \"{value}\"");

            case LabelMatcher.Types.Type.Neq:
                return($"tostring(label.{name}) != \"{value}\"");

            case LabelMatcher.Types.Type.Re:
                return($"tostring(label.{name}) matches regex \"{value}\"");

            case LabelMatcher.Types.Type.Nre:
                //operator missing
                return($"tostring(label.{name}) !contains \"{value}\"");

            default:
                break;
            }

            return(String.Empty);
        }