Skip to content

Commit 71f5cfd

Browse files
committed
Add comment fields to UI for auditing
1 parent 95fd8bf commit 71f5cfd

File tree

13 files changed

+394
-47
lines changed

13 files changed

+394
-47
lines changed

docs/operation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Existing cluster information can also be modified using the edit button.
1616

1717
![trino.gateway.io/entity](./assets/trinogateway_cluster_page.png)
1818

19+
**Note:** When adding or modifying a backend through the UI, a comment is required. Please provide a meaningful comment describing the reason for the change.
1920

2021
## Graceful shutdown
2122

gateway-ha/src/main/java/io/trino/gateway/ha/AuditAction.java renamed to gateway-ha/src/main/java/io/trino/gateway/ha/audit/AuditAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package io.trino.gateway.ha;
14+
package io.trino.gateway.ha.audit;
1515

1616
public enum AuditAction {
1717
CREATE,
1818
UPDATE,
1919
DELETE,
2020
ACTIVATE,
21-
DEACTIVATE
21+
DEACTIVATE,
22+
UNKNOWN
2223
}

gateway-ha/src/main/java/io/trino/gateway/ha/AuditContext.java renamed to gateway-ha/src/main/java/io/trino/gateway/ha/audit/AuditContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package io.trino.gateway.ha;
14+
package io.trino.gateway.ha.audit;
1515

1616
public enum AuditContext {
1717
TRINO_GW_UI,
18-
TRINO_GW_API,
18+
TRINO_GW_API
1919
}

gateway-ha/src/main/java/io/trino/gateway/ha/AuditLogger.java renamed to gateway-ha/src/main/java/io/trino/gateway/ha/audit/AuditLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package io.trino.gateway.ha;
14+
package io.trino.gateway.ha.audit;
1515

1616
import static java.util.Objects.requireNonNullElse;
1717

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.gateway.ha.audit;
15+
16+
import com.google.inject.Inject;
17+
import io.airlift.log.Logger;
18+
19+
import java.util.Collections;
20+
import java.util.Set;
21+
22+
import static java.util.Objects.requireNonNullElse;
23+
24+
public class CompositeAuditLogger
25+
implements AuditLogger
26+
{
27+
private static final Logger log = Logger.get(CompositeAuditLogger.class);
28+
private final Set<AuditLogger> loggers;
29+
30+
@Inject
31+
public CompositeAuditLogger(Set<AuditLogger> loggers)
32+
{
33+
this.loggers = requireNonNullElse(loggers, Collections.emptySet());
34+
}
35+
36+
@Override
37+
public void logAudit(String user, String ip, String backend, AuditAction action, AuditContext context, boolean success, String userComment)
38+
{
39+
String sanitizedComment = AuditLogger.sanitizeComment(userComment);
40+
for (AuditLogger logger : loggers) {
41+
try {
42+
logger.logAudit(user, ip, backend, action, context, success, sanitizedComment);
43+
}
44+
catch (Exception e) {
45+
log.error(e, "Audit sink %s failed", logger.getClass().getSimpleName());
46+
}
47+
}
48+
}
49+
}

gateway-ha/src/main/java/io/trino/gateway/ha/DatabaseAuditLogger.java renamed to gateway-ha/src/main/java/io/trino/gateway/ha/audit/DatabaseAuditLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package io.trino.gateway.ha;
14+
package io.trino.gateway.ha.audit;
1515

1616
import io.airlift.log.Logger;
1717
import io.trino.gateway.ha.persistence.dao.AuditLogDao;

gateway-ha/src/main/java/io/trino/gateway/ha/LogAuditLogger.java renamed to gateway-ha/src/main/java/io/trino/gateway/ha/audit/LogAuditLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package io.trino.gateway.ha;
14+
package io.trino.gateway.ha.audit;
1515

