-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GraphQL monitoring support (#6375)
* Added smoke-test SpringBoot GraphQL appication * Arguments capturing in GraphQL * Refactor * Fixed tests * Fixed tests * Fixed GraphQL resolver address * Missing smoke-test * Fixed tests
- Loading branch information
1 parent
76fe1a4
commit 36e924e
Showing
19 changed files
with
471 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
plugins { | ||
id "com.github.johnrengelman.shadow" | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
description = 'SpringBoot GraphQL Smoke Tests.' | ||
|
||
// The standard spring-boot plugin doesn't play nice with our project | ||
// so we'll build a fat jar instead | ||
jar { | ||
manifest { | ||
attributes('Main-Class': 'datadog.smoketest.appsec.springbootgraphql.SpringbootGraphqlApplication') | ||
} | ||
} | ||
|
||
shadowJar { | ||
mergeServiceFiles { | ||
include 'META-INF/spring.*' | ||
} | ||
} | ||
|
||
// Use Java 11 to build application | ||
tasks.withType(JavaCompile) { | ||
setJavaVersion(delegate, 11) | ||
} | ||
|
||
dependencies { | ||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.7.0' | ||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-graphql', version: '2.7.0' | ||
implementation(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.15.3') | ||
|
||
testImplementation project(':dd-smoke-tests:appsec') | ||
} | ||
|
||
tasks.withType(Test).configureEach { | ||
dependsOn "shadowJar" | ||
|
||
jvmArgs "-Ddatadog.smoketest.appsec.springboot-graphql.shadowJar.path=${tasks.shadowJar.archiveFile.get()}" | ||
} | ||
|
||
task testRuntimeActivation(type: Test) { | ||
jvmArgs '-Dsmoke_test.appsec.enabled=inactive', | ||
"-Ddatadog.smoketest.appsec.springboot-graphql.shadowJar.path=${tasks.shadowJar.archiveFile.get()}" | ||
} | ||
tasks['check'].dependsOn(testRuntimeActivation) |
12 changes: 12 additions & 0 deletions
12
...rc/main/java/datadog/smoketest/appsec/springbootgraphql/SpringbootGraphqlApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package datadog.smoketest.appsec.springbootgraphql; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SpringbootGraphqlApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringbootGraphqlApplication.class, args); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...l/src/main/java/datadog/smoketest/appsec/springbootgraphql/controller/BookController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package datadog.smoketest.appsec.springbootgraphql.controller; | ||
|
||
import datadog.smoketest.appsec.springbootgraphql.dao.Author; | ||
import datadog.smoketest.appsec.springbootgraphql.dao.Book; | ||
import org.springframework.graphql.data.method.annotation.Argument; | ||
import org.springframework.graphql.data.method.annotation.QueryMapping; | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class BookController { | ||
@QueryMapping | ||
public Book bookById(@Argument String id) { | ||
return Book.getById(id); | ||
} | ||
|
||
@SchemaMapping | ||
public Author author(Book book) { | ||
return Author.getById(book.getAuthorId()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ringboot-graphql/src/main/java/datadog/smoketest/appsec/springbootgraphql/dao/Author.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package datadog.smoketest.appsec.springbootgraphql.dao; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Author { | ||
|
||
private final String id; | ||
private final String firstName; | ||
private final String lastName; | ||
|
||
private Author(String id, String firstName, String lastName) { | ||
this.id = id; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
private static List<Author> authors = | ||
Arrays.asList( | ||
new Author("author-1", "Joshua", "Bloch"), | ||
new Author("author-2", "Douglas", "Adams"), | ||
new Author("author-3", "Bill", "Bryson")); | ||
|
||
public static Author getById(String id) { | ||
return authors.stream().filter(author -> author.id.equals(id)).findFirst().orElse(null); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...springboot-graphql/src/main/java/datadog/smoketest/appsec/springbootgraphql/dao/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package datadog.smoketest.appsec.springbootgraphql.dao; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Book { | ||
|
||
private final String id; | ||
private final String name; | ||
private final int pageCount; | ||
private final String authorId; | ||
|
||
private Book(String id, String name, int pageCount, String authorId) { | ||
this.id = id; | ||
this.name = name; | ||
this.pageCount = pageCount; | ||
this.authorId = authorId; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getPageCount() { | ||
return pageCount; | ||
} | ||
|
||
public String getAuthorId() { | ||
return authorId; | ||
} | ||
|
||
private static List<Book> books = | ||
Arrays.asList( | ||
new Book("book-1", "Effective Java", 416, "author-1"), | ||
new Book("book-2", "Hitchhiker's Guide to the Galaxy", 208, "author-2"), | ||
new Book("book-3", "Down Under", 436, "author-3")); | ||
|
||
public static Book getById(String id) { | ||
return books.stream().filter(book -> book.id.equals(id)).findFirst().orElse(null); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
dd-smoke-tests/appsec/springboot-graphql/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.graphql.graphiql.enabled=true |
16 changes: 16 additions & 0 deletions
16
dd-smoke-tests/appsec/springboot-graphql/src/main/resources/graphql/schema.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type Query { | ||
bookById(id: ID): Book | ||
} | ||
|
||
type Book { | ||
id: ID | ||
name: String | ||
pageCount: Int | ||
author: Author | ||
} | ||
|
||
type Author { | ||
id: ID | ||
firstName: String | ||
lastName: String | ||
} |
Oops, something went wrong.