Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67cc843
Test application skeleton
serhii-vydiuk-kevychsolutions Oct 13, 2024
f3e88de
Deleted unused classes
serhii-vydiuk-kevychsolutions Oct 15, 2024
a5901a0
java metrics-sdk project skeleton
serhii-vydiuk-kevychsolutions Oct 31, 2024
0eb55de
base mocked call to the readme-metrics API with 200OK response
serhii-vydiuk-kevychsolutions Nov 12, 2024
d08c67f
Integration of core and starter: Ifrastructure to handle user data an…
serhii-vydiuk-kevychsolutions Nov 30, 2024
df01fd4
1121: Changed architectural approach to support different versions o…
serhii-vydiuk-kevychsolutions Dec 8, 2024
d152693
Java: Fetch user data based on yaml/properties configuration in Sprin…
serhii-vydiuk-kevychsolutions Dec 20, 2024
ba1c647
feat(java): Collect and log request-response data (#1154)
serhii-vydiuk-kevychsolutions Jan 8, 2025
bf5dcd3
Feature/1150/1152/1168: log options, handle different content types a…
serhii-vydiuk-kevychsolutions Feb 27, 2025
98b7f4d
minor fixes
serhii-vydiuk-kevychsolutions Feb 27, 2025
9f298a6
minor fixes
serhii-vydiuk-kevychsolutions Feb 27, 2025
009b8d9
deleted useless files
serhii-vydiuk-kevychsolutions Feb 27, 2025
3edfca8
Merge remote-tracking branch 'origin/main' into java-metrics-sdk-dev
serhii-vydiuk-kevychsolutions Feb 27, 2025
9ed4f6b
Fixed md files with prettier + other minor fixes
serhii-vydiuk-kevychsolutions Feb 27, 2025
8b3b74b
Fixed lint issues
serhii-vydiuk-kevychsolutions Feb 27, 2025
09857e3
Handled comments to MR
serhii-vydiuk-kevychsolutions Mar 18, 2025
a3f336d
Added Spring+Kotlin example, Added support of Spring 2+, Collapsed me…
serhii-vydiuk-kevychsolutions Apr 30, 2025
319d171
Extended codeql-analysis with java and kotlin
serhii-vydiuk-kevychsolutions Apr 30, 2025
17230e3
CI/CD configuration
serhii-vydiuk-kevychsolutions May 24, 2025
e695050
Fixed codeql-analysis.yaml
serhii-vydiuk-kevychsolutions May 26, 2025
fad088e
Fixed deployment plugin to be triggered only on deploy phase
serhii-vydiuk-kevychsolutions May 26, 2025
5e753dc
Updated java docs to meet javadoc plugin rules
serhii-vydiuk-kevychsolutions May 27, 2025
7e4c5d7
Java docs fixes part2
serhii-vydiuk-kevychsolutions May 27, 2025
55c76cb
Merge branch 'main' into java-metrics-sdk-dev
serhii-vydiuk-kevychsolutions May 27, 2025
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
9 changes: 9 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- javascript
- python
- ruby
- java

steps:
- name: Checkout repository
Expand All @@ -34,7 +35,15 @@ jobs:
languages: ${{ matrix.language }}

- name: Autobuild
if: matrix.language != 'java'
uses: github/codeql-action/autobuild@v3

- name: Build for Java and Kotlin
if: matrix.language == 'java'
run: |
mvn clean install -f packages/java/metrics-core/pom.xml
mvn clean install -f packages/java/metrics-spring/pom.xml
mvn clean install -f packages/java/metrics-spring2/pom.xml

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
105 changes: 105 additions & 0 deletions .github/workflows/java.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: java

on:
push:
branches:
- main
paths:
- 'packages/java/**'

jobs:
build-and-deploy-core:
name: Build and Deploy metrics-core
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Configure Maven settings.xml
run: echo "${{ secrets.MAVEN_SETTINGS }}" > ~/.m2/settings.xml

- name: Build & Test metrics-core
working-directory: packages/java
run: mvn clean verify

- name: Import GPG Key
run: |
echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}

- name: Deploy metrics-core
working-directory: packages/java
run: mvn deploy -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}

build-and-deploy-for-spring3:
name: Build and Deploy metrics-spring library for Spring Boot 3+
needs: build-and-deploy-core
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Configure Maven settings.xml
run: echo "${{ secrets.MAVEN_SETTINGS }}" > ~/.m2/settings.xml

- name: Build & Test metrics-spring
working-directory: packages/java/metrics-spring
run: mvn clean verify

- name: Import GPG Key
run: |
echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}

- name: Deploy metrics-spring
working-directory: packages/java/metrics-spring
run: mvn deploy -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}

build-and-deploy-for-spring2:
name: Build and Deploy metrics-spring library for Spring Boot 2+
needs: build-and-deploy-core
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Configure Maven settings.xml
run: echo "${{ secrets.MAVEN_SETTINGS }}" > ~/.m2/settings.xml

