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

Add analyzer to warn about wrong UseGoogleTrace/UseMvc order #2054

Merged
merged 14 commits into from Apr 25, 2018

Conversation

evildour
Copy link
Contributor

@evildour evildour commented Apr 5, 2018

Resolves #1982

Recommend to review one commit at a time.

  • This also adds in support for easily auto-generating more analyzers in the future.
  • Analyzers are packaged into the nupkg file of the target assembly, but we can change that to make them their own NuGet packages if necessary.
  • My only question is about how we want to assign rule ids. I was using a "GCPxxxx" format for our internal analyzers, from 0001-0004 currently, but I think that format works nicely for the public analyzers as well, so I assigned this one to use "GCP0005". However, if we want a clean numbering from 1 for all the public analyzers, we can use a different format and/or range for the internal ones. Just let me know and I'll change the ids. I don't feel too strongly about it, but we should figure this out before release because changing it later would be a breaking change (rule severity customizations and in-source error suppressions wouldn't work after a change).

cc @SurferJeffAtGoogle

@jskeet
Copy link
Collaborator

jskeet commented Apr 5, 2018

I'm fine for us to mix and match between internal and public, so long as everything is still unique - I don't think users will attach particular meaning.

I probably won't be able to review this until Tuesday, but I'll ask friends in the Roslyn team to have a look in terms of packaging.

@evildour
Copy link
Contributor Author

evildour commented Apr 5, 2018

Great, thanks!

@evildour
Copy link
Contributor Author

evildour commented Apr 5, 2018

Travis failure looks like it may be this: dotnet/msbuild#1957. There is a workaround here: dotnet/msbuild#1957 (comment), which I'll try.

@codecov
Copy link

codecov bot commented Apr 5, 2018

Codecov Report

Merging #2054 into master will decrease coverage by 27.89%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2054      +/-   ##
==========================================
- Coverage   55.85%   27.96%   -27.9%     
==========================================
  Files         516       58     -458     
  Lines       15673      937   -14736     
==========================================
- Hits         8754      262    -8492     
+ Misses       6919      675    -6244
Impacted Files Coverage Δ
...le.Cloud.Diagnostics.Common/Trace/SpanIdFactory.cs 0% <0%> (-100%) ⬇️
...d.Diagnostics.Common/Trace/InternalTraceOptions.cs 0% <0%> (-100%) ⬇️
...e.Cloud.Diagnostics.Common/Trace/StopwatchTimer.cs 0% <0%> (-100%) ⬇️
...d.Diagnostics.Common/Trace/ManagedTracerFactory.cs 0% <0%> (-100%) ⬇️
...Cloud.Diagnostics.Common/Trace/StartSpanOptions.cs 0% <0%> (-100%) ⬇️
...d.Diagnostics.Common/ErrorReporting/EventTarget.cs 0% <0%> (-100%) ⬇️
....Cloud.Diagnostics.Common/FlushableConsumerBase.cs 0% <0%> (-100%) ⬇️
....Common/Google.Cloud.Diagnostics.Common/Project.cs 0% <0%> (-100%) ⬇️
...ogle.Cloud.Diagnostics.Common/Trace/TraceLabels.cs 3.12% <0%> (-96.88%) ⬇️
...Cloud.Diagnostics.Common/SizedBufferingConsumer.cs 0% <0%> (-94.45%) ⬇️
... and 476 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb50bf0...c6a3151. Read the comment docs.

Copy link
Contributor

@iantalarico iantalarico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a first pass, I need to read up a little on some of this and will take another pass at it.

This is pretty cool, thanks for doing this Mike!

Not sure if it's worth doing here or in another PR but we should probably do the same for error reporting bits.

@@ -0,0 +1,58 @@
param($installPath, $toolsPath, $package, $project)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,58 @@
param($installPath, $toolsPath, $package, $project)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,58 @@
param($installPath, $toolsPath, $package, $project)

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,58 @@
param($installPath, $toolsPath, $package, $project)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}
catch
{

This comment was marked as spam.

This comment was marked as spam.

@@ -93,7 +93,8 @@ public class MissingCopyrightNoticeAnalyzer : DiagnosticAnalyzer
"//------------------------------------------------------------------------------\n// <auto-generated>",
"//------------------------------------------------------------------------------\r\n// <auto-generated>",
"// Generated by the protocol buffer compiler. DO NOT EDIT!",
"// Generated by the MSBuild WriteCodeFragment class.");
"// Generated by the MSBuild WriteCodeFragment class.",
"// This file was automatically created from");

This comment was marked as spam.

This comment was marked as spam.

var analyzersDirectory = Path.Combine(apiRoot, api.Id + ".Analyzers");
if (!Directory.Exists(analyzersDirectory))
{
Directory.CreateDirectory(analyzersDirectory);

This comment was marked as spam.

This comment was marked as spam.


AddPackFile(
$@"..\{api.Id}.Analyzers\bin\$(Configuration)\{AnalyzersTargetFramework}\{api.Id}.Analyzers.dll",
"analyzers/dotnet/cs");

This comment was marked as spam.

This comment was marked as spam.

base.FinalizeSolution(projectId, ref solution);
}
}
}

This comment was marked as spam.

This comment was marked as spam.

private const string UseGoogleTrace = "UseGoogleTrace";
private const string UseMvc = "UseMvc";

private static readonly LocalizableString Title =

This comment was marked as spam.

This comment was marked as spam.

@evildour
Copy link
Contributor Author

evildour commented Apr 6, 2018

What need's to be done for the error reporting bits? Is it the same concept of an ordering requirement?

@iantalarico
Copy link
Contributor

@evildour Yea it's pretty much the same thing it needs to be called before things you want uncaught exceptions logged for MVC is probably where the bulk of this would be.

@iantalarico
Copy link
Contributor

@evildour Hit enter too soon. It's probably worth doing error reporting in a separate PR as this is already fairly large.

@evildour
Copy link
Contributor Author

evildour commented Apr 6, 2018

Yeah I agree. I'd like to nail down the packaging strategy first so we can get this in. Then I'll generalize it in another PR.

@evildour
Copy link
Contributor Author

Ok now the analyzers will be their own package. PTAL.

Copy link
Collaborator

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the tests more than the implementation, but it looks okay. Is there anything specific you want me to pay more attention to?

{
public class GoogleTraceBeforeMvcAnalyzerTests : CodeFixVerifier
{
private static readonly MetadataReference RuntimeReference =

This comment was marked as spam.

This comment was marked as spam.

}

[Fact]
public void SeparateChecksInSeaprateScopes()

This comment was marked as spam.

This comment was marked as spam.

{
internal static ITypeSymbol Type(this ISymbol symbol)
{
switch (symbol.Kind)

This comment was marked as spam.

This comment was marked as spam.

@evildour
Copy link
Contributor Author

I guess just the package details because I think we should publish these analyzers after this PR is merged.

Note: I realized I forgot to actually look in the package to make sure things were correct before, and they weren't, so I also made a few fixes there. PTAL at the project generator.

Copy link
Collaborator

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes seem reasonable. That said, the project generator is definitely growing in a somewhat Vogon-like way... we may want to take a step back and see if the current requirements could be better implemented with an overhaul. I'm slightly surprised we've managed to bend it this far :)

@evildour
Copy link
Contributor Author

Yeah, that might be a good idea, but in a different PR. Are you ok if I publish this right after merging?

@iantalarico are you still taking a look here or are you good?

@evildour
Copy link
Contributor Author

(rebase)

@evildour evildour merged commit 0e9dfea into googleapis:master Apr 25, 2018
@evildour evildour deleted the trace-analyzer branch April 25, 2018 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants