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

Port lighthouse-docker to TS in New Repo #1

Merged
merged 15 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DD_API_KEY=
DD_APP_KEY=
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@datadog/datadog-api-client": "^1.16.0",
"chrome-launcher": "^1.0.0",
"dotenv": "^16.3.1",
"lighthouse": "^11.1.0"
}
}
116 changes: 116 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions src/DatadogClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { client, v2 } from '@datadog/datadog-api-client';


export default class DatadogClient {
private clientConfiguration: client.Configuration;

constructor({ api_key, app_key}: { api_key: string, app_key: string }) {
const configurationOpts = {
authMethods: {
apiKeyAuth: api_key,
appKeyAuth: app_key
},
};

this.clientConfiguration = client.createConfiguration(configurationOpts);
}

async submitMetrics(metricName: string, dataPoints: v2.MetricPoint[], tags: string[] = []): Promise<void> {
const metricsApiInstance = new v2.MetricsApi(this.clientConfiguration);

const params: v2.MetricsApiSubmitMetricsRequest = {
body: {
series: [
{
metric: metricName,
type: 3, // gauge
points: dataPoints,
tags: tags
}
]
}
};

const response = await metricsApiInstance.submitMetrics(params);

if (response.errors && response.errors.length > 0) {
throw new Error(response.errors.join(', '));
}
mlahargou marked this conversation as resolved.
Show resolved Hide resolved
}
}