Skip to content

Commit

Permalink
fix: stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
10ko committed Dec 16, 2019
1 parent c7151ee commit 779fbce
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/demo-project/backend/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ kind: Module
name: backend
description: Backend service container
type: container
sesrvices:
services:
- name: backend
ports:
- name: http
containerPort: 8080
# Maps service:80 -> container:8080
servicePort: 80
ingrssesses:
ingresses:
- path: /hello-backend
port: http
6 changes: 3 additions & 3 deletions garden-service/src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class AnalyticsHandler implements Analytics {
private constructor(log: LogEntry) {
// { flushAt: 1 } means the client will track events as soon as they are created
// no batching is occurring: this will change once the daemon is implemented
this.segment = new segmentClient(API_KEY, { flushAt: 10, flushInterval: 300 })
this.segment = new segmentClient(API_KEY, { flushAt: 1, flushInterval: 100 })
this.log = log
this.globalConfigStore = new GlobalConfigStore()
this.globalConfig = {
Expand Down Expand Up @@ -234,7 +234,7 @@ export class AnalyticsHandler implements Analytics {
* @memberof Analytics
*/
private track(event: AnalyticsEvent) {
if (this.segment && this.hasOptedIn() && !ci.isCI) {
if (this.segment && this.hasOptedIn()) {
const segmentEvent: SegmentEvent = {
userId: this.globalConfig.userId,
event: event.type,
Expand Down Expand Up @@ -334,7 +334,7 @@ export class AnalyticsHandler implements Analytics {

trackProjectConfigError(fields: Array<string>) {
return this.track({
type: AnalyticsType.MODULE_CONFIG_ERROR,
type: AnalyticsType.PROJECT_CONFIG_ERROR,
properties: <AnalyticsProjectErrorProperties>{
...this.getBasicAnalyticsProperties(),
fields,
Expand Down
3 changes: 1 addition & 2 deletions garden-service/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ export async function run(): Promise<void> {
console.log(err)
code = 1
} finally {
const log = Logger.getInstance().placeholder()
const analytics = await AnalyticsHandler.getInstance(log)
const analytics = await AnalyticsHandler.getInstance()
await analytics.flush()
shutdown(code)
}
Expand Down
9 changes: 8 additions & 1 deletion garden-service/src/config/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { DEFAULT_API_VERSION } from "../constants"
import { defaultDotIgnoreFiles } from "../util/fs"
import { pathExists, readFile } from "fs-extra"
import { resolve } from "path"
import { AnalyticsHandler } from "../analytics/analytics"
import { AnalyticsType } from "../analytics/analytics-types"

export const defaultVarfilePath = "garden.env"
export const defaultEnvVarfilePath = (environmentName: string) => `garden.${environmentName}.env`
Expand Down Expand Up @@ -303,7 +305,8 @@ export const projectSchema = joi
export async function resolveProjectConfig(config: ProjectConfig, artifactsPath: string): Promise<ProjectConfig> {
// Resolve template strings for non-environment-specific fields
let { environmentDefaults, environments = [] } = config

const analytics = await AnalyticsHandler.getInstance()
debugger
const globalConfig = await resolveTemplateStrings(
{
apiVersion: config.apiVersion,
Expand All @@ -325,6 +328,10 @@ export async function resolveProjectConfig(config: ProjectConfig, artifactsPath:
configType: "project",
path: config.path,
projectRoot: config.path,
analyticsContext: {
analytics,
analyticsType: AnalyticsType.PROJECT_CONFIG_ERROR,
},
})

// Convert deprecated fields
Expand Down
9 changes: 6 additions & 3 deletions garden-service/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ValidateOptions {
export interface AnalyticsContext {
analytics: Analytics
analyticsType: AnalyticsType
metadata: any
metadata?: any
}

export interface ValidateWithPathParams<T> {
Expand Down Expand Up @@ -117,12 +117,15 @@ export function validate<T>(

return e
})

if (analyticsContext) {
debugger
if (analyticsContext.analyticsType === AnalyticsType.PROJECT_CONFIG_ERROR) {
analyticsContext.analytics.trackProjectConfigError(paths)
}
if (analyticsContext.analyticsType === AnalyticsType.MODULE_CONFIG_ERROR) {
} else if (analyticsContext.analyticsType === AnalyticsType.MODULE_CONFIG_ERROR) {
analyticsContext.analytics.trackModuleConfigError(analyticsContext.metadata.moduleType)
} else if (analyticsContext.analyticsType === AnalyticsType.VALIDATION_ERROR) {
analyticsContext.analytics.trackConfigValidationError(paths)
}
}

Expand Down
8 changes: 7 additions & 1 deletion garden-service/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export class Garden {
opts: GardenOpts = {}
): Promise<InstanceType<T>> {
let { environmentName, config, gardenDirPath, plugins = [] } = opts
const analytics = await AnalyticsHandler.getInstance()
if (!config) {
config = await findProjectConfig(currentDirectory)

Expand Down Expand Up @@ -632,6 +631,13 @@ export class Garden {
name: config.name,
path: config.path,
projectRoot: this.projectRoot,
analyticsContext: {
analytics: analyticsInst,
analyticsType: AnalyticsType.MODULE_CONFIG_ERROR,
metadata: {
moduleType: config.type,
},
},
})

if (config.repositoryUrl) {
Expand Down

0 comments on commit 779fbce

Please sign in to comment.