Example #1
0
        public static KustoRow ToKustoRow(TimeSeries ts)
        {
            var kustoRow = new KustoRow
            {
                Timestamp = ts.Samples[0].Timestamp,
                Value     = ts.Samples[0].Value
            };

            var labelsDict = new SortedDictionary <string, string>();

            foreach (var label in ts.Labels)
            {
                switch (label.Name)
                {
                case "__name__":
                    kustoRow.Name = label.Value;
                    break;

                case "job":
                    kustoRow.Job = label.Value;
                    break;

                case "instance":
                    kustoRow.Instance = label.Value;
                    break;
                }

                labelsDict[label.Name] = label.Value;
            }

            kustoRow.Labels = JsonConvert.SerializeObject(labelsDict);
            return(kustoRow);
        }
Example #2
0
        public void ToKustoRow_PrometheusTimeSeriesObjectShouldReturnValidKustoRowObject()
        {
            // Arrange
            var ts = new Prometheus.TimeSeries()
            {
                Labels =
                {
                    new Prometheus.Label()
                    {
                        Name  = "__name__",
                        Value = "TestName"
                    },
                    new Prometheus.Label()
                    {
                        Name  = "job",
                        Value = "TestJob"
                    }
                },
                Samples =
                {
                    new Prometheus.Sample()
                    {
                        Timestamp = 123,
                        Value     = 0
                    }
                }
            };
            var expectedKustoRow = new KustoRow()
            {
                Instance  = null,
                Job       = "TestJob",
                Labels    = @"{""__name__"":""TestName"",""job"":""TestJob""}",
                Name      = "TestName",
                Timestamp = 123,
                Value     = 0,
            };
            // Act
            var resultKustoRow = KustoManipulations.ToKustoRow(ts);

            // Assert
            foreach (PropertyInfo property in typeof(KustoRow).GetProperties())
            {
                Assert.AreEqual(
                    property.GetValue(expectedKustoRow, null),
                    property.GetValue(resultKustoRow, null),
                    $"KustoRow property '{property.Name}' are not equal"
                    );
            }
        }