Skip to content

Commit 0038828

Browse files
athakorchingor13
andauthored
feat: expose log exclusion apis (#162)
* feat: expose log exclusion apis * feat: update copyright and java docs * feat: update java docs * feat: update method names and javadoc * deps: fix build Co-authored-by: Jeff Ching <[email protected]>
1 parent 91c9344 commit 0038828

File tree

9 files changed

+1319
-2
lines changed

9 files changed

+1319
-2
lines changed

google-cloud-logging/clirr-ignored-differences.xml

+76-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,79 @@
2020
<method>* listLogs(com.google.logging.v2.ParentName)</method>
2121
<to>* listLogs(com.google.logging.v2.ProjectName)</to>
2222
</difference>
23-
</differences>
23+
<difference>
24+
<className>com/google/cloud/logging/Logging</className>
25+
<method>com.google.cloud.logging.Exclusion create(com.google.cloud.logging.Exclusion)</method>
26+
<differenceType>7012</differenceType>
27+
</difference>
28+
<difference>
29+
<className>com/google/cloud/logging/Logging</className>
30+
<method>com.google.api.core.ApiFuture createAsync(com.google.cloud.logging.Exclusion)</method>
31+
<differenceType>7012</differenceType>
32+
</difference>
33+
<difference>
34+
<className>com/google/cloud/logging/Logging</className>
35+
<method>boolean deleteExclusion(java.lang.String)</method>
36+
<differenceType>7012</differenceType>
37+
</difference>
38+
<difference>
39+
<className>com/google/cloud/logging/Logging</className>
40+
<method>com.google.api.core.ApiFuture deleteExclusionAsync(java.lang.String)</method>
41+
<differenceType>7012</differenceType>
42+
</difference>
43+
<difference>
44+
<className>com/google/cloud/logging/Logging</className>
45+
<method>com.google.cloud.logging.Exclusion getExclusion(java.lang.String)</method>
46+
<differenceType>7012</differenceType>
47+
</difference>
48+
<difference>
49+
<className>com/google/cloud/logging/Logging</className>
50+
<method>com.google.api.core.ApiFuture getExclusionAsync(java.lang.String)</method>
51+
<differenceType>7012</differenceType>
52+
</difference>
53+
<difference>
54+
<className>com/google/cloud/logging/Logging</className>
55+
<method>com.google.api.gax.paging.Page listExclusions(com.google.cloud.logging.Logging$ListOption[])</method>
56+
<differenceType>7012</differenceType>
57+
</difference>
58+
<difference>
59+
<className>com/google/cloud/logging/Logging</className>
60+
<method>com.google.api.core.ApiFuture listExclusionsAsync(com.google.cloud.logging.Logging$ListOption[])</method>
61+
<differenceType>7012</differenceType>
62+
</difference>
63+
<difference>
64+
<className>com/google/cloud/logging/Logging</className>
65+
<method>com.google.cloud.logging.Exclusion update(com.google.cloud.logging.Exclusion)</method>
66+
<differenceType>7012</differenceType>
67+
</difference>
68+
<difference>
69+
<className>com/google/cloud/logging/Logging</className>
70+
<method>com.google.api.core.ApiFuture updateAsync(com.google.cloud.logging.Exclusion)</method>
71+
<differenceType>7012</differenceType>
72+
</difference>
73+
<difference>
74+
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
75+
<method>com.google.api.core.ApiFuture create(com.google.logging.v2.CreateExclusionRequest)</method>
76+
<differenceType>7012</differenceType>
77+
</difference>
78+
<difference>
79+
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
80+
<method>com.google.api.core.ApiFuture delete(com.google.logging.v2.DeleteExclusionRequest)</method>
81+
<differenceType>7012</differenceType>
82+
</difference>
83+
<difference>
84+
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
85+
<method>com.google.api.core.ApiFuture get(com.google.logging.v2.GetExclusionRequest)</method>
86+
<differenceType>7012</differenceType>
87+
</difference>
88+
<difference>
89+
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
90+
<method>com.google.api.core.ApiFuture list(com.google.logging.v2.ListExclusionsRequest)</method>
91+
<differenceType>7012</differenceType>
92+
</difference>
93+
<difference>
94+
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
95+
<method>com.google.api.core.ApiFuture update(com.google.logging.v2.UpdateExclusionRequest)</method>
96+
<differenceType>7012</differenceType>
97+
</difference>
98+
</differences>

google-cloud-logging/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
<groupId>com.google.protobuf</groupId>
4242
<artifactId>protobuf-java</artifactId>
4343
</dependency>
44+
<dependency>
45+
<groupId>com.google.protobuf</groupId>
46+
<artifactId>protobuf-java-util</artifactId>
47+
</dependency>
4448
<dependency>
4549
<groupId>com.google.api.grpc</groupId>
4650
<artifactId>proto-google-common-protos</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.logging;
17+
18+
import static com.google.common.base.Preconditions.checkNotNull;
19+
20+
import com.google.common.base.Function;
21+
import com.google.common.base.MoreObjects;
22+
import com.google.logging.v2.LogExclusion;
23+
import com.google.protobuf.Timestamp;
24+
import java.util.Objects;
25+
26+
/**
27+
* Specifies a set of log entries that are not to be stored in Logging. If your GCP resource
28+
* receives a large volume of logs, you can use exclusions to reduce your chargeable logs.
29+
* Exclusions are processed after log sinks, so you can export log entries before they are excluded.
30+
* Note that organization-level and folder-level exclusions don't apply to child resources, and that
31+
* you can't exclude audit log entries.
32+
*/
33+
public class Exclusion {
34+
35+
static final Function<LogExclusion, Exclusion> FROM_PROTOBUF_FUNCTION =
36+
new Function<LogExclusion, Exclusion>() {
37+
@Override
38+
public Exclusion apply(LogExclusion exclusionPb) {
39+
return exclusionPb != null ? Exclusion.fromProtobuf(exclusionPb) : null;
40+
}
41+
};
42+
43+
static final Function<Exclusion, LogExclusion> TO_PROTOBUF_FUNCTION =
44+
new Function<Exclusion, LogExclusion>() {
45+
@Override
46+
public LogExclusion apply(Exclusion exclusion) {
47+
return exclusion != null ? exclusion.toProtobuf() : null;
48+
}
49+
};
50+
51+
private String name;
52+
private String description;
53+
private String filter;
54+
private boolean disabled;
55+
private Timestamp createTime;
56+
private Timestamp updateTime;
57+
58+
/** A builder for {@code Exclusion} objects. */
59+
public static class Builder {
60+
61+
private String name;
62+
private String description;
63+
private String filter;
64+
private boolean disabled;
65+
private Timestamp createTime;
66+
private Timestamp updateTime;
67+
68+
private Builder(String name, String filter) {
69+
this.name = checkNotNull(name);
70+
this.filter = checkNotNull(filter);
71+
}
72+
73+
private Builder(Exclusion exclusion) {
74+
this.name = exclusion.name;
75+
this.description = exclusion.description;
76+
this.filter = exclusion.filter;
77+
this.disabled = exclusion.disabled;
78+
this.createTime = exclusion.createTime;
79+
this.updateTime = exclusion.updateTime;
80+
}
81+
82+
/**
83+
* [Required] A client-assigned identifier, such as "load-balancer-exclusion". Identifiers are
84+
* limited to 100 characters and can include only letters, digits, underscores, hyphens, and
85+
* periods. First character has to be alphanumeric.
86+
*/
87+
public Builder setName(String name) {
88+
this.name = checkNotNull(name);
89+
return this;
90+
}
91+
92+
/** [Optional] A description of this exclusion. */
93+
public Builder setDescription(String description) {
94+
this.description = description;
95+
return this;
96+
}
97+
98+
/**
99+
* [Required] An advanced logs filter that matches the log entries to be excluded. By using the
100+
* sample function, you can exclude less than 100% of the matching log entries.
101+
*/
102+
public Builder setFilter(String filter) {
103+
this.filter = checkNotNull(filter);
104+
return this;
105+
}
106+
107+
/**
108+
* [Optional] If set to True, then this exclusion is disabled and it does not exclude any log
109+
* entries.
110+
*/
111+
public Builder setDisabled(boolean disabled) {
112+
this.disabled = disabled;
113+
return this;
114+
}
115+
116+
/** [Output only] The creation timestamp of the exclusion. */
117+
public Builder setCreateTime(Timestamp createTime) {
118+
this.createTime = createTime;
119+
return this;
120+
}
121+
122+
/** [Output only] The last update timestamp of the exclusion. */
123+
public Builder setUpdateTime(Timestamp updateTime) {
124+
this.updateTime = updateTime;
125+
return this;
126+
}
127+
128+
/** Creates a {@code Exclusion} object. */
129+
public Exclusion build() {
130+
return new Exclusion(this);
131+
}
132+
}
133+
134+
Exclusion(Builder builder) {
135+
this.name = checkNotNull(builder.name);
136+
this.description = builder.description;
137+
this.filter = checkNotNull(builder.filter);
138+
this.disabled = builder.disabled;
139+
this.createTime = builder.createTime;
140+
this.updateTime = builder.updateTime;
141+
}
142+
143+
@Override
144+
public String toString() {
145+
return MoreObjects.toStringHelper(this)
146+
.add("name", name)
147+
.add("description", description)
148+
.add("filter", filter)
149+
.add("disabled", disabled)
150+
.add("createTime", createTime)
151+
.add("updateTime", updateTime)
152+
.toString();
153+
}
154+
155+
@Override
156+
public boolean equals(Object o) {
157+
if (this == o) {
158+
return true;
159+
}
160+
if (o == null || getClass() != o.getClass()) {
161+
return false;
162+
}
163+
Exclusion exclusion = (Exclusion) o;
164+
return disabled == exclusion.disabled
165+
&& Objects.equals(name, exclusion.name)
166+
&& Objects.equals(description, exclusion.description)
167+
&& Objects.equals(filter, exclusion.filter)
168+
&& Objects.equals(createTime, exclusion.createTime)
169+
&& Objects.equals(updateTime, exclusion.updateTime);
170+
}
171+
172+
@Override
173+
public int hashCode() {
174+
return Objects.hash(name, description, filter, disabled, createTime, updateTime);
175+
}
176+
177+
/** Returns the name of log exclusion. */
178+
public String getName() {
179+
return name;
180+
}
181+
182+
/** Returns an optional description of an exclusion. Used for documentation purpose. */
183+
public String getDescription() {
184+
return description;
185+
}
186+
187+
/**
188+
* Returns an advanced logs filter. Example: {@code resource.type=gcs_bucket severity<ERROR
189+
* sample(insertId, 0.99)}.
190+
*
191+
* @see <a href="https://cloud.google.com/logging/docs/view/advanced-queries">Advanced Log
192+
* Filters</a>
193+
*/
194+
public String getFilter() {
195+
return filter;
196+
}
197+
198+
/** If set to True, then this exclusion is disabled and it does not exclude any log entries. */
199+
public boolean isDisabled() {
200+
return disabled;
201+
}
202+
203+
/** Returns the creation timestamp of the exclusion. */
204+
public Timestamp getCreateTime() {
205+
return createTime;
206+
}
207+
208+
/** Returns the last update timestamp of the exclusion. */
209+
public Timestamp getUpdateTime() {
210+
return updateTime;
211+
}
212+
213+
/** Returns a builder for this {@code Exclusion} object. */
214+
public Builder toBuilder() {
215+
return new Builder(this);
216+
}
217+
218+
/**
219+
* Returns a builder for {@code Exclusion} objects given the name of the exclusion and its filter.
220+
*/
221+
public static Builder newBuilder(String name, String filter) {
222+
return new Builder(name, filter);
223+
}
224+
225+
/** Creates a {@code Exclusion} object given the name of the exclusion and its filter. */
226+
public static Exclusion of(String name, String filter) {
227+
return new Builder(name, filter).build();
228+
}
229+
230+
LogExclusion toProtobuf() {
231+
LogExclusion.Builder builder =
232+
LogExclusion.newBuilder().setName(name).setFilter(filter).setDisabled(disabled);
233+
if (description != null) {
234+
builder.setDescription(description);
235+
}
236+
if (createTime != null) {
237+
builder.setCreateTime(createTime);
238+
}
239+
if (updateTime != null) {
240+
builder.setUpdateTime(updateTime);
241+
}
242+
return builder.build();
243+
}
244+
245+
static Exclusion fromProtobuf(LogExclusion exclusionPb) {
246+
Exclusion.Builder builder = newBuilder(exclusionPb.getName(), exclusionPb.getFilter());
247+
builder.setDisabled(exclusionPb.getDisabled());
248+
if (!exclusionPb.getDescription().equals("")) {
249+
builder.setDescription(exclusionPb.getDescription());
250+
}
251+
if (exclusionPb.hasCreateTime()) {
252+
builder.setCreateTime(exclusionPb.getCreateTime());
253+
}
254+
if (exclusionPb.hasUpdateTime()) {
255+
builder.setUpdateTime(exclusionPb.getUpdateTime());
256+
}
257+
return builder.build();
258+
}
259+
}

0 commit comments

Comments
 (0)