-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: creating a devworkspace telemetry plug-in
Signed-off-by: David Kwon <[email protected]>
- Loading branch information
Showing
22 changed files
with
872 additions
and
9 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ions/examples/creating-a-telemetry-plugin-for-devworkspaces/AnalyticsManagerSkeleton.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,52 @@ | ||
package org.my.group; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Alternative; | ||
import javax.inject.Inject; | ||
|
||
import org.eclipse.che.incubator.workspace.telemetry.base.AbstractAnalyticsManager; | ||
import org.eclipse.che.incubator.workspace.telemetry.base.AnalyticsEvent; | ||
import org.eclipse.che.incubator.workspace.telemetry.finder.DevWorkspaceFinder; | ||
import org.eclipse.che.incubator.workspace.telemetry.finder.UsernameFinder; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.slf4j.Logger; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
@Dependent | ||
@Alternative | ||
public class AnalyticsManager extends AbstractAnalyticsManager { | ||
|
||
private static final Logger LOG = getLogger(AbstractAnalyticsManager.class); | ||
|
||
public AnalyticsManager(MainConfiguration mainConfiguration, DevWorkspaceFinder devworkspaceFinder, UsernameFinder usernameFinder) { | ||
super(mainConfiguration, devworkspaceFinder, usernameFinder); | ||
|
||
mainConfiguration.welcomeMessage.ifPresentOrElse( <1> | ||
(str) -> LOG.info("The welcome message is: {}", str), | ||
() -> LOG.info("No welcome message provided") | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
|
||
@Override | ||
public void onEvent(AnalyticsEvent event, String ownerId, String ip, String userAgent, String resolution, Map<String, Object> properties) { | ||
LOG.info("The received event is: {}", event); <2> | ||
} | ||
|
||
@Override | ||
public void increaseDuration(AnalyticsEvent event, Map<String, Object> properties) { } | ||
|
||
@Override | ||
public void onActivity() {} | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/Dockerfile.jvm
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,13 @@ | ||
FROM registry.access.redhat.com/ubi8/openjdk-11:1.11 | ||
|
||
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' | ||
|
||
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ | ||
COPY --chown=185 target/quarkus-app/*.jar /deployments/ | ||
COPY --chown=185 target/quarkus-app/app/ /deployments/app/ | ||
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ | ||
|
||
EXPOSE 8080 | ||
USER 185 | ||
|
||
ENTRYPOINT ["java", "-Dquarkus.http.host=0.0.0.0", "-Djava.util.logging.manager=org.jboss.logmanager.LogManager", "-Dquarkus.http.port=${DEVWORKSPACE_TELEMETRY_BACKEND_PORT}", "-jar", "/deployments/quarkus-run.jar"] |
11 changes: 11 additions & 0 deletions
11
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/Dockerfile.native
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,11 @@ | ||
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5 | ||
WORKDIR /work/ | ||
RUN chown 1001 /work \ | ||
&& chmod "g+rwX" /work \ | ||
&& chown 1001:root /work | ||
COPY --chown=1001:root target/*-runner /work/application | ||
|
||
EXPOSE 8080 | ||
USER 1001 | ||
|
||
CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Dquarkus.http.port=$DEVWORKSPACE_TELEMETRY_BACKEND_PORT}"] |
16 changes: 16 additions & 0 deletions
16
.../extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/MainConfiguration.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,16 @@ | ||
package org.my.group; | ||
|
||
import java.util.Optional; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Alternative; | ||
|
||
import org.eclipse.che.incubator.workspace.telemetry.base.BaseConfiguration; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
@Dependent | ||
@Alternative | ||
public class MainConfiguration extends BaseConfiguration { | ||
@ConfigProperty(name = "welcome.message") <1> | ||
Optional<String> welcomeMessage; <2> | ||
} |
19 changes: 19 additions & 0 deletions
19
...s/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/TelemetryService.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,19 @@ | ||
package org.my.group; | ||
|
||
import java.util.Map; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient | ||
public interface TelemetryService { | ||
@POST | ||
@Path("/event") <1> | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
Response sendEvent(Map<String, Object> payload); | ||
} |
60 changes: 60 additions & 0 deletions
60
...xamples/creating-a-telemetry-plugin-for-devworkspaces/che_cluster_with_custom_plugin.yaml
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,60 @@ | ||
apiVersion: org.eclipse.che/v1 | ||
kind: CheCluster | ||
metadata: | ||
creationTimestamp: '2020-05-14T13:21:51Z' | ||
finalizers: | ||
- oauthclients.finalizers.che.eclipse.org | ||
generation: 18 | ||
name: {prod-checluster} | ||
namespace: __<{prod-namespace}>__ | ||
resourceVersion: '5108404' | ||
selfLink: /apis/org.eclipse.che/v1/namespaces/che/checlusters/eclipse-che | ||
uid: bae08db2-104d-4e44-a001-c9affc07528d | ||
spec: | ||
auth: | ||
identityProviderURL: 'https://keycloak-che.apps-crc.testing' | ||
identityProviderRealm: che | ||
updateAdminPassword: false | ||
oAuthSecret: ZMmNPRbgOJJQ | ||
oAuthClientName: eclipse-che-openshift-identity-provider-yrlcxs | ||
identityProviderClientId: che-public | ||
identityProviderPostgresSecret: che-identity-postgres-secret | ||
externalIdentityProvider: false | ||
identityProviderSecret: che-identity-secret | ||
openShiftoAuth: true | ||
database: | ||
chePostgresDb: dbche | ||
chePostgresHostName: postgres | ||
chePostgresPort: '5432' | ||
chePostgresSecret: che-postgres-secret | ||
externalDb: false | ||
k8s: {} | ||
metrics: | ||
enable: false | ||
server: | ||
cheLogLevel: INFO | ||
customCheProperties: | ||
CHE_WORKSPACE_DEVFILE_DEFAULT__EDITOR_PLUGINS: 'http://apache-che.apps-crc.testing/meta.yaml' | ||
externalDevfileRegistry: false | ||
cheHost: che-che.apps-crc.testing | ||
selfSignedCert: true | ||
cheDebug: 'false' | ||
tlsSupport: true | ||
allowUserDefinedWorkspaceNamespaces: false | ||
externalPluginRegistry: false | ||
gitSelfSignedCert: false | ||
cheFlavor: che | ||
storage: | ||
preCreateSubPaths: true | ||
pvcClaimSize: 1Gi | ||
pvcStrategy: per-workspace | ||
status: | ||
devfileRegistryURL: 'https://devfile-registry-che.apps-crc.testing' | ||
keycloakProvisioned: true | ||
cheClusterRunning: Available | ||
cheURL: 'https://che-che.apps-crc.testing' | ||
openShiftoAuthProvisioned: true | ||
dbProvisioned: true | ||
cheVersion: 7.13.1 | ||
keycloakURL: 'https://keycloak-che.apps-crc.testing' | ||
pluginRegistryURL: 'https://plugin-registry-che.apps-crc.testing/v3' |
4 changes: 4 additions & 0 deletions
4
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/destroy.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,4 @@ | ||
@Override | ||
public void destroy() { | ||
onEvent(WORKSPACE_STOPPED, lastOwnerId, lastIp, lastUserAgent, lastResolution, commonProperties); | ||
} |
2 changes: 2 additions & 0 deletions
2
...s/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/increaseDuration.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,2 @@ | ||
@Override | ||
public void increaseDuration(AnalyticsEvent event, Map<String, Object> properties) {} |
4 changes: 4 additions & 0 deletions
4
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/isEnabled.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,4 @@ | ||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} |
63 changes: 63 additions & 0 deletions
63
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/main.go
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,63 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
var logger *zap.SugaredLogger | ||
|
||
func event(w http.ResponseWriter, req *http.Request) { | ||
switch req.Method { | ||
case "GET": | ||
logger.Info("GET /event") | ||
case "POST": | ||
logger.Info("POST /event") | ||
} | ||
body, err := req.GetBody() | ||
if err != nil { | ||
logger.With("err", err).Info("error getting body") | ||
return | ||
} | ||
responseBody, err := ioutil.ReadAll(body) | ||
if err != nil { | ||
logger.With("error", err).Info("error reading response body") | ||
return | ||
} | ||
logger.With("body", string(responseBody)).Info("got event") | ||
} | ||
|
||
func activity(w http.ResponseWriter, req *http.Request) { | ||
switch req.Method { | ||
case "GET": | ||
logger.Info("GET /activity, doing nothing") | ||
case "POST": | ||
logger.Info("POST /activity") | ||
body, err := req.GetBody() | ||
if err != nil { | ||
logger.With("error", err).Info("error getting body") | ||
return | ||
} | ||
responseBody, err := ioutil.ReadAll(body) | ||
if err != nil { | ||
logger.With("error", err).Info("error reading response body") | ||
return | ||
} | ||
logger.With("body", string(responseBody)).Info("got activity") | ||
} | ||
} | ||
|
||
func main() { | ||
|
||
log, _ := zap.NewProduction() | ||
logger = log.Sugar() | ||
|
||
http.HandleFunc("/event", event) | ||
http.HandleFunc("/activity", activity) | ||
logger.Info("Added Handlers") | ||
|
||
logger.Info("Starting to serve") | ||
http.ListenAndServe(":8080", nil) | ||
} |
14 changes: 14 additions & 0 deletions
14
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/onActivity.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,14 @@ | ||
public class AnalyticsManager extends AbstractAnalyticsManager { | ||
|
||
... | ||
|
||
private long inactiveTimeLimit = 60000 * 3; | ||
|
||
... | ||
|
||
@Override | ||
public void onActivity() { | ||
if (System.currentTimeMillis() - lastEventTime >= inactiveTimeLimit) { | ||
onEvent(WORKSPACE_INACTIVE, lastOwnerId, lastIp, lastUserAgent, lastResolution, commonProperties); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/onEvent.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,15 @@ | ||
@Dependent | ||
@Alternative | ||
public class AnalyticsManager extends AbstractAnalyticsManager { | ||
@Inject | ||
@RestClient | ||
TelemetryService telemetryService; | ||
|
||
... | ||
|
||
@Override | ||
public void onEvent(AnalyticsEvent event, String ownerId, String ip, String userAgent, String resolution, Map<String, Object> properties) { | ||
Map<String, Object> payload = new HashMap<String, Object>(properties); | ||
payload.put("event", event); | ||
telemetryService.sendEvent(payload); | ||
} |
17 changes: 17 additions & 0 deletions
17
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/plugin.yaml
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,17 @@ | ||
schemaVersion: 2.1.0 | ||
metadata: | ||
name: devworkspace-telemetry-backend-plugin | ||
version: 0.0.1 | ||
description: A Demo telemetry backend | ||
displayName: Devworkspace Telemetry Backend | ||
components: | ||
- name: devworkspace-telemetry-backend-plugin | ||
attributes: | ||
workspaceEnv: | ||
- name: DEVWORKSPACE_TELEMETRY_BACKEND_PORT | ||
value: '4167' | ||
container: | ||
image: YOUR IMAGE <1> | ||
env: | ||
- name: WELCOME_MESSAGE <2> | ||
value: 'hello world!' |
17 changes: 17 additions & 0 deletions
17
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/pom_snippet.xml
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,17 @@ | ||
<!-- Required --> | ||
<dependency> | ||
<groupId>org.eclipse.che.incubator.workspace-telemetry</groupId> | ||
<artifactId>backend-base</artifactId> | ||
<version>LATEST VERSION FROM PREVIOUS STEP</version> | ||
</dependency> | ||
|
||
|
||
<!-- Used to make http requests to the telemetry server --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-jackson</artifactId> | ||
</dependency> |
33 changes: 33 additions & 0 deletions
33
modules/extensions/examples/creating-a-telemetry-plugin-for-devworkspaces/settings.xml
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,33 @@ | ||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 | ||
http://maven.apache.org/xsd/settings-1.0.0.xsd"> | ||
<servers> | ||
<server> | ||
<id>che-incubator</id> | ||
<username>YOUR GITHUB USERNAME</username> | ||
<password>YOUR GITHUB TOKEN</password> | ||
</server> | ||
</servers> | ||
|
||
<profiles> | ||
<profile> | ||
<id>github</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<repositories> | ||
<repository> | ||
<id>central</id> | ||
<url>https://repo1.maven.org/maven2</url> | ||
<releases><enabled>true</enabled></releases> | ||
<snapshots><enabled>false</enabled></snapshots> | ||
</repository> | ||
<repository> | ||
<id>che-incubator</id> | ||
<url>https://maven.pkg.github.com/che-incubator/che-workspace-telemetry-client</url> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
</settings> |
Oops, something went wrong.