Skip to content

Commit 60f2767

Browse files
authored
Fix authentication metrics for 4.0 (#1445)
1 parent a7f2688 commit 60f2767

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/identitypool/AuthenticationProviderMTls.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class AuthenticationProviderMTls implements AuthenticationProvider {
6969
@VisibleForTesting
7070
private final ConcurrentHashMap<String, ExpressionCompiler> poolMap = new ConcurrentHashMap<>();
7171
private boolean needCloseMetaData = false;
72+
private AuthenticationMetrics metrics;
7273

7374
private enum ErrorCode {
7475
UNKNOWN,
@@ -82,15 +83,29 @@ private enum ErrorCode {
8283
}
8384

8485
@Override
85-
public void initialize(ServiceConfiguration config) throws IOException {
86-
this.metadataStore = createLocalMetadataStore(config);
86+
public void initialize(ServiceConfiguration conf) throws IOException {
87+
initialize(Context.builder().config(conf).build());
88+
}
89+
90+
@Override
91+
public void initialize(Context context) throws IOException {
92+
metrics = new AuthenticationMetrics(
93+
context.getOpenTelemetry(), getClass().getSimpleName(), "mtls");
94+
init(context.getConfig());
95+
}
96+
97+
private void init(ServiceConfiguration conf) throws MetadataStoreException {
98+
this.metadataStore = createLocalMetadataStore(conf);
8799
this.needCloseMetaData = true;
88100
this.metadataStore.registerListener(this::handleMetadataChanges);
89101
this.poolResources = new OIDCPoolResources(metadataStore);
90102
this.loadAsync();
91103
}
92104

93105
public void initialize(MetadataStore metadataStore) {
106+
Context context = Context.builder().build();
107+
this.metrics = new AuthenticationMetrics(
108+
context.getOpenTelemetry(), getClass().getSimpleName(), "mtls");
94109
this.metadataStore = metadataStore;
95110
this.metadataStore.registerListener(this::handleMetadataChanges);
96111
this.poolResources = new OIDCPoolResources(metadataStore);
@@ -219,10 +234,10 @@ public String authenticate(AuthenticationDataSource authData) throws Authenticat
219234
errorCode = ErrorCode.NO_MATCH_POOL;
220235
throw new AuthenticationException("No matched identity pool from the client certificate");
221236
}
222-
AuthenticationMetrics.authenticateSuccess(this.getClass().getSimpleName(), this.getAuthMethodName());
237+
metrics.recordSuccess();
223238
return principal;
224239
} catch (AuthenticationException e) {
225-
this.incrementFailureMetric(errorCode);
240+
metrics.recordFailure(errorCode);
226241
throw e;
227242
}
228243
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<mockito.version>2.22.0</mockito.version>
5050
<testng.version>6.14.3</testng.version>
5151
<awaitility.version>4.0.2</awaitility.version>
52-
<pulsar.version>4.0.0-SNAPSHOT</pulsar.version>
52+
<pulsar.version>4.0.0-ursa-5-SNAPSHOT</pulsar.version>
5353
<mqtt.codec.version>4.1.94.Final</mqtt.codec.version>
5454
<log4j2.version>2.18.0</log4j2.version>
5555
<fusesource.client.version>1.16</fusesource.client.version>

0 commit comments

Comments
 (0)