@@ -89,7 +89,6 @@ func NewEmfExporter(
89
89
config configmodels.Exporter ,
90
90
params component.ExporterCreateParams ,
91
91
) (component.MetricsExporter , error ) {
92
-
93
92
exp , err := New (config , params )
94
93
if err != nil {
95
94
return nil , err
@@ -105,12 +104,23 @@ func NewEmfExporter(
105
104
}
106
105
107
106
func (emf * emfExporter ) pushMetricsData (_ context.Context , md pdata.Metrics ) (droppedTimeSeries int , err error ) {
107
+ rms := md .ResourceMetrics ()
108
+ labels := map [string ]string {}
109
+ for i := 0 ; i < rms .Len (); i ++ {
110
+ rm := rms .At (i )
111
+ am := rm .Resource ().Attributes ()
112
+ if am .Len () > 0 {
113
+ am .ForEach (func (k string , v pdata.AttributeValue ) {
114
+ labels [k ] = v .StringVal ()
115
+ })
116
+ }
117
+ }
118
+ emf .logger .Info ("Start processing resource metrics" , zap .Any ("labels" , labels ))
119
+
108
120
groupedMetrics := make (map [interface {}]* GroupedMetric )
109
121
expConfig := emf .config .(* Config )
110
122
defaultLogStream := fmt .Sprintf ("otel-stream-%s" , emf .collectorID )
111
123
112
- rms := md .ResourceMetrics ()
113
-
114
124
for i := 0 ; i < rms .Len (); i ++ {
115
125
rm := rms .At (i )
116
126
emf .metricTranslator .translateOTelToGroupedMetric (& rm , groupedMetrics , expConfig )
@@ -133,14 +143,23 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pdata.Metrics) (dr
133
143
err = wrapErrorIfBadRequest (& returnError )
134
144
return
135
145
}
136
- returnError = pusher .ForceFlush ()
137
- if returnError != nil {
138
- err = wrapErrorIfBadRequest (& returnError )
139
- return
146
+ }
147
+ }
148
+
149
+ for _ , pusher := range emf .listPushers () {
150
+ returnError := pusher .ForceFlush ()
151
+ if returnError != nil {
152
+ //TODO now we only have one pusher, so it's ok to return after first error occurred
153
+ err = wrapErrorIfBadRequest (& returnError )
154
+ if err != nil {
155
+ emf .logger .Error ("Error force flushing logs. Skipping to next pusher." , zap .Error (err ))
140
156
}
157
+ return
141
158
}
142
159
}
143
160
161
+ emf .logger .Info ("Finish processing resource metrics" , zap .Any ("labels" , labels ))
162
+
144
163
return
145
164
}
146
165
@@ -163,6 +182,19 @@ func (emf *emfExporter) getPusher(logGroup, logStream string) Pusher {
163
182
return pusher
164
183
}
165
184
185
+ func (emf * emfExporter ) listPushers () []Pusher {
186
+ emf .pusherMapLock .Lock ()
187
+ defer emf .pusherMapLock .Unlock ()
188
+
189
+ pushers := []Pusher {}
190
+ for _ , pusherMap := range emf .groupStreamToPusherMap {
191
+ for _ , pusher := range pusherMap {
192
+ pushers = append (pushers , pusher )
193
+ }
194
+ }
195
+ return pushers
196
+ }
197
+
166
198
func (emf * emfExporter ) ConsumeMetrics (ctx context.Context , md pdata.Metrics ) error {
167
199
exporterCtx := obsreport .ExporterContext (ctx , "emf.exporterFullName" )
168
200
@@ -172,20 +204,12 @@ func (emf *emfExporter) ConsumeMetrics(ctx context.Context, md pdata.Metrics) er
172
204
173
205
// Shutdown stops the exporter and is invoked during shutdown.
174
206
func (emf * emfExporter ) Shutdown (ctx context.Context ) error {
175
- emf .pusherMapLock .Lock ()
176
- defer emf .pusherMapLock .Unlock ()
177
-
178
- var err error
179
- for _ , streamToPusherMap := range emf .groupStreamToPusherMap {
180
- for _ , pusher := range streamToPusherMap {
181
- if pusher != nil {
182
- returnError := pusher .ForceFlush ()
183
- if returnError != nil {
184
- err = wrapErrorIfBadRequest (& returnError )
185
- }
186
- if err != nil {
187
- emf .logger .Error ("Error when gracefully shutting down emf_exporter. Skipping to next pusher." , zap .Error (err ))
188
- }
207
+ for _ , pusher := range emf .listPushers () {
208
+ returnError := pusher .ForceFlush ()
209
+ if returnError != nil {
210
+ err := wrapErrorIfBadRequest (& returnError )
211
+ if err != nil {
212
+ emf .logger .Error ("Error when gracefully shutting down emf_exporter. Skipping to next pusher." , zap .Error (err ))
189
213
}
190
214
}
191
215
}
0 commit comments