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

feat(performance): AngularFire Performance Monitoring #2064

Merged
merged 14 commits into from
May 24, 2019

Conversation

jamesdaniels
Copy link
Member

Basic usage

constructor(private afp: AngularFirePerformance, private afs: AngularFirestore) {}

...

ngOnInit() {
  this.articles = afs.collection('articles')
      .collection('articles', ref => ref.orderBy('publishedAt', 'desc'))
      .snapshotChanges()
      .pipe(
        this.afp.trace('getArticles'),
        map(articles => ...)
      );
}

Advanced usage

// rough copy from Space Invaders RXJS example, should flush out
export const gameUpdate = (state: State, input: Input): State => (
  afp.traceComplete('game', {
    pluckMetrics: ['score'],
    attribute$: { user: this.afAuth.user }
  }),
  whileNotGameOver(state, input),
  processInput(state, input),
  updateState(state)
);

API

trace$(...) => Observable<void>

(name:string)
(name:string, options: TraceOptions)

Observable version of firebase/perf's .trace method; the basis for AngularFirePerfomance's pipes.

.subscribe() is equivalent to calling .start()
.unsubscribe() is equivalent to calling .stop()

<T>trace(...) => (Observable<T>) => Observable<T>

(name:string)
(name:string, options: TraceOptions)

Noop pipe, that traces the observable until the emission or completion.

<T>traceComplete(...) => (Observable<T>) => Observable<T>

(name:string)
(name:string, options: TraceOptions)

Noop pipe, that traces the observable until the completion.

<T>traceUntil(...) => (Observable<T>) => Observable<T>

(name:string, test: (T) => Boolean)
(name:string, test: (T) => Boolean, options: TraceOptions)

Noop pipe, that traces the observable until the first emission that passes the provided test.

<T>traceFirst(...) => (Observable<T>) => Observable<T>

(name:string)
(name:string, test: (T) => Boolean)
(name:string, options: TraceOptions)
(name:string, test: (T) => Boolean, options: TraceOptions)

Noop pipe, that traces the observable until the first emission or the first emission that matches the provided test.

TraceOptions

TBD explain how each option is used by .trace$

export type TraceOptions = {
  pluckMetrics?: [string],
  pluckAttributes?: [string],
  metrics?: { [key:string]: number },
  attributes?: { [key:string]: string },
  attribute$?: { [key:string]: Observable<string> },
  incrementMetric$: { [key:string]: Observable<number|void|null|undefined> },
  metric$?: { [key:string]: Observable<number> }
};

@jamesdaniels jamesdaniels self-assigned this May 7, 2019
@jamesdaniels jamesdaniels added this to the 5.2.0 milestone May 7, 2019
@jamesdaniels
Copy link
Member Author

FYI this has been released for testing on @next as of 5.2.0-beta.3

@hiepxanh
Copy link
Contributor

i love this too

@jamesdaniels jamesdaniels marked this pull request as ready for review May 20, 2019 00:45
@jamesdaniels
Copy link
Member Author

Need to work on the docs but I'm ready for review here.

@jamesdaniels jamesdaniels changed the title WIP AngularFire Performance Monitoring feat(perf): AngularFire Performance Monitoring May 20, 2019
@jamesdaniels jamesdaniels changed the title feat(perf): AngularFire Performance Monitoring feat(performance): AngularFire Performance Monitoring May 20, 2019
@jamesdaniels
Copy link
Member Author

@davideast ready for review. Docs and tests could use some work.

docs/performance/getting-started.md Outdated Show resolved Hide resolved
docs/performance/getting-started.md Outdated Show resolved Hide resolved
docs/performance/getting-started.md Show resolved Hide resolved
docs/performance/getting-started.md Outdated Show resolved Hide resolved
docs/performance/getting-started.md Outdated Show resolved Hide resolved
docs/performance/getting-started.md Outdated Show resolved Hide resolved
src/performance/performance.ts Show resolved Hide resolved
@jamesdaniels
Copy link
Member Author

@davideast @jhuleatt gave it another pass.

@jamesdaniels jamesdaniels merged commit 2469e77 into master May 24, 2019
@jamesdaniels jamesdaniels deleted the performance_monitoring branch May 24, 2019 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants