Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/packages/python/django-5.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiAndreiev authored Dec 11, 2024
2 parents e059f14 + 4cf4e84 commit 9e2ebef
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 212 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
- windows-latest
python-version:
# https://endoflife.date/python
- 3.8 # EOL: October 14th, 2024
- 3.9 # EOL: October 5rd, 2025
- '3.10' # EOL: October 4rd, 2026
- '3.11' # EOL: October 24th, 2027
Expand Down
129 changes: 25 additions & 104 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/dotnet/ReadMe/ConfigValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ public class Options
public int bufferLength { get; set; } = 1;

public string baseLogUrl { get; set; } = "https://example.readme.com";

public bool fireAndForget { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using ReadMe.HarJsonObjectModels;

namespace ReadMe.HarJsonTranslationLogics
Expand All @@ -28,7 +27,7 @@ public HarJsonBuilder(RequestDelegate next, HttpContext context, IConfiguration
this.configValues = configValues;
}

public async Task<string> BuildHar()
internal async Task<Root> BuildHar()
{
Root harObj = new Root();
harObj._id = Guid.NewGuid().ToString();
Expand All @@ -37,8 +36,7 @@ public async Task<string> BuildHar()
harObj.clientIPAddress = this.context.Connection.RemoteIpAddress.ToString();
harObj.group = this.BuildGroup();
harObj.request = new RequestMain(await this.BuildLog());
string harJsonObj = JsonConvert.SerializeObject(new List<Root>() { harObj });
return harJsonObj;
return harObj;
}

private Group BuildGroup()
Expand Down
19 changes: 13 additions & 6 deletions packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ namespace ReadMe.HarJsonTranslationLogics
{
class ReadMeApiCaller
{
private readonly string harJsonObject;
private readonly string harJsonObjects;
private readonly string apiKey;

public ReadMeApiCaller(string harJsonObject, string apiKey)
public ReadMeApiCaller(string harJsonObjects, string apiKey)
{
this.harJsonObject = harJsonObject;
this.harJsonObjects = harJsonObjects;
this.apiKey = apiKey;
}

public void SendHarObjToReadMeApi()
public void SendHarObjToReadMeApi(bool fireAndForget)
{
try
{
Expand All @@ -25,8 +25,15 @@ public void SendHarObjToReadMeApi()
request.AddHeader("Content-Type", "application/json");
string apiKey = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(this.apiKey + ":"));
request.AddHeader("Authorization", apiKey);
request.AddParameter("application/json", this.harJsonObject, ParameterType.RequestBody);
client.ExecuteAsync(request);
request.AddParameter("application/json", this.harJsonObjects, ParameterType.RequestBody);
if (fireAndForget)
{
client.ExecuteAsync(request);
}
else
{
client.Execute(request);
}
}
catch (Exception)
{
Expand Down
23 changes: 20 additions & 3 deletions packages/dotnet/ReadMe/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using ReadMe.HarJsonObjectModels;
using ReadMe.HarJsonTranslationLogics;

Expand All @@ -11,12 +12,14 @@ public class Metrics
{
private readonly RequestDelegate next;
private readonly IConfiguration configuration;
private readonly List<Root> harQueue;
private Group group;

public Metrics(RequestDelegate next, IConfiguration configuration)
{
this.next = next;
this.configuration = configuration;
this.harQueue = new List<Root>();
}

public async Task InvokeAsync(HttpContext context)
Expand Down Expand Up @@ -44,9 +47,18 @@ public async Task InvokeAsync(HttpContext context)
context.Request.EnableBuffering();
HarJsonBuilder harJsonBuilder = new HarJsonBuilder(this.next, context, this.configuration, configValues);

string harJsonObj = await harJsonBuilder.BuildHar();
ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(harJsonObj, configValues.apiKey);
readmeApiCaller.SendHarObjToReadMeApi();
var harObj = await harJsonBuilder.BuildHar();
lock (this.harQueue)
{
this.harQueue.Add(harObj);
if (this.harQueue.Count >= configValues.options.bufferLength)
{
string serializaedHars = JsonConvert.SerializeObject(this.harQueue);
ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(serializaedHars, configValues.apiKey);
readmeApiCaller.SendHarObjToReadMeApi(configValues.options.fireAndForget);
this.harQueue.Clear();
}
}
}
else
{
Expand Down Expand Up @@ -114,6 +126,11 @@ private ConfigValues GetConfigValues()
optionsObj.baseLogUrl = options.GetSection("baseLogUrl").Value;
}

if (options.GetSection("fireAndForget").Value != null)
{
optionsObj.fireAndForget = bool.Parse(options.GetSection("fireAndForget").Value);
}

configValues.options = optionsObj;
return configValues;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
"prettier": "@readme/eslint-config/prettier",
"optionalDependencies": {
"pino": "^9.3.2",
"pino-pretty": "^11.2.2"
"pino-pretty": "^13.0.0"
}
}
Loading

0 comments on commit 9e2ebef

Please sign in to comment.