File: exporter_test.cc

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (77 lines) | stat: -rw-r--r-- 2,669 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <string>

#include "opentelemetry/exporters/prometheus/exporter.h"
#include "opentelemetry/exporters/prometheus/exporter_options.h"
#include "opentelemetry/sdk/metrics/instruments.h"

/**
 * PrometheusExporterTest is a friend class of PrometheusExporter.
 * It has access to a private constructor that does not take in
 * an exposer as an argument, and instead takes no arguments; this
 * private constructor is only to be used here for testing
 */

using opentelemetry::exporter::metrics::PrometheusExporter;
using opentelemetry::exporter::metrics::PrometheusExporterOptions;
using opentelemetry::sdk::metrics::AggregationTemporality;
using opentelemetry::sdk::metrics::InstrumentType;
/**
 * When a PrometheusExporter is initialized,
 * isShutdown should be false.
 */
TEST(PrometheusExporter, InitializeConstructorIsNotShutdown)
{
  PrometheusExporterOptions options;
  options.url = "localhost:8081";
  PrometheusExporter exporter(options);
  // // Asserts that the exporter is not shutdown.
  // ASSERT_TRUE(!exporter.IsShutdown());
  exporter.Shutdown();
}

/**
 * The shutdown() function should set the isShutdown field to true.
 */
TEST(PrometheusExporter, ShutdownSetsIsShutdownToTrue)
{
  PrometheusExporterOptions options;
  PrometheusExporter exporter(options);

  // exporter shuold not be shutdown by default
  ASSERT_TRUE(!exporter.IsShutdown());

  exporter.Shutdown();

  // the exporter shuold be shutdown
  ASSERT_TRUE(exporter.IsShutdown());

  // shutdown function should be idempotent
  exporter.Shutdown();
  ASSERT_TRUE(exporter.IsShutdown());
}

/**
 * The Aggregation temporality should be correctly set
 */
TEST(PrometheusExporter, CheckAggregationTemporality)
{
  PrometheusExporterOptions options;
  PrometheusExporter exporter(options);

  ASSERT_EQ(exporter.GetAggregationTemporality(InstrumentType::kCounter),
            AggregationTemporality::kCumulative);
  ASSERT_EQ(exporter.GetAggregationTemporality(InstrumentType::kHistogram),
            AggregationTemporality::kCumulative);
  ASSERT_EQ(exporter.GetAggregationTemporality(InstrumentType::kObservableCounter),
            AggregationTemporality::kCumulative);
  ASSERT_EQ(exporter.GetAggregationTemporality(InstrumentType::kObservableGauge),
            AggregationTemporality::kCumulative);
  ASSERT_EQ(exporter.GetAggregationTemporality(InstrumentType::kObservableUpDownCounter),
            AggregationTemporality::kCumulative);
  ASSERT_EQ(exporter.GetAggregationTemporality(InstrumentType::kUpDownCounter),
            AggregationTemporality::kCumulative);
}