Skip to content
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

[Feature][Connector-V2] Add sentry sink connector #2244 #2584

Merged
merged 4 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
53 changes: 53 additions & 0 deletions docs/en/connector-v2/sink/Sentry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Sentry

## Description

Write message to Sentry.

## Options

| name | type | required | default value |
|----------------------------|---------|----------| ------------- |
| dsn | string | yes | - |
| env | string | no | - |
| release | string | no | - |
| cacheDirPath | string | no | - |
| enableExternalConfiguration | boolean | no | - |
| maxCacheItems | number | no | - |
| flushTimeoutMills | number | no | - |
| maxQueueSize | number | no | - |
### dsn [string]

The DSN tells the SDK where to send the events to.

### env [string]
specify the environment

### release [string]
specify the release

### cacheDirPath [string]
the cache dir path for caching offline events

### enableExternalConfiguration [boolean]
if loading properties from external sources is enabled.

### maxCacheItems [number]
The max cache items for capping the number of events Default is 30

### flushTimeoutMillis [number]
Controls how many seconds to wait before flushing down. Sentry SDKs cache events from a background queue and this queue is given a certain amount to drain pending events Default is 15000 = 15s

### maxQueueSize [number]
Max queue size before flushing events/envelopes to the disk

## Example
```
Sentry {
dsn = "https://xxx@sentry.xxx.com:9999/6"
enableExternalConfiguration = true
maxCacheItems = 1000
env = prod
}

```
2 changes: 1 addition & 1 deletion plugin-mapping.properties
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ seatunnel.sink.Neo4j = connector-neo4j
seatunnel.sink.FtpFile = connector-file-ftp
seatunnel.sink.Socket = connector-socket
seatunnel.sink.DataHub = connector-datahub

seatunnel.sink.Sentry = connector-sentry
5 changes: 5 additions & 0 deletions seatunnel-connectors-v2-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
<artifactId>connector-datahub</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-sentry</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
58 changes: 58 additions & 0 deletions seatunnel-connectors-v2/connector-sentry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<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">
<parent>
<artifactId>seatunnel-connectors-v2</artifactId>
<groupId>org.apache.seatunnel</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>connector-sentry</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.apache.commons</groupId>-->
<!-- <artifactId>commons-lang3</artifactId>-->
<!-- </dependency>-->

Saintyang marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>5.0.1</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We manage dependencies uniformly in the root pom (dependency managernt)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-common</artifactId>
<version>2.1.3-SNAPSHOT</version>
<scope>compile</scope>
Saintyang marked this conversation as resolved.
Show resolved Hide resolved
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.sentry.sink;

public class SentryConfig {

public static final String SENTRY = "sentry";
public static final String DSN = "dsn";
public static final String ENV = "env";
public static final String RELEASE = "release";
public static final String CACHE_DIRPATH = "cacheDirPath";
public static final String ENABLE_EXTERNAL_CONFIGURATION = "enableExternalConfiguration";
public static final String MAX_CACHEITEMS = "maxCacheItems";
public static final String FLUSH_TIMEOUTMILLIS = "flushTimeoutMillis";
public static final String MAX_QUEUESIZE = "maxQueueSize";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.sentry.sink;

import org.apache.seatunnel.api.common.PrepareFailException;
import org.apache.seatunnel.api.sink.SeaTunnelSink;
import org.apache.seatunnel.api.sink.SinkWriter.Context;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.constants.PluginType;
import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;

import org.apache.seatunnel.shade.com.typesafe.config.Config;

import com.google.auto.service.AutoService;

import java.io.IOException;

/**
* @description: SentrySink class
*/
@AutoService(SeaTunnelSink.class)
public class SentrySink extends AbstractSimpleSink<SeaTunnelRow, SentrySinkState> {

private SeaTunnelRowType seaTunnelRowType;
private Config pluginConfig;
@Override
public String getPluginName() {
return SentryConfig.SENTRY;
}

@Override
public void prepare(Config pluginConfig) throws PrepareFailException {
if (!pluginConfig.hasPath(SentryConfig.DSN)) {
throw new PrepareFailException(getPluginName(), PluginType.SINK,
String.format("Config must include column : %s", SentryConfig.DSN));
}

this.pluginConfig = pluginConfig;
}

@Override
public void setTypeInfo(SeaTunnelRowType seaTunnelRowType) {
this.seaTunnelRowType = seaTunnelRowType;
}

@Override
public SeaTunnelDataType<SeaTunnelRow> getConsumedType() {
return this.seaTunnelRowType;
}

@Override
public AbstractSinkWriter<SeaTunnelRow, SentrySinkState> createWriter(Context context) throws IOException {
return new SentrySinkWriter(seaTunnelRowType, context, pluginConfig);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.sentry.sink;

import java.io.Serializable;

public class SentrySinkState implements Serializable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.sentry.sink;

import org.apache.seatunnel.api.sink.SinkWriter;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;

import org.apache.seatunnel.shade.com.typesafe.config.Config;

import io.sentry.Sentry;
import io.sentry.SentryOptions;

import java.io.IOException;

/**
* @description: SentrySinkWriter class
*/

public class SentrySinkWriter extends AbstractSinkWriter<SeaTunnelRow, SentrySinkState> {
private SeaTunnelRowType seaTunnelRowType;
public SentrySinkWriter(SeaTunnelRowType seaTunnelRowType,
SinkWriter.Context context,
Config pluginConfig) {
SentryOptions options = new SentryOptions();
options.setDsn(pluginConfig.getString(SentryConfig.DSN));
if (pluginConfig.hasPath(SentryConfig.ENV)){
options.setEnvironment(pluginConfig.getString(SentryConfig.ENV));
}
if (pluginConfig.hasPath(SentryConfig.RELEASE)){
options.setRelease(pluginConfig.getString(SentryConfig.RELEASE));
}
if (pluginConfig.hasPath(SentryConfig.CACHE_DIRPATH)){
options.setCacheDirPath(pluginConfig.getString(SentryConfig.CACHE_DIRPATH));
}
if (pluginConfig.hasPath(SentryConfig.MAX_CACHEITEMS)){
options.setMaxCacheItems(pluginConfig.getInt(SentryConfig.MAX_CACHEITEMS));
}
if (pluginConfig.hasPath(SentryConfig.MAX_QUEUESIZE)){
options.setMaxQueueSize(pluginConfig.getInt(SentryConfig.MAX_QUEUESIZE));
}
if (pluginConfig.hasPath(SentryConfig.FLUSH_TIMEOUTMILLIS)){
options.setFlushTimeoutMillis(pluginConfig.getLong(SentryConfig.FLUSH_TIMEOUTMILLIS));
}
if (pluginConfig.hasPath(SentryConfig.ENABLE_EXTERNAL_CONFIGURATION)){
options.setEnableExternalConfiguration(pluginConfig.getBoolean(SentryConfig.ENABLE_EXTERNAL_CONFIGURATION));
}
Sentry.init(options);
}

@Override
public void write(SeaTunnelRow element) throws IOException {
Sentry.captureMessage(element.toString());
CalvinKirs marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void close() throws IOException {
Sentry.close();
}

}
1 change: 1 addition & 0 deletions seatunnel-connectors-v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<module>connector-iotdb</module>
<module>connector-neo4j</module>
<module>connector-datahub</module>
<module>connector-sentry</module>
</modules>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@
<version>${project.version}</version>
</dependency>
<!-- seatunnel connectors -->

<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-sentry</artifactId>
<version>${project.version}</version>
</dependency>
<!--flink-->
<dependency>
<groupId>org.apache.flink</groupId>
Expand Down
Loading