- name: Build & Test metrics-spring2
working-directory: packages/java/metrics-spring2
run: mvn clean verify

- name: Import GPG Key
run: |
echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}

- name: Deploy metrics-spring2
working-directory: packages/java/metrics-spring2
run: mvn deploy -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ node_modules/
packages/*/.nyc_output/
packages/*/coverage/
packages/*/node_modules/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

27 changes: 27 additions & 0 deletions packages/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
../*

### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store

24 changes: 24 additions & 0 deletions packages/java/examples/SpringMetricsExample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### VS Code ###
.vscode/

.DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
3 changes: 3 additions & 0 deletions packages/java/examples/SpringMetricsExample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SpringMetricsExample

The application is a REST web-service. It is an example of using Java metrics SDK.
49 changes: 49 additions & 0 deletions packages/java/examples/SpringMetricsExample/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<!-- <version>2.7.18</version>-->
<relativePath/>
</parent>
<groupId>com.readme</groupId>
<artifactId>spring-metrics-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-metrics-example</name>
<description>Example project to test metrics-sdk</description>

<properties>
<java.version>21</java.version>
</properties>

<dependencies>
<dependency>
<groupId>com.readme</groupId>
<artifactId>metrics-spring</artifactId>
<!-- <artifactId>metrics-spring2</artifactId>-->
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.owl.example;

import com.readme.core.dataextraction.LogOptions;
import com.readme.core.dataextraction.payload.user.UserData;
import com.readme.core.dataextraction.payload.user.UserDataCollector;
import com.readme.spring.datacollection.ServletDataPayloadAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
* Configuration class for customizing the strategy to collect user data.
*
* <p>This configuration provides a custom implementation of {@link UserDataCollector},
* which overrides the default behavior provided by the SDK. It allows developers
* to specify their own logic for extracting user-specific information, such as API keys,
* email addresses, or labels, from the incoming HTTP requests.</p>
*
* <p>In this example, the API key is extracted from the HTTP headers using the header
* "X-User-Name", while the email and label fields are hardcoded with custom values.
* Developers can modify this logic to suit their application's requirements.</p>
*
* <p>By defining this bean, Spring Boot's auto-configuration will automatically use
* this custom implementation instead of the default {@link UserDataCollector}.</p>
*/
@Configuration
public class CustomUserDataCollectorConfig {

@Bean
public UserDataCollector<ServletDataPayloadAdapter> customUserDataCollector() {
return payloadAdapter -> {
String apiKey = payloadAdapter.getRequestHeaders().get("x-user-name");
return UserData.builder()
.apiKey(apiKey)
.email("[email protected]")
.label("owl-label")
.build();
};
}

@Bean
public LogOptions logOptions() {
return LogOptions.builder()
.baseLogUrl("http://baseurl.abcd")
.bufferLength(1)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.owl.example;

import com.readme.core.datatransfer.har.HttpStatus;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
* OwlController is a sample REST controller intended for demonstration and testing purposes.
* <p>
* It simulates typical HTTP requests and responses to showcase how the ReadMe Metrics SDK
* integrates into a Spring Boot application.
* <p>
* This controller is not intended for production use and serves only as an example endpoint
* to test how the SDK logs and processes different request types.
*/
@RestController
public class OwlController {

private final Map<String, String> owlStorage = new HashMap<>();

public OwlController() {
owlStorage.put("1", "Default Owl");
}

@GetMapping("/owl/{id}")
public String getOwlById(@PathVariable String id) {
return "Owl with id " + id;
}

@GetMapping("/owls")
public Collection<String> getAllOwl() {
return owlStorage.values();
}

@PutMapping("/owl/{owlName}")
public ResponseEntity<String> createOwl(@PathVariable String owlName, @RequestBody String body) {
UUID birdId = UUID.randomUUID();
owlStorage.put(birdId.toString(), owlName);

String responseBody = "Bird " + owlName + " created a bird with id: " + birdId + "\n" +
"Creation request body: \n" + body;

HttpHeaders headers = new HttpHeaders();
headers.add("bird-id", birdId.toString());
headers.add("bird-token", Base64.getEncoder()
.encodeToString(birdId.toString()
.getBytes()));

return ResponseEntity.status(HttpStatus.CREATED.getCode())
.headers(headers)
.body(responseBody);
}

@PutMapping(value = "/owl/urlencoded/{owlName}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> createOwlUrlencoded(@RequestParam Map<String, String> params) {
UUID birdId = UUID.randomUUID();

String responseBody = "Created a bird with id: " + birdId + "\n" +
"Creation request urlencoded body: \n" + params;

HttpHeaders headers = new HttpHeaders();
headers.add("bird-id", birdId.toString());
headers.add("bird-token", Base64.getEncoder()
.encodeToString(birdId.toString()
.getBytes()));

return ResponseEntity.status(HttpStatus.CREATED.getCode())
.headers(headers)
.body(responseBody);
}

}
Loading
Loading