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

Add probe (tracepoint or logpoint) tagging capability #37

Merged
merged 18 commits into from Nov 1, 2022
Merged
8 changes: 6 additions & 2 deletions .github/workflows/release-internal-repo.yml
Expand Up @@ -61,8 +61,12 @@ jobs:
"password": "${{ secrets.SIDEKICK_INTERNAL_REPO_PASSWORD }}"
}
]

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.SIDEKICK_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.SIDEKICK_GPG_PASSPHRASE}}
- name: Build and Release Snapshot with Maven
env:
GITHUB_TOKEN: ${{ secrets.SIDEKICK_DEVOPS_GITHUB_ACCESS_TOKEN }}
run: mvn -q clean install deploy --batch-mode -P release
run: mvn -f sidekick -DskipTests=true -q clean package release:clean release:prepare release:perform release:clean --batch-mode -P internal-release
20 changes: 14 additions & 6 deletions docker/scripts/schema.sql
Expand Up @@ -41,16 +41,16 @@ CREATE TABLE TracePoint
application_filters JSON,
webhook_ids JSON,
from_api BOOLEAN NOT NULL DEFAULT 0,
predefined BOOLEAN NOT NULL DEFAULT 0,
probe_name VARCHAR(255)
probe_name VARCHAR(255),
tags JSON
);

CREATE EVENT IF NOT EXISTS clean_expired_tracepoints
ON SCHEDULE EVERY 5 MINUTE
DO
DELETE
FROM TracePoint
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND predefined = 0;
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND (JSON_TYPE(tags) = 'NULL' OR JSON_LENGTH(tags) = 0);

CREATE TABLE LogPoint
(
Expand All @@ -72,16 +72,16 @@ CREATE TABLE LogPoint
log_level VARCHAR(1024),
webhook_ids JSON,
from_api BOOLEAN NOT NULL DEFAULT 0,
predefined BOOLEAN NOT NULL DEFAULT 0,
probe_name VARCHAR(255)
probe_name VARCHAR(255),
tags JSON
);

CREATE EVENT IF NOT EXISTS clean_expired_logpoints
ON SCHEDULE EVERY 5 MINUTE
DO
DELETE
FROM LogPoint
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND predefined = 0;
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND (JSON_TYPE(tags) = 'NULL' OR JSON_LENGTH(tags) = 0);

CREATE TABLE Webhook
(
Expand Down Expand Up @@ -113,4 +113,12 @@ CREATE TABLE ServerStatistics (
application_instance_count INT(10) DEFAULT 0,
tracepoint_count INT(10) DEFAULT 0,
logpoint_count INT(10) DEFAULT 0
);

CREATE TABLE ProbeTag (
id VARCHAR(64) NOT NULL PRIMARY KEY,
workspace_id VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
disabled BOOLEAN NOT NULL DEFAULT 0,
CONSTRAINT probe_tag UNIQUE (workspace_id, tag)
);
1 change: 1 addition & 0 deletions mysql/clear-tables.sql
Expand Up @@ -3,6 +3,7 @@ SET FOREIGN_KEY_CHECKS = 0;
-- ## --
DELETE FROM Application;
DELETE FROM LogPoint;
DELETE FROM ProbeTag;
DELETE FROM ReferenceEvent;
DELETE FROM ServerStatistics;
DELETE FROM TracePoint;
Expand Down
20 changes: 14 additions & 6 deletions mysql/create-tables.sql
Expand Up @@ -41,16 +41,16 @@ CREATE TABLE TracePoint
application_filters JSON,
webhook_ids JSON,
from_api BOOLEAN NOT NULL DEFAULT 0,
predefined BOOLEAN NOT NULL DEFAULT 0,
probe_name VARCHAR(255)
probe_name VARCHAR(255),
tags JSON
);

CREATE EVENT IF NOT EXISTS clean_expired_tracepoints
ON SCHEDULE EVERY 5 MINUTE
DO
DELETE
FROM TracePoint
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND predefined = 0;
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND (JSON_TYPE(tags) = 'NULL' OR JSON_LENGTH(tags) = 0);

CREATE TABLE LogPoint
(
Expand All @@ -72,16 +72,16 @@ CREATE TABLE LogPoint
log_level VARCHAR(1024),
webhook_ids JSON,
from_api BOOLEAN NOT NULL DEFAULT 0,
predefined BOOLEAN NOT NULL DEFAULT 0,
probe_name VARCHAR(255)
probe_name VARCHAR(255),
tags JSON
);

CREATE EVENT IF NOT EXISTS clean_expired_logpoints
ON SCHEDULE EVERY 5 MINUTE
DO
DELETE
FROM LogPoint
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND predefined = 0;
WHERE expire_timestamp < UNIX_TIMESTAMP() * 1000 AND (JSON_TYPE(tags) = 'NULL' OR JSON_LENGTH(tags) = 0);