1616
import io.airlift.log.Logger;
1717

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.gateway.ha.config;
15+
16+
import com.fasterxml.jackson.annotation.JsonProperty;
17+
import com.fasterxml.jackson.annotation.JsonSetter;
18+
import io.trino.gateway.ha.audit.AuditAction;
19+
import io.trino.gateway.ha.audit.AuditContext;
20+
21+
public class AdminProxyBackendConfiguration
22+
{
23+
private final ProxyBackendConfiguration proxyBackendConfiguration = new ProxyBackendConfiguration();
24+
private AuditAction action;
25+
private String comment = "";
26+
private AuditContext context;
27+
28+
@JsonProperty
29+
public String getName()
30+
{
31+
return proxyBackendConfiguration.getName();
32+
}
33+
34+
@JsonSetter
35+
public void setName(String name)
36+
{
37+
proxyBackendConfiguration.setName(name);
38+
}
39+
40+
@JsonProperty
41+
public String getProxyTo()
42+
{
43+
return proxyBackendConfiguration.getProxyTo();
44+
}
45+
46+
@JsonSetter
47+
public void setProxyTo(String proxyTo)
48+
{
49+
proxyBackendConfiguration.setProxyTo(proxyTo);
50+
}
51+
52+
@JsonProperty
53+
public String getExternalUrl()
54+
{
55+
return proxyBackendConfiguration.getExternalUrl();
56+
}
57+
58+
@JsonSetter
59+
public void setExternalUrl(String externalUrl)
60+
{
61+
proxyBackendConfiguration.setExternalUrl(externalUrl);
62+
}
63+
64+
@JsonProperty
65+
public boolean isActive()
66+
{
67+
return proxyBackendConfiguration.isActive();
68+
}
69+
70+
@JsonSetter
71+
public void setActive(boolean active)
72+
{
73+
proxyBackendConfiguration.setActive(active);
74+
}
75+
76+
@JsonProperty
77+
public String getRoutingGroup()
78+
{
79+
return proxyBackendConfiguration.getRoutingGroup();
80+
}
81+
82+
@JsonSetter
83+
public void setRoutingGroup(String routingGroup)
84+
{
85+
proxyBackendConfiguration.setRoutingGroup(routingGroup);
86+
}
87+
88+
@JsonProperty
89+
public AuditAction getAction()
90+
{
91+
return this.action;
92+
}
93+
94+
@JsonSetter
95+
public void setAction(AuditAction action)
96+
{
97+
this.action = action;
98+
}
99+
100+
@JsonProperty
101+
public String getComment()
102+
{
103+
return this.comment;
104+
}
105+
106+
@JsonSetter
107+
public void setComment(String comment)
108+
{
109+
this.comment = comment;
110+
}
111+
112+
@JsonProperty
113+
public AuditContext getContext()
114+
{
115+
return this.context;
116+
}
117+
118+
@JsonSetter
119+
public void setContext(AuditContext context)
120+
{
121+
this.context = context;
122+
}
123+
124+
public ProxyBackendConfiguration getProxyBackendConfiguration()
125+
{
126+
return proxyBackendConfiguration;
127+
}
128+
}

gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import com.google.inject.Scopes;
2020
import com.google.inject.Singleton;
2121
import io.airlift.http.client.HttpClient;
22-
import io.trino.gateway.ha.DatabaseAuditLogger;
22+
import io.trino.gateway.ha.audit.AuditLogger;
23+
import io.trino.gateway.ha.audit.CompositeAuditLogger;
24+
import io.trino.gateway.ha.audit.DatabaseAuditLogger;
25+
import io.trino.gateway.ha.audit.LogAuditLogger;
2326
import io.trino.gateway.ha.clustermonitor.ClusterStatsHttpMonitor;
2427
import io.trino.gateway.ha.clustermonitor.ClusterStatsInfoApiMonitor;
2528
import io.trino.gateway.ha.clustermonitor.ClusterStatsJdbcMonitor;
@@ -73,6 +76,7 @@
7376

7477
import java.util.List;
7578
import java.util.Map;
79+
import java.util.Set;
7680

7781
import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder;
7882
import static io.trino.gateway.ha.config.ClusterStatsMonitorType.INFO_API;
@@ -91,7 +95,7 @@ public class HaGatewayProviderModule
9195
private final GatewayBackendManager gatewayBackendManager;
9296
private final QueryHistoryManager queryHistoryManager;
9397
private final PathFilter pathFilter;
94-
private final DatabaseAuditLogger dbAuditLogger;
98+
private final CompositeAuditLogger compositeAuditLogger;
9599

96100
@Override
97101
protected void configure()
@@ -102,7 +106,7 @@ protected void configure()
102106
binder().bind(QueryHistoryManager.class).toInstance(queryHistoryManager);
103107
binder().bind(BackendStateManager.class).in(Scopes.SINGLETON);
104108
binder().bind(PathFilter.class).toInstance(pathFilter);
105-
binder().bind(DatabaseAuditLogger.class).toInstance(dbAuditLogger);
109+
binder().bind(AuditLogger.class).toInstance(compositeAuditLogger);
106110
}
107111

108112
public HaGatewayProviderModule(HaGatewayConfiguration configuration)
@@ -128,7 +132,10 @@ public HaGatewayProviderModule(HaGatewayConfiguration configuration)
128132
resourceGroupsManager = new HaResourceGroupsManager(connectionManager);
129133
gatewayBackendManager = new HaGatewayManager(jdbi, configuration.getRouting());
130134
queryHistoryManager = new HaQueryHistoryManager(jdbi, configuration.getDataStore().getJdbcUrl().startsWith("jdbc:oracle"));
131-
dbAuditLogger = new DatabaseAuditLogger(jdbi);
135+
136+
LogAuditLogger logAuditLogger = new LogAuditLogger();
137+
DatabaseAuditLogger dbAuditLogger = new DatabaseAuditLogger(jdbi);
138+
compositeAuditLogger = new CompositeAuditLogger(Set.of(logAuditLogger, dbAuditLogger));
132139
}
133140

134141
private LbOAuthManager getOAuthManager(HaGatewayConfiguration configuration)

0 commit comments

Comments
 (0)