Skip to content

feat:support push gateway event. #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions polaris-assembly/polaris-assembly-factory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<artifactId>event-tsf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>event-pushgateway</artifactId>
<version>${project.version}</version>
</dependency>

<!--测试依赖插件-->
<dependency>
Expand Down
5 changes: 5 additions & 0 deletions polaris-circuitbreaker/polaris-circuitbreaker-factory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
<artifactId>event-tsf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>event-pushgateway</artifactId>
<version>${project.version}</version>
</dependency>

<!--健康检查插件-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ global:
tsf:
# 描述:TSF 事件上报开关
enable: false
# 描述:PushGateway 事件上报插件配置
pushgateway:
# 描述:PushGateway 事件上报开关
enable: false
# 描述:PushGateway 事件上报队列长度
eventQueueSize: 10000;
# 描述:PushGateway 事件上报最大批量大小
maxBatchSize: 100
# 描述:Admin相关的配置
admin:
# 描述:Admin的监听的IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public interface DefaultPlugins {
*/
String TSF_EVENT_REPORTER_TYPE = "tsf";

/**
* PushGateway 事件上报插件名
*/
String PUSH_GATEWAY_EVENT_REPORTER_TYPE = "pushgateway";

/**
* 黑白名单鉴权插件名
*/
Expand Down
5 changes: 5 additions & 0 deletions polaris-configuration/polaris-configuration-factory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
<artifactId>event-tsf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>event-pushgateway</artifactId>
<version>${project.version}</version>
</dependency>
<!--配置加密插件-->
<dependency>
<groupId>com.tencent.polaris</groupId>
Expand Down
5 changes: 5 additions & 0 deletions polaris-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@
<artifactId>event-tsf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>event-pushgateway</artifactId>
<version>${project.version}</version>
</dependency>
<!-- polaris-plugins-ratelimiter-->
<dependency>
<groupId>com.tencent.polaris</groupId>
Expand Down
5 changes: 5 additions & 0 deletions polaris-discovery/polaris-discovery-factory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@
<artifactId>event-tsf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>event-pushgateway</artifactId>
<version>${project.version}</version>
</dependency>

<!--测试依赖插件-->
<dependency>
Expand Down
6 changes: 6 additions & 0 deletions polaris-distribution/polaris-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<artifactId>bcpkix-jdk15to18</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>${otel.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -180,6 +185,7 @@
<artifactSet>
<excludes>
<exclude>org.bouncycastle:*</exclude>
<exclude>io.opentelemetry:*</exclude>
</excludes>
</artifactSet>
</configuration>
Expand Down
9 changes: 7 additions & 2 deletions polaris-plugins/polaris-plugin-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>polaris-plugins</artifactId>
<groupId>com.tencent.polaris</groupId>
Expand All @@ -16,6 +16,11 @@
<description>Polaris Plugin API JAR</description>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-config</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package com.tencent.polaris.api.plugin.common;

import com.tencent.polaris.logging.LoggerFactory;
import org.slf4j.Logger;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;

/**
* 用于主流程传递kv数据的上下文对象,线程安全
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package com.tencent.polaris.api.plugin.event;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.polaris.api.pojo.ServiceEventKey;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -33,71 +35,92 @@ public class FlowEvent {
/**
* 事件类型
*/
@JsonProperty("event_type")
private final ServiceEventKey.EventType eventType;

/**
* 事件名称
*/
@JsonProperty("event_name")
private final FlowEventConstants.EventName eventName;

/**
* 时间戳
*/
private final Instant timestamp;
@JsonProperty("event_time")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss:SSSS")
private final LocalDateTime timestamp;

/**
* 客户端ID
*/
@JsonProperty("client_id")
private final String clientId;

/**
* 客户端IP
*/
@JsonProperty("client_ip")
private final String clientIp;

/**
* 被调命名空间
*/
@JsonProperty("namespace")
private final String namespace;

/**
* 被调服务名
*/
@JsonProperty("service")
private final String service;

/**
* 接口协议
*/
@JsonProperty("api_protocol")
private final String apiProtocol;

/**
* 接口路径
*/
@JsonProperty("api_path")
private final String apiPath;

/**
* 接口方法
*/
@JsonProperty("api_method")
private final String apiMethod;

/**
* 实例IP
*/
@JsonProperty("host")
private final String host;

/**
* 实例端口
*/
@JsonProperty("port")
private final String port;

/**
* 主调命名空间
*/
@JsonProperty("source_namespace")
private final String sourceNamespace;

/**
* 主调服务名
*/
@JsonProperty("source_service")
private final String sourceService;

/**
* 主调标签
*/
@JsonProperty("labels")
private final String labels;

/**
Expand All @@ -123,12 +146,14 @@ public class FlowEvent {
/**
* 状态转换原因
*/
@JsonProperty("reason")
private final String reason;

private final Map<String, String> additionalParams;

private FlowEvent(Builder builder) {
this.eventType = builder.eventType;
this.eventName = builder.eventName;
this.timestamp = builder.timestamp;
this.clientId = builder.clientId;
this.clientIp = builder.clientIp;
Expand Down Expand Up @@ -156,7 +181,8 @@ private FlowEvent(Builder builder) {

public static class Builder {
private ServiceEventKey.EventType eventType;
private Instant timestamp;
private FlowEventConstants.EventName eventName;
private LocalDateTime timestamp;
private String clientId = "";
private String clientIp = "";
private String namespace = "";
Expand All @@ -180,7 +206,12 @@ public Builder withEventType(ServiceEventKey.EventType eventType) {
return this;
}

public Builder withTimestamp(Instant timestamp) {
public Builder withEventName(FlowEventConstants.EventName eventName) {
this.eventName = eventName;
return this;
}

public Builder withTimestamp(LocalDateTime timestamp) {
this.timestamp = timestamp;
return this;
}
Expand Down Expand Up @@ -279,7 +310,11 @@ public ServiceEventKey.EventType getEventType() {
return eventType;
}

public Instant getTimestamp() {
public FlowEventConstants.EventName getEventName() {
return eventName;
}

public LocalDateTime getTimestamp() {
return timestamp;
}

Expand Down Expand Up @@ -359,6 +394,7 @@ public Map<String, String> getAdditionalParams() {
public String toString() {
return "FlowEvent{" +
"eventType=" + eventType +
", eventName=" + eventName +
", timestamp=" + timestamp +
", clientId='" + clientId + '\'' +
", clientIp='" + clientIp + '\'' +
Expand All @@ -368,7 +404,7 @@ public String toString() {
", apiPath='" + apiPath + '\'' +
", apiMethod='" + apiMethod + '\'' +
", host='" + host + '\'' +
", port=" + port +
", port='" + port + '\'' +
", sourceNamespace='" + sourceNamespace + '\'' +
", sourceService='" + sourceService + '\'' +
", labels='" + labels + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
*/
public class FlowEventConstants {

public enum EventName {
LosslessOnlineStart,
LosslessOnlineEnd,
LosslessWarmupStart,
LosslessWarmupEnd,
LosslessOfflineStart,

InstanceThreadEnd,

CircuitBreakerOpen,
CircuitBreakerHalfOpen,
CircuitBreakerClose,
CircuitBreakerDestroy,

RateLimitStart,
RateLimitEnd,

UNKNOWN,
}

public enum Status {
// circuit breaker status
OPEN,
Expand All @@ -47,5 +67,4 @@ public enum ResourceType {

UNKNOWN,
}

}
Loading