CREATE TABLE Webhook
(
Expand Down Expand Up @@ -113,4 +113,12 @@ CREATE TABLE ServerStatistics (
application_instance_count INT(10) DEFAULT 0,
tracepoint_count INT(10) DEFAULT 0,
logpoint_count INT(10) DEFAULT 0
);

CREATE TABLE ProbeTag (
id VARCHAR(64) NOT NULL PRIMARY KEY,
workspace_id VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
disabled BOOLEAN NOT NULL DEFAULT 0,
CONSTRAINT probe_tag UNIQUE (workspace_id, tag)
);
1 change: 1 addition & 0 deletions mysql/drop-tables.sql
Expand Up @@ -3,6 +3,7 @@ SET FOREIGN_KEY_CHECKS = 0;
-- ## --
DROP TABLE IF EXISTS Application;
DROP TABLE IF EXISTS LogPoint;
DROP TABLE IF EXISTS ProbeTag;
DROP TABLE IF EXISTS ReferenceEvent;
DROP TABLE IF EXISTS ServerStatistics;
DROP TABLE IF EXISTS TracePoint;
Expand Down
1 change: 1 addition & 0 deletions mysql/truncate-tables.sql
Expand Up @@ -3,6 +3,7 @@ SET FOREIGN_KEY_CHECKS = 0;
-- ## --
TRUNCATE TABLE Application;
TRUNCATE TABLE LogPoint;
TRUNCATE TABLE ProbeTag;
TRUNCATE TABLE ReferenceEvent;
TRUNCATE TABLE ServerStatistics;
TRUNCATE TABLE TracePoint;
Expand Down
45 changes: 45 additions & 0 deletions sidekick/pom.xml
Expand Up @@ -83,6 +83,7 @@
<module>sidekick-webhook</module>
<module>sidekick-api</module>
<module>sidekick-phone-home</module>
<module>sidekick-probetag</module>
<module>sidekick-statistics</module>
</modules>

Expand Down Expand Up @@ -159,6 +160,22 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-probetag-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-probetag-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-probetag-repository</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-webhook-model</artifactId>
Expand Down Expand Up @@ -494,6 +511,34 @@
</plugins>
</build>
</profile>
<profile>
<id>internal-release</id>
<distributionManagement>
<repository>
<id>sidekick-oss-releases</id>
<name>Sidekick OSS Releases</name>
<url>https://repo.thundra.io/content/repositories/sidekick-oss-releases/</url>
</repository>
<snapshotRepository>
<id>sidekick-oss-snapshots</id>
<name>Sidekick OSS Snapshots</name>
<url>https://repo.thundra.io/content/repositories/sidekick-oss-snapshots/</url>
<uniqueVersion>true</uniqueVersion>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<distributionManagement>
Expand Down
15 changes: 15 additions & 0 deletions sidekick/sidekick-api/pom.xml
Expand Up @@ -13,6 +13,10 @@
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-broker-client</artifactId>
</dependency>
<dependency>
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-probetag-service</artifactId>
</dependency>
<dependency>
<groupId>com.runsidekick</groupId>
<artifactId>sidekick-webhook-service</artifactId>
Expand Down Expand Up @@ -129,6 +133,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.thundra.swark</groupId>
<artifactId>thundra-env-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.thundra.swark</groupId>
<artifactId>thundra-env-utils</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<!-- ========================================== -->
</dependencies>

Expand Down
Expand Up @@ -6,6 +6,7 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand All @@ -21,6 +22,7 @@
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@Profile({"!test"})
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

private final ApiAuthService apiAuthService;
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.runsidekick.api.service.ApiAuthService;
import com.runsidekick.broker.service.BrokerService;
import com.runsidekick.broker.util.Constants;
import lombok.RequiredArgsConstructor;

/**
Expand All @@ -18,10 +19,10 @@ protected String getClient() {
}

protected String getUserId() {
return apiAuthService.getCurrentUser().getApiKey();
return Constants.USER_ID;
}

protected String getWorkspaceId() {
return apiAuthService.getCurrentUser().getApiKey();
return Constants.WORKSPACE_ID;
}
}
@@ -0,0 +1,70 @@
package com.runsidekick.api.controller;

import com.runsidekick.api.service.ApiAuthService;
import com.runsidekick.broker.model.request.impl.probetag.DisableProbeTagRequest;
import com.runsidekick.broker.model.request.impl.probetag.EnableProbeTagRequest;
import com.runsidekick.broker.model.response.impl.CompositeResponse;
import com.runsidekick.broker.model.response.impl.probetag.DisableProbeTagResponse;
import com.runsidekick.broker.model.response.impl.probetag.EnableProbeTagResponse;
import com.runsidekick.broker.service.BrokerService;
import com.runsidekick.model.ProbeTag;
import com.runsidekick.service.ProbeTagService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
* @author yasin.kalafat
*/
@RestController
@RequestMapping("/api/v1/probetags")
@Api(value = "/probetags", tags = "probetags")
public class ProbeTagController extends ControllerBase {

private final ProbeTagService probeTagService;

public ProbeTagController(ApiAuthService apiAuthService, BrokerService brokerService,
ProbeTagService probeTagService) {
super(apiAuthService, brokerService);
this.probeTagService = probeTagService;
}

@GetMapping
public List<ProbeTag> listTags() {
return probeTagService.listByWorkspaceId(getWorkspaceId());
}

@PostMapping
public ProbeTag addTag(@Valid @RequestBody ProbeTag probeTag) {
probeTag.setWorkspaceId(getWorkspaceId());
return probeTagService.add(probeTag);
}

@DeleteMapping(value = "/{id}")
public void deleteTag(@PathVariable String id) {
probeTagService.delete(id);
}

@PutMapping("/enable")
public CompletableFuture<CompositeResponse<EnableProbeTagResponse>> enableProbeTag(
@Valid @RequestBody EnableProbeTagRequest request) throws Exception {
return brokerService.enableProbeTag(request, getClient(), getWorkspaceId());
}

@PutMapping("/disable")
public CompletableFuture<CompositeResponse<DisableProbeTagResponse>> disableProbeTag(
@Valid @RequestBody DisableProbeTagRequest request) throws Exception {
return brokerService.disableProbeTag(request, getClient(), getWorkspaceId());
}

}