3
3
import com .appsmith .external .constants .AnalyticsEvents ;
4
4
import com .appsmith .external .git .FileInterface ;
5
5
import com .appsmith .external .git .operations .FileOperations ;
6
- import com .appsmith .external .helpers .Stopwatch ;
6
+ import com .appsmith .external .helpers .ObservationHelper ;
7
7
import com .appsmith .external .models .ApplicationGitReference ;
8
8
import com .appsmith .external .models .ArtifactGitReference ;
9
9
import com .appsmith .external .models .BaseDomain ;
25
25
import com .google .gson .Gson ;
26
26
import com .google .gson .JsonElement ;
27
27
import com .google .gson .JsonObject ;
28
+ import io .micrometer .core .instrument .MeterRegistry ;
29
+ import io .micrometer .core .instrument .Timer ;
30
+ import io .micrometer .tracing .Span ;
28
31
import lombok .RequiredArgsConstructor ;
29
32
import lombok .extern .slf4j .Slf4j ;
30
33
import org .eclipse .jgit .api .errors .GitAPIException ;
@@ -66,6 +69,8 @@ public class CommonGitFileUtilsCE {
66
69
public final int INDEX_LOCK_FILE_STALE_TIME = 300 ;
67
70
68
71
private final JsonSchemaVersions jsonSchemaVersions ;
72
+ private final MeterRegistry meterRegistry ;
73
+ private final ObservationHelper observationHelper ;
69
74
70
75
private ArtifactGitFileUtils <?> getArtifactBasedFileHelper (ArtifactType artifactType ) {
71
76
if (ArtifactType .APPLICATION .equals (artifactType )) {
@@ -112,26 +117,28 @@ public Mono<Path> saveArtifactToLocalRepoWithAnalytics(
112
117
3. Save artifact to git repo
113
118
*/
114
119
// TODO: see if event needs to be generalised or kept specific
115
- Stopwatch stopwatch = new Stopwatch (AnalyticsEvents .GIT_SERIALIZE_APP_RESOURCES_TO_LOCAL_FILE .getEventName ());
120
+ Timer .Sample sample = Timer .start (meterRegistry );
121
+ Span span = observationHelper .createSpan (AnalyticsEvents .GIT_SERIALIZE_APP_RESOURCES_TO_LOCAL_FILE .getEventName ());
122
+ observationHelper .startSpan (span , true );
116
123
ArtifactGitFileUtils <?> artifactGitFileUtils =
117
124
getArtifactBasedFileHelper (artifactExchangeJson .getArtifactJsonType ());
118
125
String artifactConstant = artifactGitFileUtils .getConstantsMap ().get (FieldName .ARTIFACT_CONTEXT );
119
126
120
127
try {
121
128
Mono <Path > repoPathMono = saveArtifactToLocalRepo (baseRepoSuffix , artifactExchangeJson , branchName );
122
129
return Mono .zip (repoPathMono , sessionUserService .getCurrentUser ()).flatMap (tuple -> {
123
- stopwatch .stopTimer ();
130
+ sample .stop (Timer .builder (CommonConstants .GIT_SAVE_ARTIFACT )
131
+ .description (CommonConstants .TIME_TAKEN_TO_SAVE_ARTIFACT )
132
+ .register (meterRegistry ));
133
+ observationHelper .endSpan (span , true );
124
134
Path repoPath = tuple .getT1 ();
125
135
// Path to repo will be : ./container-volumes/git-repo/workspaceId/defaultApplicationId/repoName/
126
136
final Map <String , Object > data = Map .of (
127
137
artifactConstant ,
128
138
repoPath .getParent ().getFileName ().toString (),
129
139
FieldName .ORGANIZATION_ID ,
130
140
repoPath .getParent ().getParent ().getFileName ().toString (),
131
- FieldName .FLOW_NAME ,
132
- stopwatch .getFlow (),
133
- "executionTime" ,
134
- stopwatch .getExecutionTime ());
141
+ "executionTime" , sample .toString ());
135
142
return analyticsService
136
143
.sendEvent (
137
144
AnalyticsEvents .UNIT_EXECUTION_TIME .getEventName (),
@@ -141,6 +148,7 @@ public Mono<Path> saveArtifactToLocalRepoWithAnalytics(
141
148
});
142
149
} catch (IOException | GitAPIException e ) {
143
150
log .error ("Error occurred while saving files to local git repo: " , e );
151
+ observationHelper .endSpan (span , false );
144
152
throw Exceptions .propagate (e );
145
153
}
146
154
}
@@ -202,30 +210,36 @@ private void setDatasourcesInArtifactReference(
202
210
public Mono <ArtifactExchangeJson > reconstructArtifactExchangeJsonFromGitRepoWithAnalytics (
203
211
String workspaceId , String baseArtifactId , String repoName , String branchName , ArtifactType artifactType ) {
204
212
205
- Stopwatch stopwatch = new Stopwatch (AnalyticsEvents .GIT_DESERIALIZE_APP_RESOURCES_FROM_FILE .getEventName ());
213
+ Timer .Sample sample = Timer .start (meterRegistry );
214
+ Span span = observationHelper .createSpan (AnalyticsEvents .GIT_DESERIALIZE_APP_RESOURCES_FROM_FILE .getEventName ());
215
+ observationHelper .startSpan (span , true );
206
216
ArtifactGitFileUtils <?> artifactGitFileUtils = getArtifactBasedFileHelper (artifactType );
207
217
Map <String , String > constantsMap = artifactGitFileUtils .getConstantsMap ();
208
218
return Mono .zip (
209
219
reconstructArtifactExchangeJsonFromGitRepo (
210
220
workspaceId , baseArtifactId , repoName , branchName , artifactType ),
211
221
sessionUserService .getCurrentUser ())
212
222
.flatMap (tuple -> {
213
- stopwatch .stopTimer ();
223
+ sample .stop (Timer .builder (CommonConstants .GIT_DESERIALIZE_ARTIFACT )
224
+ .description (CommonConstants .TIME_TAKEN_TO_DESERIALIZE_ARTIFACT )
225
+ .register (meterRegistry ));
226
+ observationHelper .endSpan (span , true );
214
227
final Map <String , Object > data = Map .of (
215
228
constantsMap .get (FieldName .ID ),
216
229
baseArtifactId ,
217
230
FieldName .ORGANIZATION_ID ,
218
231
workspaceId ,
219
- FieldName .FLOW_NAME ,
220
- stopwatch .getFlow (),
221
- "executionTime" ,
222
- stopwatch .getExecutionTime ());
232
+ "executionTime" , sample .toString ());
223
233
return analyticsService
224
234
.sendEvent (
225
235
AnalyticsEvents .UNIT_EXECUTION_TIME .getEventName (),
226
236
tuple .getT2 ().getUsername (),
227
237
data )
228
238
.thenReturn (tuple .getT1 ());
239
+ })
240
+ .doOnError (e -> {
241
+ observationHelper .endSpan (span , false );
242
+ log .error ("Error deserializing artifact : {}" , e .getMessage ());
229
243
});
230
244
}
231
245
0 commit comments