@@ -95,26 +95,32 @@ public void run() {
95
95
);
96
96
otelMetrics .add (getMetricWithResourceAttributes (eachPartialMetric , resourceAttrs ));
97
97
}
98
- resourceMetric = ResourceMetrics .newBuilder ()
99
- .setResource (reportingResource )
100
- .addScopeMetrics (ScopeMetrics .newBuilder ()
101
- .setScope (InstrumentationScope .newBuilder ()
102
- .setName (Constants .SELF_NAME )
103
- .setVersion (Constants .SELF_VERSION )
104
- .build ())
105
- .addAllMetrics (otelMetrics )
106
- .build ())
107
- .build ();
108
- resourceMetricsList .add (resourceMetric );
98
+ if (!otelMetrics .isEmpty ()) {
99
+ resourceMetric = ResourceMetrics .newBuilder ()
100
+ .setResource (reportingResource )
101
+ .addScopeMetrics (ScopeMetrics .newBuilder ()
102
+ .setScope (InstrumentationScope .newBuilder ()
103
+ .setName (Constants .SELF_NAME )
104
+ .setVersion (Constants .SELF_VERSION )
105
+ .build ())
106
+ .addAllMetrics (otelMetrics )
107
+ .build ())
108
+ .build ();
109
+ resourceMetricsList .add (resourceMetric );
110
+ }
109
111
}
110
- ExportMetricsServiceRequest resourceMetrics = ExportMetricsServiceRequest .newBuilder ()
111
- .addAllResourceMetrics (resourceMetricsList )
112
- .build ();
113
- log .info (requestID + ": Sending payload for: " + groupKey );
114
- log .debug (requestID + ": Complete payload for " + groupKey + ": " + resourceMetrics );
115
- boolean responseStatus = payloadHandler .postPayload (resourceMetrics );
116
- if (metricGeneratorState .getTransportStorage () != null ) {
117
- metricGeneratorState .getTransportStorage ().store (groupKey , resourceMetrics , responseStatus );
112
+ if (resourceMetricsList .isEmpty ()) {
113
+ log .info ("No metrics received from generator for: " + groupKey );
114
+ } else {
115
+ ExportMetricsServiceRequest resourceMetrics = ExportMetricsServiceRequest .newBuilder ()
116
+ .addAllResourceMetrics (resourceMetricsList )
117
+ .build ();
118
+ log .info (requestID + ": Sending payload for: " + groupKey );
119
+ //log.debug(requestID + ": Complete payload for " + groupKey + ": " + resourceMetrics);
120
+ boolean responseStatus = payloadHandler .postPayload (resourceMetrics );
121
+ if (metricGeneratorState .getTransportStorage () != null ) {
122
+ metricGeneratorState .getTransportStorage ().store (groupKey , resourceMetrics , responseStatus );
123
+ }
118
124
}
119
125
currentCount ++;
120
126
metricGeneratorState .getThreadPayloadCounts ().put (groupKey , currentCount );
@@ -139,21 +145,28 @@ private Pair<List<Resource>, List<Set<String>>> getReportingResources() {
139
145
.get (resourceType ).stream ()
140
146
.filter (GeneratorResource ::isActive )
141
147
.toList ();
148
+ int allReportingResourcesCount = allReportingResources .size ();
149
+ log .info ("All " + allReportingResourcesCount + " " + resourceType + " resources will report the metrics: " +
150
+ String .join (", " , metricsWithAllResources ));
142
151
List <Set <String >> metricsForEachResource = new ArrayList <>();
143
- for (int resourceIndex =0 ; resourceIndex <allReportingResources . size () ; resourceIndex ++) {
152
+ for (int resourceIndex =0 ; resourceIndex <allReportingResourcesCount ; resourceIndex ++) {
144
153
metricsForEachResource .add (new HashSet <>(metricsWithAllResources ));
145
154
}
146
155
Set <String > metricsWithFilteredResources = new HashSet <>(metrics .keySet ());
147
156
metricsWithFilteredResources .removeAll (metricsWithAllResources );
148
157
for (String metricWithFilteredResources : metricsWithFilteredResources ) {
149
- for (int resourceIndex =0 ; resourceIndex <allReportingResources .size (); resourceIndex ++) {
158
+ int selectedCount = 0 ;
159
+ for (int resourceIndex =0 ; resourceIndex <allReportingResourcesCount ; resourceIndex ++) {
150
160
if (allReportingResources .get (resourceIndex ).getEvaluatedAttributes ().entrySet ().containsAll (
151
161
metrics .get (metricWithFilteredResources ).getParsedFilteredReportingResources ()
152
162
.get (resourceType ).entrySet ()
153
163
)) {
154
164
metricsForEachResource .get (resourceIndex ).add (metricWithFilteredResources );
165
+ selectedCount ++;
155
166
}
156
167
}
168
+ log .debug (selectedCount + " " + resourceType + " resources selected for metric " +
169
+ metricWithFilteredResources );
157
170
}
158
171
return Pair .of (allReportingResources .stream ().map (GeneratorResource ::getOTelResource ).toList (),
159
172
metricsForEachResource );
0 commit comments