diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 885a4eef..8ff2ce72 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -2498,55 +2498,6 @@ namespace MP.Data.Services { int answ = -1; saveCallRec("getCounterTC"); - // 2023.11.08 versione originale con tentativi reiterati, eliminata -#if false - // variabile x controllo dati recuperati - DS_ProdTempi.StatoProdDataTable datiProdAct = null; - bool okDatiProd = false; - int taSP_ms_ant = memLayer.ML.cdvi("taStatoProd_ms_anticipo"); - DateTime dataRif = DateTime.Now.AddMilliseconds(-taSP_ms_ant); - okDatiProd = getStatoProd(idxMacchina, ref datiProdAct, dataRif); - // se NON avesse recuperato --> aspetto taSP_ms_ant e poi RICHIAMO procedura... - int maxTry = 3; - while (!okDatiProd && maxTry > 0) - { - Log.Info(string.Format("[pzCounterTC] Impossibile recuperare dati ODL x idxMacchina {0}", idxMacchina), tipoLog.WARNING); - // sleep... - Thread.Sleep(taSP_ms_ant * 2); - // riprovo lettura... - okDatiProd = getStatoProd(idxMacchina, ref datiProdAct, dataRif); - maxTry--; - } - - // ora proseguo SE ho trovato i dati... - if (okDatiProd) - { - if (datiProdAct != null) - { - if (datiProdAct.Count > 0) - { - if (!datiProdAct[0].IsPzTotODLNull()) - { - // ...a questo punto recupero DAVVERO i dati (o almeno ci provo...) - try - { - // controllo - answ = datiProdAct[0].PzTotODL; - } - catch (Exception exc) - { - Log.Info(string.Format("[pzCounterTC] Eccezione in recupero PzTotODL x idxMacchina {0}{1}{2}", idxMacchina, Environment.NewLine, exc), tipoLog.EXCEPTION); - } - } - } - } - } - else - { - Log.Info(string.Format("[pzCounterTC] Dati ODL x idxMacchina {0} non recuperati dopo tentativi reiterati...", idxMacchina), tipoLog.WARNING); - } -#endif - DateTime dataRif = DateTime.Now; var datiProd = await StatoProdMacchina(idxMacchina, dataRif); if (datiProd != null) diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index c11f5885..071c480a 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -100,6 +100,7 @@ namespace MP.SPEC.Data /// public async Task ActionGetReq() { + using var activity = ActivitySource.StartActivity("ActionGetReq"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); DisplayAction? result = null; @@ -116,6 +117,7 @@ namespace MP.SPEC.Data { result = new DisplayAction(); } + activity?.SetTag("data.source", "REDIS"); return result; } @@ -126,6 +128,7 @@ namespace MP.SPEC.Data /// public bool ActionSetReq(DisplayAction? act2save) { + using var activity = ActivitySource.StartActivity("ActionSetReq"); bool fatto = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); @@ -136,6 +139,7 @@ namespace MP.SPEC.Data stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"ActionSetReq REDIS send to broadcast + Write cache: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "REDIS"); return fatto; } @@ -145,6 +149,7 @@ namespace MP.SPEC.Data /// public AnagCountersModel AnagCountersGetNext(string cntType) { + using var activity = ActivitySource.StartActivity("AnagCountersGetNext"); AnagCountersModel result = new AnagCountersModel(); string source = "DB"; Stopwatch sw = new Stopwatch(); @@ -152,6 +157,7 @@ namespace MP.SPEC.Data result = dbController.AnagCountersGetNext(cntType); sw.Stop(); Log.Debug($"AnagCountersGetNext | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); return result; } @@ -161,6 +167,7 @@ namespace MP.SPEC.Data /// public bool AnagGruppiDelete(AnagGruppiModel updRec) { + using var activity = ActivitySource.StartActivity("AnagGruppiDelete"); bool result = false; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -171,6 +178,7 @@ namespace MP.SPEC.Data sw.Stop(); TimeSpan ts = sw.Elapsed; Log.Debug($"AnagGruppiDelete | CodGruppo {updRec.CodGruppo} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } @@ -181,6 +189,7 @@ namespace MP.SPEC.Data /// public bool AnagGruppiUpsert(AnagGruppiModel UpdRec) { + using var activity = ActivitySource.StartActivity("AnagGruppiUpsert"); bool result = false; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -191,15 +200,23 @@ namespace MP.SPEC.Data sw.Stop(); TimeSpan ts = sw.Elapsed; Log.Debug($"AnagGruppiUpsert | CodGruppo {UpdRec.CodGruppo} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } + /// + /// Oggetto per collezione dati Activity (span in Uptrace) + /// + private static readonly ActivitySource ActivitySource = new ActivitySource("MP.DATA.Tracer"); + /// /// Elenco Gruppi /// /// public async Task> AnagKeyValGetAll() { + // nuovo oggetto span activity + using var activity = ActivitySource.StartActivity("AnagKeyValGetAll"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string source = "DB"; @@ -225,22 +242,27 @@ namespace MP.SPEC.Data stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"AnagKeyValGetAll Read from {source}: {ts.TotalMilliseconds}ms"); + + // 3. Aggiunta dei dati come "Tag" allo span, non come una stringa di testo (il tempo è implicito) + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); + return result; } public async Task> AnagStatiComm() { + using var activity = ActivitySource.StartActivity("AnagStatiComm"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); + string source = "DB"; List? result = new List(); // cerco in redis... RedisValue rawData = await redisDb.StringGetAsync(Utils.redisStatoCom); if (!string.IsNullOrEmpty($"{rawData}")) { result = JsonConvert.DeserializeObject>($"{rawData}"); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"AnagStatiComm Read from REDIS: {ts.TotalMilliseconds}ms"); + source = "REDIS"; } else { @@ -248,19 +270,22 @@ namespace MP.SPEC.Data // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(Utils.redisStatoCom, rawData, getRandTOut(redisLongTimeCache)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"AnagStatiComm Read from DB: {ts.TotalMilliseconds}ms"); } if (result == null) { result = new List(); } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagStatiComm Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } public async Task> AnagTipoArtLV() { + using var activity = ActivitySource.StartActivity("AnagStatiComm"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string source = "DB"; @@ -279,13 +304,15 @@ namespace MP.SPEC.Data rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(Utils.redisTipoArt, rawData, getRandTOut(redisLongTimeCache)); } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"AnagTipoArtLV Read from {source}: {ts.TotalMilliseconds}ms"); if (result == null) { result = new List(); } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagTipoArtLV Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -295,17 +322,18 @@ namespace MP.SPEC.Data /// public async Task> ArticleWithDossier() { + using var activity = ActivitySource.StartActivity("ArticleWithDossier"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = Utils.redisArtByDossier; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -320,7 +348,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ArticleWithDossier | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ArticleWithDossier | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -331,8 +361,10 @@ namespace MP.SPEC.Data /// public async Task ArticoliDeleteRecord(AnagArticoliModel currRec) { + using var activity = ActivitySource.StartActivity("ArticoliDeleteRecord"); bool fatto = await dbController.ArticoliDeleteRecord(currRec); await resetCacheArticoli(); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -344,10 +376,11 @@ namespace MP.SPEC.Data /// public List ArticoliGetByTipo(string tipo, string azienda = "*") { + using var activity = ActivitySource.StartActivity("ArticoliGetByTipo"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string sKey = string.IsNullOrEmpty(tipo) ? "ALL" : tipo; string currKey = $"{Utils.redisArtList}:{azienda}:Tipo:{sKey}"; // cerco in redis dato valore sel idxMaccSel... @@ -355,7 +388,7 @@ namespace MP.SPEC.Data if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -370,7 +403,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ArticoliGetByTipo | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ArticoliGetByTipo | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -382,10 +417,11 @@ namespace MP.SPEC.Data /// public async Task> ArticoliGetSearch(int numRecord, string azienda, string searchVal) { + using var activity = ActivitySource.StartActivity("ArticoliGetSearch"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string sKey = string.IsNullOrEmpty(searchVal) ? "***" : searchVal; string currKey = $"{Utils.redisArtList}:{azienda}:{sKey}"; // cerco in redis dato valore sel idxMaccSel... @@ -393,7 +429,7 @@ namespace MP.SPEC.Data if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -408,7 +444,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ArticoliGetSearch | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ArticoliGetSearch | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -419,8 +457,10 @@ namespace MP.SPEC.Data /// public async Task ArticoliUpdateRecord(AnagArticoliModel currRec) { + using var activity = ActivitySource.StartActivity("ArticoliUpdateRecord"); bool fatto = await dbController.ArticoliUpdateRecord(currRec); await resetCacheArticoli(); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -432,6 +472,7 @@ namespace MP.SPEC.Data /// public bool ArticoloDelEnabled(object CodArt) { + using var activity = ActivitySource.StartActivity("ArticoloDelEnabled"); bool answ = false; string codArticolo = $"{CodArt}"; int cacheCheckArtUsato = 1; @@ -488,12 +529,16 @@ namespace MP.SPEC.Data catch { } } + activity?.SetTag("data.source", "DB+REDIS"); return answ; } public string CalcRecipe(RecipeModel currRecipe) { - return mongoController.CalcRecipe(currRecipe); + using var activity = ActivitySource.StartActivity("CalcRecipe"); + var result = mongoController.CalcRecipe(currRecipe); + activity?.SetTag("data.source", "MONGO"); + return result; } /// @@ -502,7 +547,8 @@ namespace MP.SPEC.Data /// public List ConfigGetAll() { - string currMode = "REDIS"; + using var activity = ActivitySource.StartActivity("ConfigGetAll"); + string source = "REDIS"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List? result = new List(); @@ -514,7 +560,7 @@ namespace MP.SPEC.Data } else { - currMode = "DB"; + source = "DB"; result = dbController.ConfigGetAll(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); @@ -525,7 +571,9 @@ namespace MP.SPEC.Data result = new List(); } stopWatch.Stop(); - Log.Debug($"ConfigGetAll Read from {currMode}: {stopWatch.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"ConfigGetAll Read from {source}: {stopWatch.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -535,6 +583,8 @@ namespace MP.SPEC.Data /// public async Task> ConfigGetAllAsync() { + using var activity = ActivitySource.StartActivity("ConfigGetAllAsync"); + string source = "REDIS"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List? result = new List(); @@ -543,9 +593,7 @@ namespace MP.SPEC.Data if (!string.IsNullOrEmpty($"{rawData}")) { result = JsonConvert.DeserializeObject>($"{rawData}"); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ConfigGetAllAsync Read from REDIS: {ts.TotalMilliseconds}ms"); + source = "REDIS"; } else { @@ -553,14 +601,15 @@ namespace MP.SPEC.Data // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ConfigGetAllAsync Read from DB: {ts.TotalMilliseconds}ms"); } if (result == null) { result = new List(); } + stopWatch.Stop(); + Log.Debug($"ConfigGetAllAsync Read from {source}: {stopWatch.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -570,7 +619,9 @@ namespace MP.SPEC.Data /// public async Task ConfigResetCache() { + using var activity = ActivitySource.StartActivity("ConfigResetCache"); await redisDb.StringSetAsync(Utils.redisConfKey, ""); + activity?.SetTag("data.source", "REDIS"); } /// @@ -580,6 +631,7 @@ namespace MP.SPEC.Data /// public string ConfigTryGet(string keyName) { + using var activity = ActivitySource.StartActivity("ConfigTryGet"); string answ = ""; // preselezione valori if (configData == null || configData.Count == 0) @@ -600,7 +652,7 @@ namespace MP.SPEC.Data { answ = currRec.Valore; } - + activity?.SetTag("data.source", "DB+REDIS"); return answ; } @@ -611,6 +663,7 @@ namespace MP.SPEC.Data /// public async Task ConfigTryGetAsync(string keyName) { + using var activity = ActivitySource.StartActivity("ConfigTryGetAsync"); string answ = ""; // preselezione valori if (configData == null || configData.Count == 0) @@ -631,7 +684,7 @@ namespace MP.SPEC.Data { answ = currRec.Valore; } - + activity?.SetTag("data.source", "DB+REDIS"); return answ; } @@ -641,7 +694,10 @@ namespace MP.SPEC.Data /// public async Task ConfigUpdate(ConfigModel updRec) { - return await Task.FromResult(dbController.ConfigUpdate(updRec)); + using var activity = ActivitySource.StartActivity("ConfigUpdate"); + var updRes = dbController.ConfigUpdate(updRec); + activity?.SetTag("data.source", "DB"); + return await Task.FromResult(updRes); } /// @@ -650,6 +706,7 @@ namespace MP.SPEC.Data /// public Dictionary DbDedupStats() { + using var activity = ActivitySource.StartActivity("DbDedupStats"); Dictionary actStats = new Dictionary(); string currKey = $"{Utils.redisStatsDbMaint}"; // recupero i record statistiche correnti @@ -662,6 +719,7 @@ namespace MP.SPEC.Data actStats = rawStats; } } + activity?.SetTag("data.source", "REDIS"); return actStats; } @@ -683,6 +741,7 @@ namespace MP.SPEC.Data /// public async Task DossiersDeleteRecord(DossierModel selRecord) { + using var activity = ActivitySource.StartActivity("DossiersDeleteRecord"); bool result = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); @@ -693,6 +752,7 @@ namespace MP.SPEC.Data stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"DossiersDeleteRecord | IdxMacchina {selRecord.IdxMacchina} | DtRif {selRecord.DtRif} | IdxODL {selRecord.IdxODL} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } @@ -706,17 +766,18 @@ namespace MP.SPEC.Data /// public async Task> DossiersGetLastFilt(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd) { + using var activity = ActivitySource.StartActivity("DossiersGetLastFilt"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisDossByMac}:{IdxMacchina}:{CodArticolo}:{DtStart:yyyyMMddHHmm}:{DtEnd:yyyyMMddHHmm}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -731,7 +792,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DossiersGetLastFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"DossiersGetLastFilt | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -742,9 +805,10 @@ namespace MP.SPEC.Data /// public async Task DossiersInsert(DossierModel currDoss) { + using var activity = ActivitySource.StartActivity("DossiersInsert"); // aggiorno record sul DB bool answ = await dbController.DossiersInsert(currDoss); - + activity?.SetTag("data.source", "DB"); return answ; } @@ -757,8 +821,8 @@ namespace MP.SPEC.Data /// public async Task DossiersTakeParamsSnapshotLast(string IdxMacchina, DateTime dtMin, DateTime dtMax) { + using var activity = ActivitySource.StartActivity("DossiersUpdateValore"); bool answ = false; - await Task.Delay(1); Log.Info($"Richiesta snapshot per idxMaccSel {IdxMacchina} | periodo {dtMin} --> {dtMax}"); // chiamo stored x salvare parametri dbController.DossiersTakeParamsSnapshotLast(IdxMacchina, dtMin, dtMax); @@ -766,6 +830,7 @@ namespace MP.SPEC.Data RedisValue pattern = new RedisValue($"{Utils.redisDossByMac}:*"); answ = await ExecFlushRedisPatternAsync(pattern); Log.Info($"Svuotata cache dossier | {pattern}"); + activity?.SetTag("data.source", "DB+REDIS"); return answ; } @@ -776,9 +841,10 @@ namespace MP.SPEC.Data /// public async Task DossiersUpdateValore(DossierModel currDoss) { + using var activity = ActivitySource.StartActivity("DossiersUpdateValore"); // aggiorno record sul DB bool answ = await dbController.DossiersUpdateValore(currDoss); - + activity?.SetTag("data.source", "DB"); return answ; } @@ -788,7 +854,10 @@ namespace MP.SPEC.Data /// public Task> ElencoAziende() { - return Task.FromResult(dbController.AnagGruppiAziende()); + using var activity = ActivitySource.StartActivity("ElencoAziende"); + var listAz = dbController.AnagGruppiAziende(); + activity?.SetTag("data.source", "DB"); + return Task.FromResult(listAz); } /// @@ -797,10 +866,11 @@ namespace MP.SPEC.Data /// public List ElencoGruppiFase() { + using var activity = ActivitySource.StartActivity("ElencoGruppiFase"); List result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisAnagGruppi}:FASE"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); @@ -811,7 +881,7 @@ namespace MP.SPEC.Data { result = rawResult; } - readType = "REDIS"; + source = "REDIS"; } else { @@ -826,13 +896,18 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ElencoGruppiFase | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ElencoGruppiFase | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } public Task> ElencoLink() { - return Task.FromResult(dbController.ElencoLink()); + using var activity = ActivitySource.StartActivity("ElencoLink"); + var linkList = dbController.ElencoLink(); + activity?.SetTag("data.source", "DB"); + return Task.FromResult(linkList); } /// @@ -841,10 +916,11 @@ namespace MP.SPEC.Data /// public List ElencoRepartiDTO() { + using var activity = ActivitySource.StartActivity("ElencoRepartiDTO"); List result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisAnagGruppi}:REPARTO"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); @@ -855,7 +931,7 @@ namespace MP.SPEC.Data { result = rawResult; } - readType = "REDIS"; + source = "REDIS"; } else { @@ -870,7 +946,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ElencoRepartiDTO | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ElencoRepartiDTO | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -881,7 +959,10 @@ namespace MP.SPEC.Data /// public async Task EvListInsert(EventListModel newRec) { - return await dbController.EvListInsert(newRec); + using var activity = ActivitySource.StartActivity("EvListInsert"); + var result = await dbController.EvListInsert(newRec); + activity?.SetTag("data.source", "DB"); + return result; } /// @@ -891,6 +972,7 @@ namespace MP.SPEC.Data /// public bool ExecFlushRedisPattern(string pat2Flush) { + using var activity = ActivitySource.StartActivity("ExecFlushRedisPattern"); bool answ = false; var masterEndpoint = redisConn.GetEndPoints() .Where(ep => redisConn.GetServer(ep).IsConnected && !redisConn.GetServer(ep).IsReplica) @@ -925,23 +1007,7 @@ namespace MP.SPEC.Data redisDb.KeyDelete(item); } answ = true; -#if false - var listEndpoints = redisConnAdmin.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConnAdmin.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - redisDb.KeyDelete(item); - } - answ = true; - } - } -#endif + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -952,6 +1018,7 @@ namespace MP.SPEC.Data /// public async Task ExecFlushRedisPatternAsync(RedisValue pat2Flush) { + using var activity = ActivitySource.StartActivity("ExecFlushRedisPatternAsync"); bool answ = false; var masterEndpoint = redisConn.GetEndPoints() .Where(ep => redisConn.GetServer(ep).IsConnected && !redisConn.GetServer(ep).IsReplica) @@ -983,23 +1050,7 @@ namespace MP.SPEC.Data } } answ = true; -#if false - var listEndpoints = redisConnAdmin.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - var server = redisConnAdmin.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - answ = true; - } - } -#endif - + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -1010,6 +1061,7 @@ namespace MP.SPEC.Data /// public DateTime ExpiryReloadParamGet() { + using var activity = ActivitySource.StartActivity("ExpiryReloadParamGet"); DateTime dtRif = DateTime.Now; string currKey = $"{Utils.redisParamPageExp}"; RedisValue rawData = redisDb.StringGet(currKey); @@ -1017,6 +1069,7 @@ namespace MP.SPEC.Data { dtRif = JsonConvert.DeserializeObject($"{rawData}"); } + activity?.SetTag("data.source", "REDIS"); return dtRif; } @@ -1027,19 +1080,22 @@ namespace MP.SPEC.Data /// public bool ExpiryReloadParamSet(DateTime expTime) { + using var activity = ActivitySource.StartActivity("ExpiryReloadParamSet"); bool fatto = false; string currKey = $"{Utils.redisParamPageExp}"; string rawData = JsonConvert.SerializeObject(expTime); fatto = redisDb.StringSet(currKey, rawData); + activity?.SetTag("data.source", "REDIS"); return fatto; } public async Task FlushCacheFluxLog() { + using var activity = ActivitySource.StartActivity("FlushCacheFluxLog"); bool answ = false; RedisValue pattern = new RedisValue($"{Utils.redisParetoFLKey}:*"); answ = await ExecFlushRedisPatternAsync(pattern); - + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -1049,11 +1105,13 @@ namespace MP.SPEC.Data /// public async Task FlushMpIoOdlCache() { + using var activity = ActivitySource.StartActivity("FlushMpIoOdlCache"); // svuoto dalla cache REDIS del server IO... bool ok01 = await ResetIoCache("CurrODL"); bool ok02 = await ResetIoCache("CurrOdlRow"); bool ok03 = await ResetIoCache("CurrStatoMacc"); bool ok04 = await ResetIoCache("DtMac"); + activity?.SetTag("data.source", "REDIS"); return ok01 && ok02 && ok03 && ok04; } @@ -1069,9 +1127,10 @@ namespace MP.SPEC.Data public async Task FlushRedisKey(string redKey) { - await Task.Delay(1); + using var activity = ActivitySource.StartActivity("FlushRedisKey"); RedisValue pattern = Utils.RedValue(redKey); bool answ = await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -1087,11 +1146,13 @@ namespace MP.SPEC.Data /// public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, DtUtils.Periodo currPeriodo, Enums.ValSelection valMode, Enums.DataInterval intReq, int maxItem) { + using var activity = ActivitySource.StartActivity("FluxLogDataRedux"); List procStats = await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); // effettuo merge statistiche... ProcDedupStatMerge(procStats); // svuoto cache await FlushCacheFluxLog(); + activity?.SetTag("data.source", "DB+REDIS"); } public List FluxLogDtoGetByFlux(string Valore) @@ -1127,17 +1188,18 @@ namespace MP.SPEC.Data /// public async Task> FluxLogGetLastFilt(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec, double redisCacheSec) { + using var activity = ActivitySource.StartActivity("FluxLogGetLastFilt"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisFluxLogFilt}:{IdxMacchina}:{CodFlux}:{MaxRec}:{DtMax:yyyyMMddHHmm}:{DtMin:yyyyMMddHHmm}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1159,7 +1221,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"FluxLogGetLastFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"FluxLogGetLastFilt | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1169,6 +1233,7 @@ namespace MP.SPEC.Data /// public async Task> FluxLogPareto(string idxMacchina, DateTime dtFrom, DateTime dtTo) { + using var activity = ActivitySource.StartActivity("FluxLogPareto"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string source = "DB"; @@ -1195,6 +1260,8 @@ namespace MP.SPEC.Data stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"ParetoFluxLog Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1210,6 +1277,7 @@ namespace MP.SPEC.Data /// public async Task ForceDbMaint(bool doExec = true, bool doUpdStat = true, bool doSave = true, int minPgCnt = 1000, int minAvgFrag = 10, int maxAvgFragReb = 50) { + using var activity = ActivitySource.StartActivity("ForceDbMaint"); Stopwatch sw = Stopwatch.StartNew(); await dbController.ForceDbMaint(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); sw.Stop(); @@ -1217,6 +1285,7 @@ namespace MP.SPEC.Data RecDbMaintStat(sw.Elapsed); // svuoto cache await FlushCacheFluxLog(); + activity?.SetTag("data.source", "DB+REDIS"); } /// @@ -1226,16 +1295,17 @@ namespace MP.SPEC.Data /// public bool Grp2MaccDelete(Gruppi2MaccModel rec2del) { + using var activity = ActivitySource.StartActivity("Grp2MaccDelete"); bool result = false; Stopwatch sw = new Stopwatch(); sw.Start(); result = dbController.Grp2MaccDelete(rec2del); // elimino cache redis... - ExecFlushRedisPattern(new RedisValue($"{Utils.redisAnagGruppi}:*")); - ExecFlushRedisPattern(new RedisValue($"{Utils.redisMacList}:*")); + ResetMacGrpCache(); sw.Stop(); TimeSpan ts = sw.Elapsed; Log.Debug($"Grp2MaccDelete | CodGruppo {rec2del.CodGruppo} | IdxMacc {rec2del.IdxMacchina} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } @@ -1246,18 +1316,27 @@ namespace MP.SPEC.Data /// public bool Grp2MaccInsert(Gruppi2MaccModel upsRec) { + using var activity = ActivitySource.StartActivity("Grp2MaccInsert"); bool result = false; Stopwatch sw = new Stopwatch(); sw.Start(); result = dbController.Grp2MaccInsert(upsRec); // elimino cache redis... - ExecFlushRedisPattern(new RedisValue($"{Utils.redisAnagGruppi}:*")); - ExecFlushRedisPattern(new RedisValue($"{Utils.redisMacList}:*")); + ResetMacGrpCache(); sw.Stop(); TimeSpan ts = sw.Elapsed; Log.Debug($"Grp2MaccInsert | CodGruppo {upsRec.CodGruppo} | IdxMacc {upsRec.IdxMacchina} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } + /// + /// Reset macchine e gruppi + /// + private void ResetMacGrpCache() + { + ExecFlushRedisPattern($"{Utils.redisAnagGruppi}:*"); + ExecFlushRedisPattern($"{Utils.redisMacList}:*"); + } /// /// Eliminazione di un record operatore dal gruppo @@ -1266,16 +1345,17 @@ namespace MP.SPEC.Data /// public bool Grp2OperDelete(Gruppi2OperModel rec2del) { + using var activity = ActivitySource.StartActivity("Grp2OperDelete"); bool result = false; Stopwatch sw = new Stopwatch(); sw.Start(); result = dbController.Grp2OperDelete(rec2del); // elimino cache redis... - ExecFlushRedisPattern(new RedisValue($"{Utils.redisAnagGruppi}:*")); - ExecFlushRedisPattern(new RedisValue($"{Utils.redisOprList}:*")); + ResetOprGrpCache(); sw.Stop(); TimeSpan ts = sw.Elapsed; Log.Debug($"Grp2OperDelete | CodGruppo {rec2del.CodGruppo} | MatrOpr {rec2del.MatrOpr} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } @@ -1286,19 +1366,29 @@ namespace MP.SPEC.Data /// public bool Grp2OperInsert(Gruppi2OperModel upsRec) { + using var activity = ActivitySource.StartActivity("Grp2OperInsert"); bool result = false; Stopwatch sw = new Stopwatch(); sw.Start(); result = dbController.Grp2OperInsert(upsRec); // elimino cache redis... - ExecFlushRedisPattern(new RedisValue($"{Utils.redisAnagGruppi}:*")); - ExecFlushRedisPattern(new RedisValue($"{Utils.redisOprList}:*")); + ResetOprGrpCache(); sw.Stop(); TimeSpan ts = sw.Elapsed; Log.Debug($"Grp2OperInsert | CodGruppo {upsRec.CodGruppo} | MatrOpr {upsRec.MatrOpr} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB+REDIS"); return result; } + /// + /// Reset cache operatori e gruppi + /// + private void ResetOprGrpCache() + { + ExecFlushRedisPattern($"{Utils.redisAnagGruppi}:*"); + ExecFlushRedisPattern($"{Utils.redisOprList}:*"); + } + /// /// Init ricetta /// @@ -1318,6 +1408,7 @@ namespace MP.SPEC.Data /// public async Task IobInfo(string IdxMacchina) { + using var activity = ActivitySource.StartActivity("IobInfo"); string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -1344,6 +1435,7 @@ namespace MP.SPEC.Data } sw.Stop(); Log.Debug($"IobInfo per {IdxMacchina} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); return result; } @@ -1353,12 +1445,14 @@ namespace MP.SPEC.Data /// public async Task IstKitDelete(IstanzeKitModel currRecord) { + using var activity = ActivitySource.StartActivity("IstKitDelete"); bool fatto = false; // salvo fatto = dbController.IstKitDelete(currRecord); // svuoto cache RedisValue pattern = $"{Utils.redisKitInst}:*"; await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -1370,6 +1464,7 @@ namespace MP.SPEC.Data /// public List IstKitFilt(string keyKit, string keyExtOrd) { + using var activity = ActivitySource.StartActivity("IstKitFilt"); string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -1395,6 +1490,8 @@ namespace MP.SPEC.Data } sw.Stop(); Log.Debug($"IstKitFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1406,14 +1503,16 @@ namespace MP.SPEC.Data public bool IstKitInsertByWKS(string CodArtParent, string KeyFilt) { bool fatto = false; + using var activity = ActivitySource.StartActivity("IstKitInsertByWKS"); // salvo fatto = dbController.IstKitInsertByWKS(CodArtParent, KeyFilt); // svuoto cache - ExecFlushRedisPattern((RedisValue)$"{Utils.redisKit}:*"); + ExecFlushRedisPattern($"{Utils.redisKit}:*"); //ExecFlushRedisPattern((RedisValue)$"{Utils.redisKitInst}:*"); //ExecFlushRedisPattern((RedisValue)$"{Utils.redisKitScore}:*"); //ExecFlushRedisPattern((RedisValue)$"{Utils.redisKitTempl}:*"); //ExecFlushRedisPattern((RedisValue)$"{Utils.redisKitWip}:*"); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -1423,12 +1522,14 @@ namespace MP.SPEC.Data /// public async Task IstKitUpsert(IstanzeKitModel currRecord) { + using var activity = ActivitySource.StartActivity("IstKitUpsert"); bool fatto = false; // salvo fatto = dbController.IstKitUpsert(currRecord); // svuoto cache RedisValue pattern = $"{Utils.redisKitInst}:*"; await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -1438,17 +1539,18 @@ namespace MP.SPEC.Data /// public async Task> ListGiacenze(int IdxOdl) { + using var activity = ActivitySource.StartActivity("ListGiacenze"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisGiacenzaList}:{IdxOdl}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1463,7 +1565,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ListGiacenze | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ListGiacenze | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1475,12 +1579,13 @@ namespace MP.SPEC.Data /// public List ListPODL_ByCodArt(string CodArticolo, bool OnlyAvail) { + using var activity = ActivitySource.StartActivity("ListPODL_ByCodArt"); List result = new List(); if (!string.IsNullOrEmpty(CodArticolo)) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string avType = OnlyAvail ? "Avail" : "ALL"; string currKey = $"{Utils.redisPOdlByCodArt}:{CodArticolo}:{avType}"; // cerco in redis dato valore sel idxMaccSel... @@ -1491,7 +1596,7 @@ namespace MP.SPEC.Data if (rawResult != null) { result = rawResult; - readType = "REDIS"; + source = "REDIS"; } } else @@ -1507,7 +1612,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"ListPODL_ByCodArt | {readType} | {ts.TotalMilliseconds}ms"); + Log.Trace($"ListPODL_ByCodArt | {source} | {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); } else { @@ -1523,10 +1630,11 @@ namespace MP.SPEC.Data /// public List MacchineGetFilt(string codGruppo) { + using var activity = ActivitySource.StartActivity("MacchineGetFilt"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; string currKey = $"{Utils.redisMacList}:{keyGrp}"; // cerco in redis dato valore sel idxMaccSel... @@ -1534,7 +1642,7 @@ namespace MP.SPEC.Data if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1549,7 +1657,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"MacchineGetAll | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"MacchineGetAll | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", 1); return result; } @@ -1560,17 +1670,18 @@ namespace MP.SPEC.Data /// public string MacchineRecipeArchive(string idxMacchina) { + using var activity = ActivitySource.StartActivity("MacchineRecipeArchive"); string? result = ""; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisMacRecipePath}:{idxMacchina}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1584,7 +1695,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"MacchineRecipeArchive | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"MacchineRecipeArchive | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", 1); return result ?? ""; } @@ -1595,17 +1708,18 @@ namespace MP.SPEC.Data /// public string MacchineRecipeConf(string idxMacchina) { + using var activity = ActivitySource.StartActivity("MacchineRecipeConf"); string? result = ""; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisMacRecipeConf}:{idxMacchina}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1619,7 +1733,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"MacchineRecipeConf | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"MacchineRecipeConf | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", 1); return result ?? ""; } @@ -1631,17 +1747,18 @@ namespace MP.SPEC.Data /// public async Task> MacchineWithFlux(DateTime dtStart, DateTime dtEnd) { + using var activity = ActivitySource.StartActivity("MacchineWithFlux"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisMacByFlux}:{dtStart:yyyyMMddHHmm}:{dtEnd:yyyyMMddHHmm}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1656,7 +1773,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"MacchineWithFlux | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"MacchineWithFlux | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1667,6 +1786,7 @@ namespace MP.SPEC.Data /// public Dictionary MachIobConf(string IdxMacchina) { + using var activity = ActivitySource.StartActivity("MachIobConf"); string source = "NA"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -1691,6 +1811,8 @@ namespace MP.SPEC.Data } sw.Stop(); Log.Debug($"MachIobConf per {IdxMacchina} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1731,17 +1853,18 @@ namespace MP.SPEC.Data /// public async Task> OdlByBatch(string BatchSel) { + using var activity = ActivitySource.StartActivity("OdlByBatch"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = Utils.redisOdlByBatch; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1756,7 +1879,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OdlByBatch | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"OdlByBatch | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1767,14 +1892,16 @@ namespace MP.SPEC.Data /// public ODLExpModel OdlByKey(int IdxOdl) { + using var activity = ActivitySource.StartActivity("OdlByKey"); ODLExpModel? result = new ODLExpModel(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; result = dbController.OdlByKey(IdxOdl); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OdlByKey | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"OdlByKey | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); return result; } @@ -1787,8 +1914,8 @@ namespace MP.SPEC.Data /// indica se confermare i pezzi priam di chiudere ODL public async Task ODLClose(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi) { + using var activity = ActivitySource.StartActivity("ODLClose"); bool fatto = false; - await Task.Delay(1); // recupero dati x conf modalità conferma var configData = await ConfigGetAllAsync(); if (configData != null) @@ -1808,7 +1935,7 @@ namespace MP.SPEC.Data // chiamo metodo conferma! fatto = await dbController.ODLClose(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); } - + activity?.SetTag("data.source", "DB"); return fatto; } @@ -1818,8 +1945,10 @@ namespace MP.SPEC.Data /// public async Task OdlGetByKey(int IdxOdl) { + using var activity = ActivitySource.StartActivity("OdlGetByKey"); await Task.Delay(1); var dbResult = dbController.OdlGetByKey(IdxOdl); + activity?.SetTag("data.source", "DB"); return dbResult; } @@ -1830,10 +1959,11 @@ namespace MP.SPEC.Data /// public List OdlGetCurrent() { + using var activity = ActivitySource.StartActivity("OdlGetCurrent"); List? dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisOdlCurrByMac}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); @@ -1845,7 +1975,7 @@ namespace MP.SPEC.Data } catch { } - readType = "REDIS"; + source = "REDIS"; } else { @@ -1859,8 +1989,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OdlGetCurrent | Read from {readType}: {ts.TotalMilliseconds}ms"); - + Log.Debug($"OdlGetCurrent | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", dbResult.Count); return dbResult; } @@ -1871,14 +2002,16 @@ namespace MP.SPEC.Data /// public List OdlListAll() { + using var activity = ActivitySource.StartActivity("OdlListAll"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; result = dbController.OdlListAll(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OdlListAll | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"OdlListAll | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB"); return result; } @@ -1895,17 +2028,18 @@ namespace MP.SPEC.Data /// public async Task> OdlListGetFilt(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate) { + using var activity = ActivitySource.StartActivity("OdlListGetFilt"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisOdlList}:{inCorso}:{codArt}:{keyRichPart}:{Reparto}:{IdxMacchina}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1920,7 +2054,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OdlListGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"OdlListGetFilt | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1931,10 +2067,11 @@ namespace MP.SPEC.Data /// public List OperatoriGetFilt(string codGruppo) { + using var activity = ActivitySource.StartActivity("OperatoriGetFilt"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; string currKey = $"{Utils.redisOprList}:{keyGrp}"; // cerco in redis dato valore sel idxMaccSel... @@ -1942,7 +2079,7 @@ namespace MP.SPEC.Data if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1957,7 +2094,8 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OperatoriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"OperatoriGetFilt | Read from {source}: {ts.TotalMilliseconds}ms"); activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -1968,17 +2106,18 @@ namespace MP.SPEC.Data /// public async Task> ParametriGetFilt(string IdxMacchina) { + using var activity = ActivitySource.StartActivity("ParametriGetFilt"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisFluxByMac}:{IdxMacchina}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -1993,7 +2132,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"ParametriGetFilt | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2004,10 +2145,11 @@ namespace MP.SPEC.Data /// public async Task POdlDeleteRecord(PODLExpModel currRec) { + using var activity = ActivitySource.StartActivity("POdlDeleteRecord"); var dbResult = await dbController.PODLDeleteRecord(currRec); // elimino cache redis... await POdlFlushCache(); - await Task.Delay(1); + activity?.SetTag("data.source", "DB+REDIS"); return dbResult; } @@ -2018,10 +2160,11 @@ namespace MP.SPEC.Data /// public async Task POdlDoSetup(PODLExpModel currRec) { + using var activity = ActivitySource.StartActivity("POdlDoSetup"); var dbResult = await dbController.PODL_startSetup(currRec, 0, 1, 1, "", DateTime.Now); // elimino cache redis... await POdlFlushCache(); - await Task.Delay(1); + activity?.SetTag("data.source", "DB+REDIS"); return dbResult; } @@ -2032,12 +2175,13 @@ namespace MP.SPEC.Data /// public async Task POdlGetByKey(int idxPODL) { + using var activity = ActivitySource.StartActivity("POdlGetByKey"); PODLModel result = new PODLModel(); if (idxPODL != 0) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisPOdlByPOdl}:{idxPODL}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); @@ -2047,7 +2191,7 @@ namespace MP.SPEC.Data if (rawResult != null) { result = rawResult; - readType = "REDIS"; + source = "REDIS"; } } else @@ -2063,7 +2207,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"POdlGetByKey | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Trace($"POdlGetByKey | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", 1); } else { @@ -2079,12 +2225,13 @@ namespace MP.SPEC.Data /// public PODLModel POdlGetByOdl(int idxODL) { + using var activity = ActivitySource.StartActivity("POdlGetByOdl"); PODLModel result = new PODLModel(); if (idxODL != 0) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisPOdlByOdl}:{idxODL}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); @@ -2095,7 +2242,7 @@ namespace MP.SPEC.Data { result = rawResult; } - readType = "REDIS"; + source = "REDIS"; } else { @@ -2110,7 +2257,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"POdlGetByOdl | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Trace($"POdlGetByOdl | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", 1); } else { @@ -2125,12 +2274,17 @@ namespace MP.SPEC.Data /// IdxPODL parent public bool PodlIstKitDelete(int IdxPODL) { + using var activity = ActivitySource.StartActivity("PodlIstKitDelete"); bool fatto = false; // salvo fatto = dbController.PodlIstKitDelete(IdxPODL); // svuoto cache - RedisValue pattern = $"{Utils.redisKit}:*"; - ExecFlushRedisPattern(pattern); + string pattern = $"{Utils.redisKit}:*"; + if (!string.IsNullOrEmpty(pattern)) + { + ExecFlushRedisPattern(pattern); + } + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -2141,17 +2295,18 @@ namespace MP.SPEC.Data /// public List POdlListByKitParent(int IdxPodlParent) { + using var activity = ActivitySource.StartActivity("POdlListByKitParent"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisPOdlList}_kit:ByParent:{IdxPodlParent}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -2166,7 +2321,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"POdlListByKitParent | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"POdlListByKitParent | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2182,17 +2339,18 @@ namespace MP.SPEC.Data /// public List POdlListGetFilt(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) { + using var activity = ActivitySource.StartActivity("POdlListGetFiltAsync"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisPOdlList}:{codGruppo}:{idxMacchina}:{keyRichPart}:{lanciato}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -2207,7 +2365,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"POdlListGetFiltAsync | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"POdlListGetFiltAsync | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2223,17 +2383,18 @@ namespace MP.SPEC.Data /// public async Task> POdlListGetFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) { + using var activity = ActivitySource.StartActivity("POdlListGetFiltAsync"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisPOdlList}:{codGruppo}:{idxMacchina}:{keyRichPart}:{lanciato}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -2248,7 +2409,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"POdlListGetFiltAsync | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"POdlListGetFiltAsync | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2264,17 +2427,18 @@ namespace MP.SPEC.Data /// public async Task> POdlToKitListGetFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) { + using var activity = ActivitySource.StartActivity("POdlToKitListGetFiltAsync"); List? result = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "DB"; + string source = "DB"; string currKey = $"{Utils.redisPOdlList}_kit:{codGruppo}:{idxMacchina}:{keyRichPart}:{lanciato}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}"; // cerco in redis dato valore sel idxMaccSel... RedisValue rawData = redisDb.StringGet(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; + source = "REDIS"; } else { @@ -2289,7 +2453,9 @@ namespace MP.SPEC.Data } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"POdlToKitListGetFiltAsync | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"POdlToKitListGetFiltAsync | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2301,6 +2467,7 @@ namespace MP.SPEC.Data /// public async Task POdlUpdateRecipe(int idxPODL, string recipeName) { + using var activity = ActivitySource.StartActivity("POdlUpdateRecipe"); bool answ = false; answ = await dbController.PODL_updateRecipe(idxPODL, recipeName); // reset redis... @@ -2308,6 +2475,7 @@ namespace MP.SPEC.Data { await POdlFlushCache(); } + activity?.SetTag("data.source", "DB+REDIS"); return answ; } @@ -2318,9 +2486,11 @@ namespace MP.SPEC.Data /// public async Task POdlUpdateRecord(PODLModel currRec) { + using var activity = ActivitySource.StartActivity("POdlUpdateRecord"); var dbResult = await dbController.PODLUpdateRecord(currRec); // elimino cache redis... await POdlFlushCache(); + activity?.SetTag("data.source", "DB+REDIS"); return dbResult; } @@ -2330,6 +2500,7 @@ namespace MP.SPEC.Data /// public List ProcFLStats() { + using var activity = ActivitySource.StartActivity("ProcFLStats"); List actStats = new List(); string currKey = $"{Utils.redisStatsProcFL}"; // recupero i record statistiche correnti @@ -2342,6 +2513,7 @@ namespace MP.SPEC.Data actStats = rawStats; } } + activity?.SetTag("data.source", "REDIS"); return actStats; } @@ -2352,14 +2524,16 @@ namespace MP.SPEC.Data /// public async Task RecipeGetByPODL(int idxPODL) { + using var activity = ActivitySource.StartActivity("RecipeGetByPODL"); RecipeModel? result = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - string readType = "MongoDB"; + string source = "MongoDB"; result = await mongoController.RecipeGetByPODL(idxPODL); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"RecipeGetByPODL | Read from {readType}: {ts.TotalMilliseconds}ms"); + Log.Debug($"RecipeGetByPODL | Read from {source}: {ts.TotalMilliseconds}ms"); + activity?.SetTag("data.source", "DB"); return result; } @@ -2370,12 +2544,14 @@ namespace MP.SPEC.Data /// public async Task RecipeSetByPODL(RecipeModel currRecord) { + using var activity = ActivitySource.StartActivity("RedisCountKey"); bool answ = false; answ = await mongoController.RecipeSetByPODL(currRecord); if (answ) { await POdlFlushCache(); } + activity?.SetTag("data.source", "DB+REDIS"); return answ; } @@ -2386,6 +2562,7 @@ namespace MP.SPEC.Data /// public int RedisCountKey(string keyPattern) { + using var activity = ActivitySource.StartActivity("RedisCountKey"); int num = 0; keyPattern = (string.IsNullOrEmpty(keyPattern) ? "**" : keyPattern); try @@ -2404,7 +2581,7 @@ namespace MP.SPEC.Data { Log.Error($"Eccezione in RedisCountKey{Environment.NewLine}{arg}"); } - + activity?.SetTag("data.source", "REDIS"); return num; } @@ -2415,6 +2592,7 @@ namespace MP.SPEC.Data /// public bool RedisDelKey(string keyVal) { + using var activity = ActivitySource.StartActivity("RedisDelKey"); bool answ = false; var listEndpoints = redisConnAdmin.GetEndPoints(); foreach (var endPoint in listEndpoints) @@ -2426,6 +2604,7 @@ namespace MP.SPEC.Data answ = true; } } + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -2436,6 +2615,7 @@ namespace MP.SPEC.Data /// public async Task ResetIoCache(string baseMem) { + using var activity = ActivitySource.StartActivity("TemplateKitDelete"); // patterna a partire da cache IO... RedisValue pattern = new RedisValue($"{MpIoNS}:*"); if (!string.IsNullOrEmpty(baseMem)) @@ -2443,6 +2623,7 @@ namespace MP.SPEC.Data pattern = new RedisValue($"{MpIoNS}:{baseMem}:*"); } bool answ = await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -2456,7 +2637,7 @@ namespace MP.SPEC.Data } /// - /// restituisce il valore da REDIS associato al tag richeisto + /// Restituisce il valore da REDIS associato al tag richiesto /// /// Chiave in cui cercare il valore /// @@ -2487,12 +2668,14 @@ namespace MP.SPEC.Data /// public async Task TemplateKitDelete(TemplateKitModel currRecord) { + using var activity = ActivitySource.StartActivity("TemplateKitDelete"); bool fatto = false; // salvo fatto = dbController.TemplateKitDelete(currRecord); // svuoto cache RedisValue pattern = $"{Utils.redisKitTempl}:*"; await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -2504,6 +2687,7 @@ namespace MP.SPEC.Data /// public List TemplateKitFilt(string codParent, string codChild) { + using var activity = ActivitySource.StartActivity("TemplateKitFilt"); string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -2529,6 +2713,8 @@ namespace MP.SPEC.Data } sw.Stop(); Log.Debug($"TemplateKitFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2539,12 +2725,14 @@ namespace MP.SPEC.Data /// public async Task TemplateKitUpsert(TemplateKitModel currRecord, string codAzienda) { + using var activity = ActivitySource.StartActivity("TemplateKitUpsert"); bool fatto = false; // salvo fatto = dbController.TemplateKitUpsert(currRecord, codAzienda); // svuoto cache RedisValue pattern = $"{Utils.redisKitTempl}:*"; await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "DB+REDIS"); return fatto; } @@ -2557,6 +2745,7 @@ namespace MP.SPEC.Data /// public List TksScore(string KeyFilt, int MaxResult, bool ForceDb) { + using var activity = ActivitySource.StartActivity("TksScore"); string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -2582,6 +2771,8 @@ namespace MP.SPEC.Data } sw.Stop(); Log.Debug($"TksScore | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2610,6 +2801,7 @@ namespace MP.SPEC.Data public async Task updateDossierValue(DossierModel currDoss, FluxLogDTO editFL) { + using var activity = ActivitySource.StartActivity("updateDossierValue"); bool answ = false; // recupero intero set valori dossier deserializzando... var fluxLogList = FluxLogDtoGetByFlux(currDoss.Valore); @@ -2644,7 +2836,7 @@ namespace MP.SPEC.Data // aggiorno record sul DB await dbController.DossiersUpdateValore(currDoss); } - + activity?.SetTag("data.source", "DB+REDIS"); return answ; } @@ -2654,6 +2846,7 @@ namespace MP.SPEC.Data /// public List VocabolarioGetAll() { + using var activity = ActivitySource.StartActivity("VocabolarioGetAll"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List? result = new List(); @@ -2679,6 +2872,8 @@ namespace MP.SPEC.Data { result = new List(); } + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2688,12 +2883,13 @@ namespace MP.SPEC.Data /// public bool WipKitDelete(WipSetupKitModel currRecord) { + using var activity = ActivitySource.StartActivity("WipKitDelete"); bool fatto = false; // salvo fatto = dbController.WipKitDelete(currRecord); // svuoto cache - RedisValue pattern = $"{Utils.redisKitWip}:*"; - ExecFlushRedisPattern(pattern); + EmptyWipCache(); + activity?.SetTag("data.source", "REDIS"); return fatto; } @@ -2703,12 +2899,13 @@ namespace MP.SPEC.Data /// public bool WipKitDeleteGroup(string KeyFilt) { + using var activity = ActivitySource.StartActivity("WipKitDeleteGroup"); bool fatto = false; // salvo fatto = dbController.WipKitDeleteGroup(KeyFilt); // svuoto cache - RedisValue pattern = $"{Utils.redisKitWip}:*"; - ExecFlushRedisPattern(pattern); + EmptyWipCache(); + activity?.SetTag("data.source", "REDIS"); return fatto; } @@ -2718,15 +2915,28 @@ namespace MP.SPEC.Data /// public bool WipKitDeleteOlder(DateTime DateLimit) { + using var activity = ActivitySource.StartActivity("WipKitDeleteOlder"); bool fatto = false; // salvo fatto = dbController.WipKitDeleteOlder(DateLimit); // svuoto cache - RedisValue pattern = $"{Utils.redisKitWip}:*"; - ExecFlushRedisPattern(pattern); + EmptyWipCache(); + activity?.SetTag("data.source", "REDIS"); return fatto; } + /// + /// Svuota cache creazione KIT + /// + private void EmptyWipCache() + { + string pattern = $"{Utils.redisKitWip}:*"; + if (!string.IsNullOrEmpty(pattern)) + { + ExecFlushRedisPattern(pattern); + } + } + /// /// Elenco Template KIT da ricerca /// @@ -2734,6 +2944,7 @@ namespace MP.SPEC.Data /// public List WipKitFilt(string KeyFilt) { + using var activity = ActivitySource.StartActivity("WipKitFilt"); string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -2759,6 +2970,8 @@ namespace MP.SPEC.Data } sw.Stop(); Log.Debug($"WipKitFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + activity?.SetTag("data.source", source); + activity?.SetTag("result.count", result.Count); return result; } @@ -2768,12 +2981,13 @@ namespace MP.SPEC.Data /// public bool WipKitUpsert(WipSetupKitModel currRecord) { + using var activity = ActivitySource.StartActivity("WipKitUpsert"); bool fatto = false; // salvo fatto = dbController.WipKitUpsert(currRecord); - // svuoto cache - RedisValue pattern = $"{Utils.redisKitWip}:*"; - ExecFlushRedisPattern(pattern); + // svuoto cache KitWip + EmptyWipCache(); + activity?.SetTag("data.source", "REDIS"); return fatto; } @@ -2915,38 +3129,9 @@ namespace MP.SPEC.Data #region Private Methods -#if false - /// - /// Esegue flush memoria redis dato pat2Flush - /// - /// - /// - private bool ExecFlushRedisPattern(RedisValue pattern) - { - bool answ = false; - var listEndpoints = redisConn.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConn.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - redisDb.KeyDelete(item); - } - answ = true; - } - } - // notifico DoUpdate ai client in ascolto x reset cache - NotifyReloadRequest($"FlushRedisCache | {pattern}"); - return answ; - } -#endif - private async Task POdlFlushCache() { + using var activity = ActivitySource.StartActivity("POdlFlushCache"); bool answ = false; RedisValue pattern = new RedisValue($"{Utils.redisXdlData}:*"); answ = await ExecFlushRedisPatternAsync(pattern); @@ -2956,7 +3141,7 @@ namespace MP.SPEC.Data answ = await ExecFlushRedisPatternAsync(pattern); pattern = new RedisValue($"{Utils.redisPOdlList}:*"); answ = await ExecFlushRedisPatternAsync(pattern); - + activity?.SetTag("data.source", "REDIS"); return answ; } @@ -2977,10 +3162,12 @@ namespace MP.SPEC.Data private async Task resetCacheArticoli() { + using var activity = ActivitySource.StartActivity("resetCacheArticoli"); RedisValue pattern = new RedisValue($"{Utils.redisArtByDossier}:*"); await ExecFlushRedisPatternAsync(pattern); pattern = new RedisValue($"{Utils.redisArtList}:*"); await ExecFlushRedisPatternAsync(pattern); + activity?.SetTag("data.source", "REDIS"); } #endregion Private Methods