Skip to content

Commit

Permalink
Add label (#194)
Browse files Browse the repository at this point in the history
* add label

* fix
  • Loading branch information
ckr123 authored Jan 15, 2025
1 parent feac322 commit 24bae7b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ await _unitOfWork.OutboxMessageRepository.Create(new OutboxMessage
JsonPayload = JsonSerializer.Serialize(payloadObj)
});
_unitOfWork.Commit();
_stampMetrics.IncrementIssuedCounter();
_stampMetrics.IncrementIssuedCounter(certificate.CertificateType);

_logger.LogInformation("Certificate with registry {Registry} and certificateId {CertificateId} issued.", message.Registry, message.CertificateId);
}
Expand Down
6 changes: 4 additions & 2 deletions src/ProjectOrigin.Stamp.Server/Metrics/StampMetrics.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using ProjectOrigin.Stamp.Server.Models;

namespace ProjectOrigin.Stamp.Server.Metrics;

public interface IStampMetrics
{
void IncrementIssuedCounter();
void IncrementIssuedCounter(GranularCertificateType type);
void IncrementIntentsCounter();
}

Expand All @@ -22,6 +24,6 @@ public class StampMetrics(MeterBase meterBase) : IStampMetrics
unit: "1",
description: "The total number of certificate issuance intents received.");

public void IncrementIssuedCounter() => _issuanceIssuedCounter.Add(1);
public void IncrementIssuedCounter(GranularCertificateType type) => _issuanceIssuedCounter.Add(1, new KeyValuePair<string, object?>("CertificateType", type.ToString()));
public void IncrementIntentsCounter() => _issuanceIntentsCounter.Add(1);
}
1 change: 1 addition & 0 deletions src/ProjectOrigin.Stamp.Test/CertificateIssuingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public async Task IssueSingleCertificate_IncrementsIssuedAndIntentsCountersByOne
var issuedMeasurements = issuedCollector.GetMeasurementSnapshot();
var intentsMeasurements = intentsCollector.GetMeasurementSnapshot();

issuedMeasurements[0].Tags["CertificateType"].Should().Be("Production");
Assert.Equal(1, issuedMeasurements.EvaluateAsCounter());
Assert.Equal(1, intentsMeasurements.EvaluateAsCounter());
}
Expand Down

0 comments on commit 24bae7b

Please sign in to comment.